WAP using function template to add two numbers and display result.
#include <iostream>
using namespace std;
template<class t1,class t2>
void sum(t1 a,t2 b)//defining template function
{
cout<<"\sum="<<a+b<<endl;
}
int main()
{
int a,b;
float x,y;
cout << "\nEnter two integer data: " << endl;
cin>>a>>b;
cout << "\nEnter two float data: " << endl;
cin>>x>>y;
sum(a,b);//adding two integer type data
sum(x,y);//adding two float type data
sum(a,x);//adding float and integer type data
return 0;
}
Comments
Leave a comment