【题目】
任意给定一个正整数N(N<=100),计算2的n次方的值。
输入:
输入一个正整数N。
输出:
输出2的N次方的值。
样例输入:
5
样例输出:
32
【题解】
#include <iostream>
#include <cstdio>
using namespace std;
int a[105], n, k;
int main() {
// freopen("data.in", "r", stdin);
// freopen("data.out", "w", stdout);
cin >> n;
a[0] = 1;
a[1] = 1;
for(int i=1; i<=n; i++){
k = 0;
for(int j=1; j<=a[0]; j++){
a[j] = a[j]*2 + k;
k = a[j] / 10;
a[j] %= 10;
}
if(k > 0){
a[0]++;
a[a[0]] = k;
}
}
for(int i=a[0]; i>0; i--)
cout << a[i];
// fclose(stdin);
// fclose(stdout);
return 0;
}
参考:https://zhuanlan.zhihu.com/p/341543181
【题解】
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,ans=1;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
ans=ans*2;
}
printf("%d",ans);
return 0;
}