Create a program that will calculate the factorial of any user entered integer.
ID: 3581036 • Letter: C
Question
Create a program that will calculate the factorial of any user entered integer. For any positive integer n, the factorial is given as: n! = n ? (n-1) ? (n-2) ? …… ? 3 ? 2 ? 1. The factorial of 0 is 1. If a number is negative, factorial does not exist and this program should display error message. Sample output dialogues should look like these:
This is a C++ question using visual studio 2012 to answer it
please assist
6. Create a program that will calculate the factorial of any user entered integer. For any positive integer n, the factorial is given as: n! n (n-1) (n-2) 2 1. The factorial of 0 is 1. If a number is factorial does not exist and this program should display error message. Sample output dialogues should look like these: EnterAan integenER ERROR Factorial of a negative number doesn't exist Enter an integer 10 Factor iale 3628800Explanation / Answer
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int i, number, factorial=1;
cout<<"Enter the any no. : ";
cin>>number;
if(number==0){// if number is zero
cout<<"Factorial of 0 is 1 "<<endl;
}else if(number<=0){// if number is negative
cout<<"ERROR!!! Factorial of negative number doesn't exist "<<endl;
} else{ // other than 0 and negative numbers
for(i=1;i<=number;i++)// multiplying the number of times of that number
{
factorial=factorial*i;
}
cout<<"Factorial: "<<factorial;
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.