You are on page 1of 1

/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include<stdio.h>

long factorial (int n)


{
if (n == 0)
return 1;
else

return (n * factorial (n - 1));


}

void main ()
{
long fact;
long sum=0;
int i,N;
printf ("Enter the number N upto which you want to find the sum of the factorials
of the first N numbers: ");
scanf ("%d", &N);

for(i=1;i<=N;i++)
{
sum += factorial(i);
}
printf("The required sum = %ld",sum);
//return 0;
}

You might also like