Menu
×
Tutorials Ms Word Tutorial Ms Excel Tutorial Ms PowerPoint Tutorial C Language Tutorial C++ Tutorial C Sharp Tutorial Visual Basic Tutorial HTML Tutorial CSS Tutorial JavaScript Tutorial WordPress Tutorial
     ❯   

ADVERTISEMENT

Print Numbers From 1 to 100

This C program prints the numbers from 1 to 100 using C.

#include<stdio.h>
main()
{
   int i;
   for(i=1;i<=100;i++)
   {
      printf("%d\n",i);
   }
}
C Programming Examples

OUTPUT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
C Programming Examples

Explanation:

This C program prints the numbers from 1 to 100. Here’s a step-by-step explanation of the code:

Header File:

  • The program includes the standard C library header <stdio.h>. This header is required for input and output operations.

Main Function:

  • The main function is the entry point of the program, where the execution starts.

Variable Declaration:

  • The program declares an integer variable ‘i’. This variable is used as a loop counter to iterate through the numbers from 1 to 100.

For Loop:

The program utilizes a for loop to repeatedly execute a block of code. The loop is structured as follows:

  • Initialization: i = 1 – The loop counter ‘i’ is initialized to 1 when the loop begins.
  • Condition: i <= 100 – The loop continues as long as ‘i’ is less than or equal to 100.
  • Increment: i++ – After each iteration, ‘i’ is incremented by 1.

Printing Numbers:

  • Inside the loop, the program uses printf to display the value of ‘i’ followed by a newline character (\n). This will print the current value of ‘i’ on the screen and move to the next line.

Loop Iteration:

  • The loop continues to execute, incrementing ‘i’ in each iteration. It prints the numbers from 1 to 100, one number per line.

End of Program:

  • Once ‘i’ exceeds 100 (after printing 100), the loop terminates, and the program reaches the end of the main function, concluding the program’s execution.
  • In summary, this code uses a for loop to iterate through the numbers from 1 to 100, printing each number on a separate line. This generates a list of integers from 1 to 100.
Spread the love
Scroll to Top
Scroll to Top