To illustrate a practical example of a for loop, let’s write a program that counts to 100 in increments of ten:
for (i = 0; i <= 100; i += 10) { printf(“%d\n”, i); } |
In this example, we develop a program that exclusively prints even numbers from 0 to 10:
for (i = 0; i <= 10; i = i + 2) { printf(“%d\n”, i); } |
In this example, we design a program that displays the multiplication table for a given number.
int number = 2; int i; // Print the multiplication table for the number 2 return 0; |