15. Write a C++ program to define function power to raise a number m to a power n the function takes a double value for m. And integervalue for n and return the result correctly use a default value of 2 for n to make the function calculate squares when this argument is omitted


#include<iostream.h>
#include<conio.h>
#include<math.h>
double power(double m,int n=2)
{
double t;
t=pow(m,n);
return t;
}
void main()
{
double num,ans;
int p;
cout<<“Enter the number: \n”;
cin>>num;
cout<<“\n enter the power:”;
cin>>p;
if(p==0)
{
ans=power(num);
cout<<“\nPower of “<<num<<” is “<<ans<<endl;
}
else
{
ans=power(num,p);
cout<<“\nPower of “<<num<<” is “<<ans<<endl;
}
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s