#include <iostream>
using namespace std;
int main() {
int n, i, f = 1;
cout << "enter a num : ";
cin >> n;
if( n == 0 ) { // n should be assigned to 0
cout << "Factorial; " << f << endl;
} else {
for(i = 1; i <= n; i++) {
f = f*i;
}
cout << "Factorial: " << f << endl; // result come outside the for loop, inside for loop you only see the process BTS
}
return 0;
}
No comments:
Post a Comment