C program to print all natural numbers in reverse

Category: C Program

C program to print all natural numbers in reverse order using while loop and for loop. How to print natural numbers in reverse order in C language.

C program to print all natural numbers in reverse (from n to 1). - using while loop

#include <stdio.h>

void main()
{
    int n;
    printf("Enter value of n: ");
    scanf("%d", &n);
    while(n > 0)
    {
        printf("%d\n", n);
        n--;
    }
}

C program to print all natural numbers in reverse (from n to 1). - using for loop

#include <stdio.h>

void main()
{
    int n, i;
    printf("Enter value of n: ");
    scanf("%d", &n);
    for (i = n; i >= 1; i--)
        printf("%d\n", i);
}

Output

Enter value of n: 10
10
9
8
7
6
5
4
3
2
1

Recommended Posts