C Programming

C Program to Use Trigonometric Functions

C programming, you can use trigonometric functions from the <math.h> header to perform various trigonometric calculations. Here’s a simple program that demonstrates the use of some common trigonometric functions. sin( ) : #include<stdio.h>#include<math.h>int main(){double result,x;printf(“Enter the Value : “);scanf(“%lf”,&x);result=sin(x);printf(“The sin() of %lf is %lf\n”,x,result);return 0;} Output : cos( ) : #include<stdio.h>#include<math.h>int main(){double result,x;printf(“Enter the Value : “);scanf(“%lf”,&x);result=cos(x);printf(“The cosine() of %lf is %lf\n”,x,result);return 0;} Output : tan( ) : #include<stdio.h>#include<math.h>int main(){double result,x;printf(“Enter the Value : “);scanf(“%lf”,&x);result=tan(x);printf(“The tan of %lf is %lf\n”,x,result);return 0;} Output : abs( ) : #include<stdio.h>#include<math.h>int main(){int result,x;printf(“Enter the Value : “);scanf(“%d”,&x);result=abs(x);printf(“The Absolute value of %d is %d\n”,x,result);return 0;} Output : sqrt( ) : #include<stdio.h>#include<math.h>int main(){double result,x;printf(“Enter the Value : “);scanf(“%lf”,&x);result=sqrt(x);printf(“The square root of %lf is %lf.\n”,x,result);return 0;} Output : log( ) : #include<stdio.h>#include<math.h>int main(){double result,x;printf(“Enter the Value : “);scanf(“%lf”,&x);result=log(x);printf(“The natural log of %lf is %lf.\n”,x,result);return 0;} Output :

C Program to Use Trigonometric Functions Read More »

C Program to Find the Length of a String

C program uses an array of characters (char str[100]) to store the input string. It uses fgets to read the string from the user, ensuring that it doesn’t overflow the array. The length of the string is then calculated using a while loop that iterates until it encounters the null character (‘\0’) or a newline character (‘\n’). The null character indicates the end of the string in C. Finally, the program prints the length of the string to the console. Method 1 : #include<stdio.h>void main(){int i=0;char input[20];printf(“Enter any String :”);gets(input);while(input[i]!=’\0′){i++;}printf(“Length of given string: %d”,i);} Output : Method 2 : #include<stdio.h>#include<conio.h>#include<string.h>void main(){char input[80];int i;printf(“Enter the string: “);gets(input);i=strlen(input);printf(“The length of the string is : %d”,i);} Output :

C Program to Find the Length of a String Read More »

C Program to Reverse a Given Number

This c program takes an integer as input, stores the original number in a separate variable, and then reverses the digits of the number using a while loop. The reversed number is then displayed on the screen along with the original number. Program : #include<stdio.h>#include<conio.h>main(){int n,r=0;printf(“Enter a number to reverse : “);scanf(“%d”,&n);while(n!=0){r=r*10;r=r+n%10;n=n/10;}printf(“Reverse of Entered Number is = %d\n”,r);} Output :

C Program to Reverse a Given Number Read More »

C Program to Display Fibonacci Series in a Given Range

The Fibonacci series is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. Here’s a simple C program to display the Fibonacci series up to a specified number of terms Program : #include<stdio.h>#include<conio.h>void main(){int a,b,c,i,n;a=0;b=1;printf(“\nEnter n for how many times generate series : “);scanf(“%d”,&n);printf(“\nFibonacci Series : \n”);printf(“%d %d “,a,b);for(i=0;i<=n-3;i++){c=a+b;a=b;b=c;printf(“%d “,c);}getch();} Output :

C Program to Display Fibonacci Series in a Given Range Read More »

Shopping Basket
Verified by MonsterInsights