"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Sunday, February 21, 2010

Write a program that uses a function power() to raise a number m to power n. The function takes int values for m and n and returns the result correctly. Use a default value of 2 for n to make the function calculate square of m when the value for n is missing while calling


double power(int m, int n = 2)
double res = pow(m,n);
return res;

void main()
int x;

cout<< "\n Enter a number to calculate its square :";
double d = power(x);
cout<< "\n The square of " << x <<"is " << d;

cout<< "\n Enter a number to calculate its cube :";

 d = power(x,3);
cout<< "\n The cube of " << x <<"is " << d;

int y;
cout<< "\n Enter a number  and its power to calculate the result :";

d = power(x,y);
cout<< "\n The " << x << " to the power " << y <<" is " << d;

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.