Pages

Sunday, 30 August 2015

Series 6

Number Series 6

x - x^3/3! + x^5/5! - x^7/7! + x^9/9!+...upto n terms

Coding:
#include<stdio.h>
int main()
{
 int i,n,k=2;
 float term,sum=0,x;
 printf("Please enter the number of terms:");
 scanf("%d",&n);
 printf("Please enter the x:");
 scanf("%f",&x);
 x=(x*22)/(7*180);
 term=x;
 for(i=1;i<=n;i++)
 {
  sum=sum+term;
  term=((-1)*term*x*x)/(k*(k+1));
  k=k+2;
 }
 printf("Result is:%f",sum);
 return 0;
}
Output:
Please enter the number of terms:5
Please enter the x:30
Result is:0.500183