Write a C++ program to find the sum of factorial of a given number using recursive function.

Implementation of the above problem:
#include<iostream.h>
int factorial(int n)
{
int fact;
if(n==1 || n==0)
{
return 1;
}
fact=n*factorial(n-1); //recursive function
return fact;
}
int main()
{
int n,i,sum=0;
cout<<"\nEnter the number of terms\n";
cin >>n;
for(i=1;i<=n;i++)
{
sum+=factorial(i);
}
cout<<"Sum of factorial of first "<<n<<" number is "<<sum;
return 0;
}


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: