Evaluation of CosX Series - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void cosx(float x,int n)
{
    int i;
    float term=1,sum=1;
    for(i=1;i<=n;i++)
    {
        term=((-term)*(x*x))/((2*i)*(2*i-1));
        sum=sum+term;
    }
    printf("Sum of the cos series=%f\n",sum);
}
void main()
{
    int n,y;
    float x;//clrscr();
    printf("Enter the no of terms:");
    scanf("%d",&n);
    printf("enter the value in degree:");
    scanf("%f",&x);
    y=x;
    x=x*(3.14/180);
    cosx(x,n);
//      getch();
}

Output:
nn@linuxmint ~ $ gcc c12.c
nn@linuxmint ~ $ ./a.out
Enter the no of terms:10
enter the value in degree:0
Sum of the cos series=1.000000
nn@linuxmint ~ $ ./a.out
Enter the no of terms:0
enter the value in degree:0
Sum of the cos series=1.000000
nn@linuxmint ~ $ ./a.out
Enter the no of terms:10
enter the value in degree:60
Sum of the cos series=0.500460
nn@linuxmint ~ $

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...