编写一个程序,用C++风格的I/O从键盘上输入两个整数,然后显示一个以第一个数为底,第二个数为指数的结果

来源:百度知道 编辑:UC知道 时间:2024/04/28 20:20:06
用Viscual C++
才开始看C++的书,这是书上第四章的编程题的第一题,需要一个比较简单的答案,毕竟才刚开始学,书上不会出这么复杂的题吧

//简单的
#include<iostream>
using namespace std;

int main()
{
int a, b;
cout << "请输入一个数字" << endl;
cin >> a;
cout << "请输入另一个数字" << endl;
cin >> b;

int result = 1;
for ( int i = 0; i < b; i ++ )
result *= a;

cout << a << "的" << b << "次方的结果是" << result << endl;

return 0;
}

#include<iostream>
#include<iomanip>
using namespace std;

const int MAX_SIZE = 100000; /*for each result[ i ], result[ i ] >= 0 && result[ i ] < MAX_SIZE*/
int result[ MAX_SIZE ];

void init()
{
memset( result, 0, sizeof( result ) );
result[ MAX_SIZE - 1 ] = 1;
}

int exp( int a, int b ) /* compute a^b, return the beginning of the array result[ MAX_SIZE ] */
{
int begin = MAX_S