Inefficient Median: You need to write a program that reads in two integers from cin and outputs an horribly inefficent calculation of the median value. First count from the first number to the second, but stop one short. Then, count from that number back towards the first, again stopping one short. Continue until you reach a single number.
So for the case of the first test I have 3 and 10
and the output should look like this
3 4 5 6 7 8 9
9 8 7 6 5 4
4 5 6 7 8
5 6 7
7 6
6
I have other questions of similar style but don't quite work. as it often leaves the 10 on the first line but in the output it needs to be gone. thank your for your help.
#include<iostream>
using namespace std;
int main()
{
int a,b,i,j,k=0;
//input two numbers
cout<<endl<<"Enter two numbers";
cin>>a>>b;
//assign the greatest number to b and smallest number
to a,if user enters the
//first number as big and second as small
if(a>b)
{
i=a;
a=b;
b=i;
}
//loop to continue the number of times toprint
do
{
if(k==0) //condition to print increasing
order
{
for(i=a;i<b;i++)
{
cout<<" "<<i; //print the value
}
k=1;
b=b-1;//update the value of b
}
else
{ //loop to print in decreasing
order
for(i=b;i>a;i--)
{
cout<<"
"<<i; //print the value
}
k=0;
a=a+1;//update
the value of a
}
cout<<endl;
}while(a!=b); //termination condition
}
OUTPUT
Get Answers For Free
Most questions answered within 1 hours.