first with while loop
// program to print/display all odd numbers lying between 1 and 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1;
while(k<=100)
{
if(k%2!=0)
{
printf("%d,",k);
}
k++;
}
getch();
}
now with for loop
//program to print/display all odd numbers lying between 1 and 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int k,n;
for(k=1;k<=100;k++)
{
if(k%2!=0)
{
printf("%d,",k);
}
}
getch();
}
now using do..while loop
//program to print/display all odd numbers lying between 1 and 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1,n;
do
{
if(k%2!=0)
{
printf("%d,",k);
}
k++;
}
while(k<=100);
getch();
}
We can also use some other methods as shown below using different loop.
//program to print/display all odd numbers lying between 1 and 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1;
while(k<=100)
{
printf("%d,",k);
k=k+2;
}
getch();
}
You now try same using other loops.
// program to print/display all odd numbers lying between 1 and 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1;
while(k<=100)
{
if(k%2!=0)
{
printf("%d,",k);
}
k++;
}
getch();
}
now with for loop
//program to print/display all odd numbers lying between 1 and 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int k,n;
for(k=1;k<=100;k++)
{
if(k%2!=0)
{
printf("%d,",k);
}
}
getch();
}
now using do..while loop
//program to print/display all odd numbers lying between 1 and 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1,n;
do
{
if(k%2!=0)
{
printf("%d,",k);
}
k++;
}
while(k<=100);
getch();
}
We can also use some other methods as shown below using different loop.
//program to print/display all odd numbers lying between 1 and 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1;
while(k<=100)
{
printf("%d,",k);
k=k+2;
}
getch();
}
You now try same using other loops.