如下:
#include<iostream>
#define endl '\n'
using namespace std;
signed main() {
ios::sync_with_stdio(0);//关流
cout.tie(0);
cin.tie(0);
int top = 1,n=0;
cout << "请输入需要求的2的次方数字:";
cin >> n;
int* a = (int*)calloc(n, sizeof(a));
a[0] = 1;
for (int i = 0; i < n; i++) {
int t = 0;
for (int j = 0; j < top; j++)
{
t += a[j]*2;
a[j] = t % 10;
t /= 10;
}
if (t)a[top++]++;
cout << "2的" << i+1 << "次方为";
for (int i2 = top - 1; i2 >= 0; i2--) {
cout << a[i2];
}
cout << endl;
}free(a);
return 0;
}