fork download
  1. #include<iostream>
  2. using namespace std;
  3. int power(int x, int y)
  4. {
  5. if(y==0)
  6. {
  7. return 1;
  8.  
  9. }
  10.  
  11. else if(y%2==0)
  12. {
  13. return power(x,y/2)*power(x,y/2);
  14. }
  15. else{
  16. return x*power(x,y/2)*power(x,y/2);
  17. }
  18.  
  19.  
  20.  
  21. }
  22.  
  23.  
  24. int main()
  25. {
  26. int x,y;
  27. cout<<"Enter number xand y"<<endl;
  28. cin>>x>>y;
  29.  
  30. cout<<power(x,y);
  31.  
  32. return 0;
  33.  
  34.  
  35. }
  36.  
Success #stdin #stdout 0.01s 5524KB
stdin
Standard input is empty
stdout
Enter number xand y
0