C Program to Print Natural Numbers in Reverse Order from 1 to N using For, While and Do-while Loop

In following C programs, we will print natural numbers in reverse order from N to 1 using for loop, while loop and do-while loop.

Required Knowledge


C program to print natural numbers from N to 1 in reverse order using for loop

 #include <stdio.h>  
  
int main() {  
    int counter, N;  
 
    printf("Enter a Positive Number\n");  
    scanf("%d", &N);  
  
    printf("Printing Numbers form %d to 1\n", N);  
 
    for(counter = N; counter > 0; counter--) {  
        printf("%d \n", counter);  
    }
    
    return 0;  
} 

Output
Enter a Positive Number
10
Printing Numbers form 10 to 1
10
9
8
7
6
5
4
3
2
1

C program to print numbers in reverse order from 10 to 1 using while loop

#include <stdio.h>  
  
int main() {  
    int counter, N;  
 
    printf("Enter a Positive Number\n");  
    scanf("%d", &N);  
  
    printf("Printing Numbers form %d to 1\n", N);  

    counter = N;
    while(counter > 0) {  
        printf("%d \n", counter);  
        counter--;
    }
    
    return 0;  
} 

Output
Enter a Positive Number
6
Printing Numbers form 6 to 1
6
5
4
3
2
1

C program to print numbers in reverse from N to 1 using do-while loop

#include <stdio.h>  
  
int main() {  
    int counter, N;    
    printf("Enter a Positive Number\n");  
    scanf("%d", &N);  
  
    printf("Printing Numbers form %d to 1\n", N);  

    counter = N;
    do {  
        printf("%d \n", counter);  
        counter--;
    } while(counter > 0);
    
    return 0;  
} 

Output
Enter a Positive Number
6
Printing Numbers form 6 to 1
6
5
4
3
2
1

Related Topics
C program to print even numbers between 1 to N using for and while loop
C program to print odd numbers between 1 to N using for and while loopr
C program to print all prime numbers between 1 to N using for loop
C program to print all prime factors of a number
C program to find perfect numbers between 1 to N using for loop
C program to find product of digits of a number using while loop
C program to find sum of all even numbers between 1 to N using for loop
C program to find sum of all odd numbers between 1 to N using for loop
C program to print multiplication table of a number
List of all C programs