avr39-ripe

maxTemplate

Mar 27th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. int fakt(int n)
  2. {
  3.         if ( n == 0) return 1;
  4.         return n * fakt(n - 1);
  5. }
  6.  
  7.  
  8.  
  9.  
  10.  
  11. #include <iostream>
  12. using namespace std;
  13.  
  14. template <typename T> T maxi(T a, T b)
  15. {
  16.     if (a > b) return a;
  17.     return b;
  18. }
  19.  
  20. template <typename T> T maxi(T a, T b, T c)
  21. {
  22.     return maxi(maxi(a,b),c);
  23. }
  24.  
  25. template <typename T> T maxi(T a, T b, T c, T d)
  26. {
  27.     return maxi(maxi(a,b),maxi(c,d));
  28. }
  29.  
  30.  
  31. int main()
  32. {
  33.     cout<<maxi(10, 23)<<endl;
  34.     cout<<maxi(10.1,10.2)<<endl;
  35.     cout<<maxi(1,2,3)<<endl;
  36.     cout<<maxi(1,4,3,2)<<endl;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment