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


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: