C++ examples for Data Type:int
Computes the factorial of numbers with for loop, no recursive function
#include <iostream> using namespace std; int main()//from w w w . java 2 s.co m { int outer, num, fact, total; cout << "What factorial do you want to see? "; cin >> num; for (outer=1; outer <= num; outer++) { total = 1; // Initialize total for each factorial. for (fact=1; fact<= outer; fact++) { total *= fact; } // Compute each factorial. } cout << "The factorial for " << num << " is " << total; return 0; }