高精度运算
2的n次方代码
#include<iostream>
#include<cstdio>
using namespace std;
const int N = 3010;
int main()
{
int a[N] = { 1 };//保证首项是1可以乘
int n; //n次方
cin >> n;
int m=1; //代表几位数位数
for (int i = 0; i < n; i++)//乘方循环
{
int t = 0;
for (int j = 0; j < m; j++)//位数循环
{
t += a[j] * 2;
a[j] = t % 10;
t /= 10;
}
if (t) a[m++] = 1; //如果有进一,位数m就加一。
}
for (int i = m - 1; i >= 0; i--) cout << a[i] << "";//倒序输出。
system("pause");
return 0;
}