c++ program to get two integers from the user x,y and calculate x power y using recursion and pointers
#include <iostream>
using namespace std;
int pow(int *, int *);
int main()
{
int x,y;
cout<<"Enter the value for x\n";
cin>>x;
cout<<"Enter the value for y\n";
cin>>y;
cout<<x<<" ^ "<<y<<" = "<<pow(&x,&y)<<"\n";
return 0;
}
int pow(int *x, int *y)
{
int power=1;
for(int i=0;i<*y;i++)
{
power=(power * *x);
}
return power;
}
Comments
Leave a comment