120. C Program to Compute the 1!+2!+3!+ 4!+…………+n series.
How does this program work?
- This program is used to compute the sum of series for the given order.
- Here we are going to find the series for 1!+2!+3!+ 4!+ …………………+n upto nth term.
- where The nth term is the user input.
- Computing the given series is easy by Using the simple for loop condition.
Here is the code
#include <stdio.h>
int main(void)
{
int num,i,j,fact,sum=0;//Variables
printf("Enter the last number of series:\n");
scanf("%d",&num);//Last number of series
for(i=1;i<=num;i++)//Loop upto Last number
{
fact=1;
if(i!=num)
printf("%d!+ ",i);//To display the elements
else
printf("%d!= ",i);
for(j=1;j<=i;j++)
fact=fact*j;
sum=sum+fact;
}
printf("%d",sum);//To dislay the output
return 0;
}