真的没骗你,这道才是简单题 —— 对任意给定的不超过10的正整数n,要求你输出2^n 。
输入在一行中给出一个不超过10的正整数n。
在一行中按照格式 2^n = 计算结果
输出2^n的值。
5
2^5 = 32
1 #include <cstdio> 2 #include <cmath> 3 using namespace std; 4 int main() { 5 int n; 6 scanf("%d", &n); 7 printf("2^%d = %d", n, (int)pow(2, n)); 8 //pow返回一个double型,如果不想用int强制转换可以写成“printf("2^n = %.0f", n, pow(2, n));”也能过 9 return 0; 10 }
原文:https://www.cnblogs.com/lavaicer/p/12789536.html