实现X*N

#include<iostream> 
using namespace std;

double foo(int n,double x) 
{ 
  if(1==n) 
  { 
	return x; 
  } 
  else 
  { 
	if(n%2==0) 
	  return foo(n/2,x*x); 
	else 
	  return x*foo((n-1)/2, x*x); 
  } 
} 

int main() 
{ 
  int n; 
  double x;
  cin >> x >>n; 
  cout<< foo(n,x) <<endl; 
} 

  

原文地址:https://www.cnblogs.com/eternal1025/p/4435558.html