Monday 8 April 2013

C++ PROGRAM TO COMPUTE POWER(m,n) Using Function OverLoading


/*C++ PROGRAM TO IMPLEMENT FUNCTION OVERLOADING IN ORDER TO COMPUTE POWER(m,n) WHERE
i)m IS DOUBLE AND n IS INT
ii)m & n ARE INT */
#include<iostream.h>
#include<conio.h>
#include<math.h>
double power(double m,int n)
{
double res=1.0;
res=pow(m,n);
return res;
}
int power(int m,int n)
{
int res=1;
res=pow(m,n);
return res;
}
void main()
{
double x;
int y;
clrscr();
cout<<"\nENTER THE VALUES AS DOUBLE & INTEGER TYPES:";
cin>>x>>y;
double res=power(x,y);
cout<<"\nPOW("<<x<<","<<y<<")="<<res<<endl;
int a,b;
cout<<"\nENTER THE VALUES AS INTEGER TYPES:";
cin>>a>>b;
int res1=power(a,b);
cout<<"\nPOW("<<a<<","<<b<<")="<<res1<<endl;
getch();
}

No comments:

Post a Comment