递归练习之求 x 的 N 次方

/*********************************************************************************  
 Copyright (C), 1988-1999, drvivermonkey. Co., Ltd.  
 File name:   
 Author: Driver Monkey  
 Version:   
 Mail:bookworepeng@hotmail.com  qq:196568501
 Date: 2014.04.02  
 Description:   递归练习之求 x 的 N 次方 
 *********************************************************************************/  

#include <iostream>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <memory.h>
#include <thread> 
#include <stdlib.h>     /* labs */
#include <math.h>

using namespace std;


typedef struct
{
    int value;
    int flag;
}valut_t;

typedef struct
{
    valut_t value_50;
    valut_t value_25;
    valut_t value_10;
    valut_t value_5;
    valut_t value_1;
}all_value_t;

static int  fuction(int x, int n);

int main()
{
    cout<<"fuction = " <<fuction(4,3)<<endl;
    return 0;
}

static int  fuction(int x, int n)
{
    if(n == 0)
    {
        return 1;
    }
    if(n == 1)
    {
        return  x;
    }
    return x * fuction(x, n-1);
}



          
展开阅读全文

没有更多推荐了,返回首页