Write a C++ program with a while loop structure. This program will reads a list of
non-zero integers from the standard input device, and displays the largest and the
smallest number, and the difference between them. The program will end when a 0
value is read. This final value 0 will not participate in the required calculation.
Develop a Defining Diagram (i.e. an IPO Diagram) before writing the program.
1
Expert's answer
2012-09-07T10:38:53-0400
#include <iostream> using namespace std; #include <vector> #include <algorithm> int main() { vector <int> a; while (1) { & int i=0; & cin>>i; & if (i == 0) break; & a.push_back(i); } int max = *max_element(a.begin(),a.end()), min = *min_element(a.begin(),a.end()); cout<< "Max element: "<< max << "& Min element: " << min<<endl; cout<<"Different: " <<max - min<<endl; system("pause"); return 0; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment