I need help for this homework create a for loop that returns

I need help for this homework, create a for loop that returns all the odd numbers between 1 and 100.

Solution

Answer:-

#include<iostream.h>

#include<conio.h>

main()
{
clrscr();

cout<<\"\ odd numbers between 1 to 100 :\"<<endl;


cout<<\"\ \ Using while loop : \"<<endl;
int i=1;

while(i<=100)
{
if(i%2==1)
cout<<\" \"<<i;
i++;
}

cout<<\"\ \ Using do-while loop :\"<<endl;

int j=1;

do
{
if(j%2==1)
cout<<\" \"<<j;
j++;
}
while(j<=100);

cout<<\"\ \ Using for loop :\"<<endl;

for(int k=1;k<=100;k++)
{
if(k%2==1)
cout<<\" \"<<k;
}

getch();
return 0;
}

I need help for this homework, create a for loop that returns all the odd numbers between 1 and 100.SolutionAnswer:- #include<iostream.h> #include<coni

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site