请大家帮我看看这段代码有问题么 执行起来巨慢无比
初学C++,写了一小段为练习函数的封装和参数的传递,做简单的A的B次方运算
代码如下:
#include <iostream>int power (int a,int b){ int i,j; j=a; for (i=1;i<b;i++) {j=j*a;} return j;}int main(){ using namespace std; int A,B,Ans; cout<<"Let's calculate A^B!\n"; cout<<"Please enter the Value A:"; cin>>A; cout<<"Please enter the Value B:"; cin>>B; Ans=power(A,B); cout<<"The answer is:"<<Ans<<"\n"; system ("pause"); return 0;}