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

Question #24588

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;

double factorial(long n){

if (n < 1)

return 0;

double product = 1;

for (int i = 1; i <= n; i++)

product *= i;

return product;

}

int main()

{

int number=0;

cout<<"Enter number: ";

cin>>number;

if(number>=1 && number<=10){

cout<<"Factorial = "<<factorial(number);

} else{

cout<<"Incorrect interval

";

main();

}

getch();

return 0;

}

#include <conio.h>

using namespace std;

double factorial(long n){

if (n < 1)

return 0;

double product = 1;

for (int i = 1; i <= n; i++)

product *= i;

return product;

}

int main()

{

int number=0;

cout<<"Enter number: ";

cin>>number;

if(number>=1 && number<=10){

cout<<"Factorial = "<<factorial(number);

} else{

cout<<"Incorrect interval

";

main();

}

getch();

return 0;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment