Filled Under: ,

C Program to Calculate the Sum of cos(x) Series.

C program to calculate the sum of cos(x)

C Program to Calculate the Sum of cos(x) Series

In this program, I have discussed about the C Program to Calculate the Sum of cos(x) Series.

The value from 0° to 180 ° in steps of 30 °  is tabulated in the main program..

#include<stdio.h>
#include<math.h>
double func(long);
double fact(int);
int main()
{ int i,k;long j;
for(i=0;i<=180;i+=30)
{ k=func(i);
printf("The value of the series when X is %d is %d \n",i,k);
}
}
double func(long as)
{ float p=0,r; int l,e=0;
r=((3.14/180)*as);  //angle is converted into radians.
for(l=1;l<=10;l++,e+=2)
{p=p+pow(-1,l+1)*(pow(r,e)/fact(e));
}
return p;
}
double fact(int i)
{ int u=1,y;
for(y=1;y<=i;y++)
{ u*=y;
}
return u;
}

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.

Enjoy programming in C.


0 comments:

Post a Comment

 

Copyright 2020 Programming in C All Right Reserved