Saturday 11 December 2010

program for To calculate the sum. Sum=1-x2/2!+ x4/4!- x6/6!+ x8/8!- x10/10!

Program:


#include<stdio.h>
#include<math.h>
 long fact(int);
 void main()

{
 int x,i,n;
float s=0,c; clrscr();

printf("\n enter the value of x\t"); scanf("%d",&x);
/*perform the looping operation*/ for(i=0,n=0;i<=10;i=i+2,n++) s=s+(pow(-1,n)*pow(x,i)/fact(i)); printf("\n the result is %f",s);
 getch();

}
/* calling sub program*/
 long fact(int x)

{
long int y=1; while(x!=0)

{
y=y*x; x--;
}
return y;
}

Output:

1.Enter the value of x : 1 The result is 0.540302 2 Enter the value of x: 2 The result is -0.416155


Conclusion: The program is error free

VIVA QUESTIONS:
1)  What is function ?
Ans: A function is a sub program it returns a value.
2)  What is procedure ?
Ans: A procedure is a sub program it does not returns a value
What are the basic data types in C ? Ans: int, char, float, double
3)    How to define preprocessor ?

Ans: By using the # symbol Ex: #include<stdio.h>

No comments:

Post a Comment