1! + 2! + 3! + 4! + 5! + ... + n!
long fact(int n)
{
long i, f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
return f;
}
int main()
{
long i,n,sum=0;
n=5;
for(i=1;i<=n;i++)
{
sum=sum+fact(i);
}
printf("Sum: %d",sum);
return 0;
}
Related Links:
- More Series Programs
- Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
It is giving me the wrong value
ReplyDeletewhats your input and expected output ?
Delete#include
ReplyDeleteint main()
{
int i,n,sum=0,result=1;
printf("enter the last number : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
result=result*i;
sum = sum+result;
}
printf("resulr= %d\n",sum);
return 0;
}
is this right..?
DeleteFibonacci series
ReplyDelete