26.8.15

Implement function overloading

Write a C++ program to implement function overloading in order to compute power(m,n) where i) m is double and n is int ii) m and n are int.

#include<iostream.h>

#include<conio.h>
#include<math.h>

int power(int a,int b);

double power(int i, double d);

int main()

{

int i1,i2,i3; double d1; clrscr();
cout<<"\nEnter Two Integer Numbers To Calculate Power : "; cin >>i1>>i2;
int p1=power(i1,i2);

cout<<"\nThe Power of "<<i1<<" and "<<i2<<" is : "<<p1; cout<<"\n\nEnter One Integer And One Double To calculate power :"; cin>>i3>>d1;

double p2=power(i3,d1);

cout<<"\nThe Power of "<<i3<<" and "<<d1<<" is : "<<p2; getch();
return(0);

}

int power(int a,int b)

{
return(pow(a,b));
}
double power(int i, double d)
{
return(pow(i,d));
}


********************************OUTPUT**********************************

Enter Two Integer Numbers To Calculate Power : 2  4

The Power of 2 and 4 is : 16

Enter One Integer And One Double To calculate power :2 2.5


The Power of 2 and 2.5 is : 5.656854

No comments:

Post a Comment

Comment Here