更多資源請關注紐扣編程微信公眾號
http://noi.openjudge.cn/ch0103/20/
描述
給定非負整數n,求2n。
輸入
一個整數n。0 <= n < 31。
輸出
一個整數,即2的n次方。
樣例輸入
3
樣例輸出
8
參考程序-1
#include<bits/stdc++.h>
using namespace std;int main(){int n;cin>>n;int ans=1;for(int i=0;i<n;i++){//n個2相乘ans=ans*2;}cout<<ans;return 0;
}
參考程序-2
#include<bits/stdc++.h>
using namespace std;int main(){int n;cin>>n;int ans=pow(2,n);//pow 函數 參數1-底數 參數2-指數cout<<ans;return 0;
}