|
Get 9,000+ Interview Questions with Answers in an eBook
C Source Codes List | Source Code Home
Program : Program to calculate sum of the series :- 1/1! 2/2! 3/3! 4/4! ...
/*Prg. to calculate the sum of series*/
#include
#include
long int factorial(int n);
void main()
{
int n,i;
float s,r;
char c;
clrscr();
printf("\t\t\tWELCOME TO THE PROGRAM SIR/MADAM\n\n\n");
repeat : printf("\n\nYou have this series:- 1/1! + 2/2! \
+ 3/3! + 4/4! ...");
printf("\nTo which term you want its sum? ");
scanf("%d",&n);
s=0;
for (i=1;i<=n;i++)
{ s=s+((float)i/(float)factorial(i)); }
printf("\nThe sum of %d terms is %f",n,s);
fflush(stdin);
printf ("\n\nDo you want to continue?(y/n):- ");
scanf("%c",&c);
if (c=='y')
goto repeat;
printf("\n\n\n\n\n\t\t\tHAVE A NICE DAY! BYE.");
getch();
}
long int factorial(int n)
{
if (n<=1)
return(1);
else
n=n*factorial(n-1);
return(n);
}
C Source Codes List | Source Code Home
|
|
|