first with while loop
//A program to print/display 1 to 10 natural numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1;
while(k<=10)
{
printf("%d,",k);
k++;
}
getch();
}
now with for loop
//A program to print/display 1 to 10 natural numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int k;
for(k=1;k<=10;k++)
{
printf("%d,",k);
}
getch();
}
now using do..while loop
//A program to print/display 1 to 10 natural numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1;
do
{
printf("%d,",k);
k++;
}
while(k<=10);
getch();
}
//A program to print/display 1 to 10 natural numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1;
while(k<=10)
{
printf("%d,",k);
k++;
}
getch();
}
now with for loop
//A program to print/display 1 to 10 natural numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int k;
for(k=1;k<=10;k++)
{
printf("%d,",k);
}
getch();
}
now using do..while loop
//A program to print/display 1 to 10 natural numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1;
do
{
printf("%d,",k);
k++;
}
while(k<=10);
getch();
}
No comments:
Post a Comment