Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int pow(int x, int y)
- {
- if (x == 1 || y==0)
- {
- return 1;
- }
- else if (y == 1)
- {
- return x;
- }
- else
- {
- return x * pow(x, y - 1);
- }
- }
- int main()
- {
- int x, y;
- cout << "Enter a num and its power: ";
- cin >> x; cin >> y;
- cout << " Product is: ";
- cout<<pow(x, y);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement