Question
Write a complete C++ program that does the following. First it reads three integers and reports the median of those three integers. Next, it reads
Write a complete C++ program that does the following.
-
First it reads three integers and reports the median of those three integers.
-
Next, it reads integers until it reads 1. It reports the mean of all of those integers, excluding the 1 at the end.
Example 1
If the input is
3 9 5 4 5 8 20 25 -1
then your program should say:
The median of (3, 9, 5) is 5. The mean of (4, 5, 8, 20, 25) is 12.40
Using
Create integer variables x, y and z
int x, y, z;
Create a real-valued variable r
double r;
Read an integer and store it into x
scanf("%i", &x);
Read three integers and store them into x, y and z
scanf("%i%i%i", &x, &y, &z);
Read an integer and store it into x
scanf("%i", &x);
Write a string
If x = 4, y = 10, z = 3 and median = 4, then
printf("The median of %i, %i and %i is %i. ", &x, &y, &z, &median);
writes
The median of 4, 10 and 3 is 4.
Write an integer
printf("%i", x);
Write a real number
If r has type double, then
printf("%0.2lf", r);
If-statement with else
if(x > y & y > z) { } else { }
If-statement without else
if(x > y & y > z) { }
While-loops
while(x != -1) { }
Main function
int main() { ... return 0; }
___________________________________________________
What I have so far...
#includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started