Answer to Question #219835 in C++ for qwe

Question #219835

c++ program to get two integers from the user x,y and calculate x power y using recursion and pointers


1
Expert's answer
2021-07-22T18:32:58-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS