Friday, October 14, 2011

Write a C program to calculate the following Sum: Sum=1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10!

#include<stdio.h>
#include<math.h>
main()
{
    float x,a=1,b=1,c,d,e,f,g,h;
    printf("Enter a variable you want\t:");
    scanf("%f",&x);
    for(a=1;a<=10;a++)
    {
        b=b*a;
        if(a==2)
            c=b;
        if(a==4)
            d=b;
        if(a==6)
            e=b;
        if(a==8)
            f=b;
        if(a==10)
            g=b;
    }
    h=1-((pow(x,2))/c)+((pow(x,4))/d)-((pow(x,6))/e)+((pow(x,8))/f)-((pow(x,10))/g);
    printf("%f\n",h);
   
   
}

No comments:

Post a Comment