- Learn C By Examples Time
- Learn C by Examples - Home
- C Examples - Simple Programs
- C Examples - Loops/Iterations
- C Examples - Patterns
- C Examples - Arrays
- C Examples - Strings
- C Examples - Mathematics
- C Examples - Linked List
- C Programming Useful Resources
- Learn C By Examples - Quick Guide
- Learn C By Examples - Resources
- Learn C By Examples - Discussion
Counting program in C
Counting is sequence of whole numbers in ascending order without zero. Developing a program of counting in C programming language is easy and we shall see here in this chapter.
Algorithm
Let's first see what should be the step-by-step procedure for counting −
START Step 1 → Define start and end of counting Step 2 → Iterate from start to end Step 3 → Display loop value at each iteration STOP
Pseudocode
Let's now see the pseudocode of this algorithm −
procedure counting() FOR value = START to END DO DISPLAY value END FOR end procedure
Implementation
Now, we shall see the actual implementation of the program −
#include <stdio.h> int main() { int i, start, end; start = 1; end = 10; for(i = start; i <= end; i++) printf("%2d\n", i); return 0; }
Output
Output of this program should be −
1 2 3 4 5 6 7 8 9 10
loop_examples_in_c.htm
Advertisements