Write a program to calculate the following series:
Write a program to calculate the following series: S=1!+2!+3!+4!+..............................+n.
- 5690 Views
- 1 Answers
Your Answer
#include<stdio.h>
int add(int num)
{
int i,j,fact,sum=0;
for(i=1;i<=num;i++)//loop for finding factorial and sum
{
fact=1;
if(i!=num)
printf("%d!+ ",i);
else
printf("%d!= ",i);
for(j=1;j<=i;j++)
fact=fact*j;
sum=sum+fact;
}
return sum;
}
int main()
{
int num;
printf("Enter the last number of series:\n");
scanf("%d",&num);//last number of series
printf("%d",add(num));
return 0;
}
-
- 09 Apr
- 0 Comment
Comment
Practice Mock Test
c programming