A program to demonstrate the concept of generic function in C++

#include<iostream>
#include<conio.h>
using namespace std;
template<class t>
t area(t length, t breadth)
{
return(length*breadth);
}
main()
{
int l1=3, b1=5;
float l2=3.25, b2=5.24;
cout<<“Area=”<<area(l1,b1)<<endl;
cout<<“Area2=”<<area(l2,b2);
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *