Factorial Program in C++
Tagged:
The factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 6! = 1 x 2 x 3 x 4 x 5 x 6 = 720.
#include<iostream>
using namespace std;
int main(){
unsigned long int product = 1;
int initial = 1;
int n;
cout << "enter positive integer: ";
cin >> n;
if (n >= 0){
while(initial <= n){
product = product * initial;
initial ++;
}
}
else{
cout << "error: please enter positive number";
return 0;
}
cout << n << "! = " << product;
return 0;
}
output:


I barely passed hope you do better
Post new comment