You are required to write a program in C++ that reads a list of (non-zero) integ
ID: 3626707 • Letter: Y
Question
You are required to write a program in C++ that reads a list of (non-zero) integers from the standard input device, and calculates and displays the difference of between the largest and the smallest of these values. The program will end when a 0 value is read.Also write another program that C++ to read a series of positive integers from the keyboard (treated as the standard input device), until a non-positive number (0,
or negative number) is read. Compute and display the average of those positive numbers that are read. Obviously we exclude the last non-positive number from the total and average calculation. Also please write algorithm after.
Explanation / Answer
Is the imput suposed to be entered all in one line or mutiples lines? int MaxMin(){ int n; int max = 0; int min = 0; Printf("List of intigers :"); (scanf("%d",&n); while ( n != 0){ if ( max == 0) min = max = n; // i'm assuming you can't ever have the value 0, otherwise you'll have to change the inicial values of max and min else if ( n > max) max = n; else if ( n 0){ n++; total += x; (scanf("%d",&x); } doube average = (double) total / n; printf(" average is %d ",average); } this is more C than C++ but if you change the input functions to cin and cout it's the same thing, didn't tested so it might be buggy but the basis is thereRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.