For Loop in C++
For loop have three parts;
for (i= 1; i <= n; ++i)
loop initialization: e.g i=1;
loop condition: e.g i<=n;
loop increment/decrement: e.g i++;
Example of For loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <iostream> using namespace std; int main() { int i, n; int factorial= 1; cout << "Enter a number: "; cin >> n; for (i= 1; i <= n; ++i) { factorial*= i; } cout<< "Factorial of "<<n<<" = "<<factorial; return 0; } |
Latest posts by Prof. Fazal Rehman Shamil (see all)
- List of Public service commissions - August 31, 2020
- Comparison of fee structure of Pakistani Universities - June 1, 2020
- Past Guess Paper of Auditing - May 12, 2020