Advertisement
JosepRivaille

Suma del mínim i el màxim de tres enters

Feb 19th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //Precondició: Llegeix 3 enters
  5. //Postcondició: Retorna la suma del màxim i el mínim
  6.  
  7. int main() {
  8.   int x, y, z, max, min;
  9.   cin >> x;
  10.   max = x;
  11.   cin >> y;
  12.   if (y > x) {
  13.     max = y;
  14.     min = x;
  15.   }else min = y;
  16.   cin >> z;
  17.   if (z > max) max = z;
  18.   else if (z < min) min = z;
  19.   cout << max + min << endl;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement