/* WRITE A C PROGRAM TO SUM THE
SERIES:
x^3 x^5 x^7
SIN(x)= x - ----- + ----- + ----- + ...
3! 5! 7!
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI 3.143
long int fact(int n) /* To find factorial */
{
if(n==0)
return 1;
else
return(n*fact(n-1));
}
void main()
{
int i,n,term=1;
float x,y,sum;
clrscr();
printf("\n SIN Series...");
printf("\n Enter No. of Terms N [1-12] : ");
scanf("%ld",&n);
if(n>=1 && n<=12)
{
printf("\n Enter the Value of 'X' : ");
scanf("%f",&y);
x=y*(PI/180.00); /* Converting degrees to radians */
sum=x;
for(i=3;term<=n;i+=2)
{
if(i==3)
sum-=pow(x,i)/(float)fact(i);
else
sum+=pow(x,i)/(float)fact(i);
term++;
}
printf("\n Sin(%f) = %f",y,sum);
}
else
printf("Wrong entry!!!");
getch();
}
/* =====OUT PUT=====
SIN Series...
1. Enter No. of Terms N [1-12] : 9
Enter the Value of 'X' : 45
Sin(45.000000) = 0.707429
2. SIN Series...
Enter No. of Terms N [1-12] : 5
Enter the Value of 'X' : 0
Sin(0.000000) = 0.000000
3. SIN Series...
Enter No. of Terms N [1-12] : 15
Wrong entry!!!
*/
No comments:
Post a Comment