
- 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
Reverse Counting program in C
Reverse counting is sequence of whole numbers in descending 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 reverse counting −
START Step 1 → Define start and end of counting Step 2 → Iterate from end to start Step 3 → Display loop value at each iteration STOP
Pseudocode
Let's now see the pseudocode of this algorithm −
procedure counting() FOR value = END to START 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; //reverse counting, we'll interchange loop variables for(i = end; i >= start; i--) printf("%2d\n", i); return 0; }
Output
Output of this program should be −
10 9 8 7 6 5 4 3 2 1
loop_examples_in_c.htm
Advertisements