#include <stdio.h>
#include<conio.h>
int factorial (int num)
{
int i, fact=1;
for (i = 1; i <= num; i++)
{
fact = fact * i;
}
return fact;
}
int main ()
{
int terms, sum=0, i;
printf ("Input number of terms: ");
scanf ("%d", &terms);
for (i = 1; i <= terms; i++)
{
sum = sum + factorial (i);
}
printf ("Sum of Series (S = 1! + 2! ... + %d!): %d", terms, sum);
getch();
return 0;
}
Input number of terms: 8
Sum of Series (S = 1! + 2! ... + 8!): 46233
--------------------------------
Process exited after 6.115 seconds with return value 0
Press any key to continue . . .
#include<stdio.h>
int fact(int n)
{
if (n==1)
return 1;
else
return n*fact(n-1);
}
int main()
{
int n,sum=0,i;
printf("Enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+fact(i);
}
printf("Sum of the series is: %d",sum);
return 0;
}
Enter a number
5
Sum of the series is: 153
--------------------------------
Process exited after 3.462 seconds with return value 0
Press any key to continue . . .