Advertisement
howarto

Problem P73231_ca: Màxim de quatre enters

Oct 31st, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // PRE: 2 enters
  6. // POS: màxim dels dos enters introduits
  7. int max2 (int a, int b) {
  8.     if (a < b) return b;
  9.     else return a;
  10. }
  11.  
  12. // PRE: 4 enters
  13. // POS: retorna el màxim dels 4 enters
  14. int max4(int a, int b, int c, int d) {
  15.     return max2(max2(a,b),max2(c,d));
  16. }
  17.  
  18. int main() {
  19.      int a, b, c, d;
  20.      cin >> a >> b >> c >> d;
  21.      cout << max4(a, b, c, d) << endl;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement