Advertisement
Crackbone

Zadatak8.3

Dec 18th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T>  T maximum(T a, T b) {
  5.     if (a > b) {
  6.         return a;
  7.     }
  8.     else {
  9.         return b;
  10.     }
  11. }
  12. template <class T> T apsolute(T x)
  13. {
  14.     if (x < 0)
  15.         x = x * (-1);
  16.  
  17.     return x;
  18. }
  19.  
  20. int main() {
  21.     int a = 3, b = 5;
  22.     double c = 3.1, d = 5.2;
  23.  
  24.     cout << maximum(a, b) << endl;
  25.     cout << maximum(c, d) << endl;
  26.  
  27.     int e = -1, f = -2;
  28.     double g = 5.3, h = -3.2;
  29.  
  30.     cout << apsolute(e) << endl;
  31.     cout << apsolute(f) << endl;
  32.     cout << apsolute(g) << endl;
  33.     cout << apsolute(h) << endl;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement