Answer to Question #26663 in C++ for DIPESH

Question #26663
1+2!+3!+4!..............n!
1
Expert's answer
2013-03-18T11:35:55-0400
#include <iostream>
using namespace std;
// we're going to calculate factorial from number
int main(){
cout<<"Enter n\n";
// we ask people for N
int n ;cin>>n;
// 1*2*... n
long long num=1;
//for 1!+2!+3!+...+N!
long long sum = 0;
// we multiply 1 * 2 * 3 ... N
for (int i = 1 ; i <= n ; i++){
num *= i;
sum += num;
}
// out the answer
cout<<"the answer is: "<<sum<<endl;

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS