Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<class T>
- T absoluteValue(T& n1, T& n2)
- {
- return n1 > n2 ? n1 - n2 : n2 - n1;
- }
- int main()
- {
- int i1, i2;
- double d1, d2;
- char c1, c2;
- i1 = 10; i2 = 20;
- cout << "Absolute value of 10, 20 is " << absoluteValue(i1, i2) << endl;
- d1 = 5.5; d2 = 3.1;
- cout << "Absolute value of 5.5, 3.1 is " << absoluteValue(d1, d2) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment