Advertisement
JosepRivaille

X46340: Funció per a la suma del mínim i el màxim de 3enters

Apr 4th, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int sum_min_max(int x, int y, int z) {
  6.     int d, g, p;
  7.     if (x <= y && x <= z) {
  8.         p = x;
  9.         if (y <= z) g = z;
  10.         else g = y;
  11.     }
  12.     else if (y <= x && y <= z) {
  13.         p = y;
  14.         if (x <= z) g = z;
  15.         else g = x;
  16.     }
  17.     else {
  18.         p = z;
  19.         if (x <= y) g = y;
  20.         else g = x;
  21.     }
  22.     d = g + p;
  23.     return d;
  24. }
  25.  
  26. //Pre: Llegeix 3 enters
  27. //Post: Escriu la suma del màxim i el mínim
  28. int main() {
  29.     int x, y, z;
  30.     cin >> x >> y >> z;
  31.     cout << sum_min_max(x, y, z) << endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement