The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include <conio.h>
#include <math.h>
template<typename T>
T power(T x, T y)
{
return pow(x,y);
}
void main()
{
cout<<"Power of integer: "<<power(2, 7)<<endl;
cout<<"Power of float: "<<power(3.5, 2.0)<<endl;
getch();
clrscr();
}
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
#include <math.h>
using namespace std;
template <typename T>
T power(T x, T y)
{
return pow(x,y);
}
int main()
{
cout<<"Power of integer: "<<power(2, 7)<<endl;
cout<<"Power of float: "<<power(3.5, 2.0)<<endl;
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP