Task:
Write a function:
- exp(x,y):
- where x is positive (possibly a decimal) and y is a positive integer.
- Returns x to the y.
- The definition of x to the y: x multiplied by itself y times.
- Example: 2 to the 3 is 2*2*2.
- Example: 6 to the 1 is 6.
- Example: 12 to the 0 is 1. Anything to the 0 is 1, except 0. But you don't have to worry about 0.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
double exp(double&x,int y)
{
int n=1;
for(int=k;k<=y;k++)
n=n*x;
return n;
}
int main()
{
double x;
int y;
cout<<"Enter two numbers ";
cin>>x>>y;
exp(x,y);
cout<<x<<endl;
return 0;
}