Advertisement
JosepRivaille

X46340: Funció per la suma del mínim i el màxim de tres e

Mar 14th, 2015
1,140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. //Pre: Llegeix 3 enters
  6. //Post: Suma el màxim i el minim
  7. int sum_min_max(int x, int y, int z) {
  8.     int d, g, p;
  9.     if (x <= y && x <= z) {
  10.         p = x;
  11.         if (y <= z) g = z;
  12.         else g = y;
  13.     }
  14.     else if (y <= x && y <= z) {
  15.         p = y;
  16.         if (x <= z) g = z;
  17.         else g = x;
  18.     }
  19.     else {
  20.         p = z;
  21.         if (x <= y) g = y;
  22.         else g = x;
  23.     }
  24.     d = g + p;
  25.     return d;
  26. }
  27.  
  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