juinda

absolute

Jun 14th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<class T>
  5. T absoluteValue(T& n1, T& n2)
  6. {
  7. return n1 > n2 ? n1 - n2 : n2 - n1;
  8. }
  9.  
  10. int main()
  11. {
  12. int i1, i2;
  13. double d1, d2;
  14. char c1, c2;
  15. i1 = 10; i2 = 20;
  16. cout << "Absolute value of 10, 20 is " << absoluteValue(i1, i2) << endl;
  17.  
  18. d1 = 5.5; d2 = 3.1;
  19. cout << "Absolute value of 5.5, 3.1 is " << absoluteValue(d1, d2) << endl;
  20.  
  21. return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment