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. & integer value for n & 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 a , int b=2)//fun. overloading
{
return pow(a,b);
}
void main()
{
clrscr();
double a;
int b;
char ch;
cout<<"\n Enter the number:-";
cin>>a;
cout<<"\n Enter your choice:-";
cin>>ch;
if(ch=='y')
{
cout<<"\n Enter the power:-";
cin>>b;
cout<<"\n (a^b)=\t"<<power(a,b);
}
else
{
cout<<"\n\n (a^b)=\t"<<power(a);
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<math.h>
double power(double a , int b=2)//fun. overloading
{
return pow(a,b);
}
void main()
{
clrscr();
double a;
int b;
char ch;
cout<<"\n Enter the number:-";
cin>>a;
cout<<"\n Enter your choice:-";
cin>>ch;
if(ch=='y')
{
cout<<"\n Enter the power:-";
cin>>b;
cout<<"\n (a^b)=\t"<<power(a,b);
}
else
{
cout<<"\n\n (a^b)=\t"<<power(a);
}
getch();
}