I'm going to print out the numbers 3-19 using a while loop: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 I'm going to print out the numbers 42-56 using a do-while loop: 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 I'm going to print out the numbers 87-95 using a for loop: 87 88 89 90 91 92 93 94 95 Now I'll print whatever numbers you'd like! Give me a starting number: 2 Give me an ending number: -4 I see that your ending number is lower. Okay, I'll count down! 2 1 0 -1 -2 -3 -4 ----jGRASP: operation complete.
#include<iostream>
using namespace std;
main()
{
int i=3;
while(i<=19)
{
cout<<i<<" ";
i++;
}
cout<<endl;
int j=42;
do
{
cout<<j<<" ";
j++;
}while(j<=56);
cout<<endl;
for(int k=87;k<=95;k++)
cout<<k<<" ";
cout<<endl;
cout<<"enter two numbers"<<endl;
int x,y;
cin>>x>>y;
if(x<=y)
{
for(int a=x;a<=y;a++)
cout<<a<<" ";
cout<<endl;
}
else
{
for(int a=x;a>=y;a--)
cout<<a<<" ";
cout<<endl;
}
return 0;
}
PS:If this answer is helpful for you then please give an upvote.
Get Answers For Free
Most questions answered within 1 hours.