dear,
i am a novice of c++. the below program compiles perfectly and works as expected. However, I need to understand why the 'for loop' did not print the factorial line as many times as the loop.
I am referring to Turbo C++ by Robert Lafore . In the previous example the same for loop was used to print several lines. I could not differentiate why the cout << did not print many lines.Code:// program to computer factorial #include <iostream> void main() { unsigned int numb; // input variable unsigned long fact=1; // the factorial variable cout << "\nenter the number: "; cin >> numb; for(int j=numb; j>0; j--) // initialising the loop fact *= j; cout << "Factorial is " << fact; // result is factorial }
can you please guide, thanks