Question #26663

1+2!+3!+4!..............n!

Expert's answer

#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;

}

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;

}

## Comments

## Leave a comment