Write a program that prints numbers(digits) from 1 to 10 :
There are three methods:
- By using while statement
- By using do-while statement
- By using for statement
1. By using while statement :
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
a=1;
while(a<=10)
{
printf("%d\n" ,a);
a++ ; // a=a+1
}
getch();
}
2. By using do-while statement :
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
a=1;
do
{
printf("%d\n" ,a);
a++ ; // a=a+1
} while(a<=10)
getch();
}
3. By using for statement
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
for(a=1 ;a<=10 ;a++)
{
printf("%d\n" ,a);
}
getch();
}
Output of all the above Three Programs:
1
2
3
4
5
6
7
8
9
10
0 Response to "C Program: Prints the digits from 1 to10 by using three Different Methods"
Post a Comment