WAP to print all natural number in reverse from n to 1 using while loop

C Program to Print Natural Numbers in Reverse Order from 1 to N using For, While and Do-while Loop
·                     Write a C program to print natural numbers in reverse order from N to 1 using for loop.
·                     Wap in C to print numbers in reverse order using while and do-while loop


Required Knowledge
·                     C printf and scanf functions
·                     For loop in C
·                     While loop in C
·                     Do while loop in C

C program to print natural numbers from N to 1 in reverse order using for loop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h> 
   
int main() { 
    int counter, N; 
    /*
     * Take a positive number as input form user
     */ 
    printf("Enter a Positive Number\n"); 
    scanf("%d", &N); 
   
    printf("Printing <a href="#">Numbers</a> form %d to 1\n", N); 
    /*
     * Initialize the value of counter to N and keep on
     * decrementing it's value in every iteration till
     * counter > 0
     */
    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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h> 
   
int main() { 
    int counter, N; 
    /*
     * Take a positive number as input form user
     */
    printf("Enter a Positive Number\n"); 
    scanf("%d", &N); 
   
    printf("Printing <a href="#">Numbers</a> form %d to 1\n", N); 
    /*
     * Initialize the value of counter to N and keep on
     * decrementing it's value in every iteration till
     * counter > 0
     */
    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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h> 
   
int main() { 
    int counter, N; 
    /*
     * Take a positive number as input form user
     */ 
    printf("Enter a Positive Number\n"); 
    scanf("%d", &N); 
   
    printf("Printing <a href="#">Numbers</a> form %d to 1\n", N); 
    /*
     * Initialize the value of counter to N and keep on
     * decrementing it's value in every iteration till
     * counter > 0
     */
    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

Comments

Most Viewed

Write C program to enter any year and check whether year is leap year or not using conditional/ternary operator.

WAP to input week number and print week day name.

C Program to Find Third Angle of a Triangle