我想,大家在做数学题的时候常会遇到这样的题:
这是不是太麻烦了?我们就用C++来编写一个程序,来解放双手吧!
Coed:
#include <bits/stdc++.h>
using namespace std;
int f(int x, int n)//自定义函数
{
if(n<2) return x;
return x*f(x,n-1);
}
int main()
{
double x,n;
cout<<"输入原数(整数):"; cin>>x;
cout<<"输入x的几次方:"; cin>>n;
cout<<x<<"的"<<n<<"次方是"<<f(x,n);//使用
return 0;
}
哈!感觉太好了!
试试看吧!