Curriculum
Course: C basic
Login

Curriculum

C basic

C Introduction

0/1

C Get Started

0/1

C Comments

0/1

C Constants

0/1

C Operators

0/1

C Break and Continue

0/1

C User Input

0/1

C Memory Address

0/1

C Structures

0/1
Text lesson

Real-Life Examples

Real-Life Examples

To illustrate a practical example of a for loop, let’s write a program that counts to 100 in increments of ten:

Example

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:

Example

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.

Example

int number = 2;
int i;

// Print the multiplication table for the number 2
for (i = 1; i <= 10; i++) {
  printf(“%d x %d = %d\n”, number, i, number * i);
}

return 0