#include <iostream.h>
#include <conio.h>
#include<math.h>
//first function
int power(int n, int p=2)
{
int res = pow(n, p);
return res;
}
//second function
double power(double n, int p = 2)
{
double res;
res = pow(n,p);
return res;
}
void main()
{
int value, powr, result;
cout<< "\n Enter a value (any integer ) to find it's square:";
cin>> value;
// first function will be called
result = power(value);
cout<< "\n The square of " << value << " = " << result;
cout<< "\n Enter a value (any integer ) to find it's cube:";
cin>> value;
// first function will be called
result = power(value, 3);
cout<< "\n The cube of " << value < <" = " << result;
cout<< "\n Enter a value (any integer) :";
cin>> value;
cout<< "\n Enter its power (any integer) :";
cin>> powr;
// first function will be called
result = power(value, powr);
cout<< "\n The " << value < <" to the power of " << powr <<" is " << result;
int p;
float val, r;
float val, r;
cout<< "\n Enter a value :";
cin>> val;
cout<< "\n Enter its power ( integer):";
cin>> p;
//second function is called
r = power(val, p);
cout<< "\n The " << val << " to the power of " << p <<" is " << r;
cout<< "\n Enter a value :";
cin>> val;
// second function will be called
r = power(val);
cout<< "\n The square of " << val << " = " << r;
getch();
}
No comments:
Post a Comment