Evaluation of SinX Series - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void sinx(float x,int n)
{
int i;
float term=x,sum=x;
for(i=1;i<=n;i++)
{
term=((-term)*(x*x))/((2*i)*(2*i+1));
sum=sum+term;
}
printf("Sum of the sin series=%f\n",sum);
}

void main()
{
int n,y;
float x;//clrscr();
printf("enter the limit:");
scanf("%d",&n);
printf("enter the value in degree:");
scanf("%f",&x);
y=x;
x=x*(3.14/180);
sinx(x,n);
//getch();
}

Output:
nn@linuxmint ~ $ gcc c11.c
nn@linuxmint ~ $ ./a.out
enter the limit:10
enter the value in degree:90
Sum of the sin series=1.000000
nn@linuxmint ~ $ ./a.out
enter the limit:10
enter the value in degree:0
Sum of the sin series=0.000000
nn@linuxmint ~ $ ./a.out
enter the limit:10
enter the value in degree:30
Sum of the sin series=0.499770
nn@linuxmint ~ $

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...