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!
1
Expert's answer
2013-02-19T09:40:43-0500
#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; }
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments