C Program To Print 10 to 1 Numbers Using While Loop
#include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("\n"); //for new line // While Loop n=10; //Initialize while(n>=1) // Condition { printf(" %d",n); n--; // Decrement } getch(); }
Output :
Display 10-1 Numbers using do..while loop
#include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("\n"); //for new line // Do While Loop n=10; // Initialize do { printf(" %d",n); n--; // Decrement } while(n>=1); // Condition getch(); }
C Program To Print Numbers From 10 To 1 Using For Loop
#include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("\n"); //for new line // For loop // (initialize; condition ; increment) for(n=10;n>=1;n--) { printf(" %d",n); } getch(); }
To Run this program in DevC++ we have to make some changes in the above program, after changes the code will look like this:
#include<stdio.h> int main() { int n; printf("\n"); //for new line // For loop // (initialize; condition ; increment) for(n=10;n>=1;n--) { printf(" %d",n); } getch(); return 0; }
Output :
In this way, we can easily display numbers in any range using different types of loops.