63 839
Assignments Done
99,2%
Successfully Done
In August 2018

Answer to Question #24620 in C++ for Calvin Thames

Question #24620
Write a program that asks user to input a number N. The program will check if N is between 1 and 10. If the number is not in the proper interval, output “Incorrect interval”. Then the program will calculate and output the sum of factorials: 1+2!+3!+...+N!
Expert's answer
#include <iostream>

#include <conio.h>

using namespace std;

long factorial(int n)
{
long result = 1;
while (n)
result *= n--;
return result;
}

int main()
{
int N;
cout << "Enter a number between 1 and 10: ";
cin >> N;

if (N < 0 || N > 10)
cout << "Incorrect interval." << endl;
else
{
long sum = 1;
for (int k = 2; k <= N; k++)
sum += factorial(k);
cout << endl << "The sum of factorials is: " << sum << endl;
}

_getch();
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions