Friday, September 30, 2011

To Display The Sum Of 1!+2!+3!+.......+n! using C


#include<stdio.h>
#include<conio.h>
double fact(int n);
void main()
{
int n,i;
double sum=0.0;
clrscr();
printf("Up To Which Term ?");
scanf("%d",&n);
for(i=1;i<=n;++i)
sum+=fact(i);
printf("Sum Of The Factorials Of The Numbers Up To %d Is %g",n,sum);
getch();
}
double fact(int n)
{

int i;
double f=1.0;
for(i=2;i<=n;++i)
f*=i;
return f;
}

0 comments:

Post a Comment