Uploaded by Himanshu Kumar

Aman CA2 CAP010

advertisement
CA2 (CAP 010)
Name:- Aman
Registration no.:- 12219896
Section:- DOC 11
CODE:#include <stdio.h>
#include <math.h>
int fac(int x)
{
int i,fac=1;
for(i=1;i<=x;i++)
fac=fac*i;
return fac;
}
int main()
{
float x,Q,sum=0;
int i,j,limit;
printf("Enter the value of x : ");
scanf("%f",&x);
printf("Enter number of terms: ");
scanf("%d",&limit);
for(i=1,j=1;i<=limit;i++,j=j+2)
{
if(i%2!=0)
{
sum=sum+pow(x,j)/fac(j);
}
else
sum=sum-pow(x,j)/fac(j);
}
printf("sum %f",sum);
return 0;
}
OUTPUT:Enter the value of x : 2
Enter number of terms: 4
sum 0.907937
Download