[刷题] 求平方

例题:编写函数,求一个数的平方

#include <iostream>
using namespace std;

int power(int a,int b);

int main(){
    int n;
    n = power(3,3);
    printf("%d
",n);
}

int power(int a,int b){
    int i;
    int r = a;
    if(b == 0){
        return 1;
    }
    for(i = 1;i < b;i++)
        r = r*a;
    return r;
}
原文地址:https://www.cnblogs.com/cxc1357/p/10513689.html