| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
 
# include< stdio.h > 
# include< math.h > 
 
 
int main() 
{ 
        int a; 
        int b; 
        int Pow(  int m, int n ); 
         
         
        while( 1 ) 
        { 
                 
                printf( "Please input 2 numbers:\n" ); 
                 
                scanf( "%d, %d", &a, &b ); 
                getchar(); 
                printf( "The power is %d.\n", Pow( a, b ) ); 
                getchar(); 
        } 
} 
 
 
int IsEven( int Y )                                                                        //判断奇偶 
{ 
        if( ( Y % 2 ) == 0 ) 
                return 1; 
        else  
                return 0; 
} 
 
 
 int 
Pow(  int X, int N )                                                                                        //递归求幂运算 
{ 
         if( N == 0 ) 
         { 
                 return 1; 
         }         
         if( N == 1 ) 
         { 
                 return X; 
         }         
         if( IsEven( N ) ) 
         { 
                 return Pow( (X * X), (N / 2) ); 
         }         
         else 
         { 
                 return Pow( (X * X), (N / 2) ) * X; 
                  
         }         
} 
 
 
 
 
//这个程序在VB6怎么也得不出正确的运算结果,不知道哪出问题了,望来个大佬解惑,感激感谢   
- #include <stdio.h>
 
 - #include <math.h>
 
  
- int main(){
 
 -         int POW(int b, int e);
 
 -         int a, b;
 
 -         printf("Please enter 2 integer: ");
 
 -         scanf("%d%d", &a, &b);
 
 -         printf("The power %d of %d is %d", b, a, POW(a, b));
 
 -         return 0;
 
 - }
 
  
- int POW(int b, int e){
 
 -         if(!(e)) return 1;
 
 -         else if(e == 1) return b;
 
 -         else if(!(e%2)) return POW(b*b, e/2);
 
 -         else return POW(b*b, e/2)*b;
 
 - }
 
  复制代码 
 
 
 |   
 
 
 
 |