0
点赞
收藏
分享

微信扫一扫

天梯赛习题集 L 1 - 012 计算指数 (5 分)

岁月不饶人老不正经 2022-04-14 阅读 102
c++

真的没骗你,这道才是简单题 —— 对任意给定的不超过 10 的正整数 n,要求你输出 2n。不难吧?

输入格式:

输入在一行中给出一个不超过 10 的正整数 n。

输出格式:

在一行中按照格式 2^n = 计算结果 输出 2n 的值。

输入样例:

5

输出样例:

2^5 = 32

 

代码长度限制:16 KB

时间限制:400 ms

内存限制:64 MB

题解代码:

#include <iostream>
#include <cstdio>

using namespace std;

int n;
int res = 1;

int main(){
    cin >> n;
    int i = n;
    while(n--){
        res *= 2;
    }
    printf ("2^%d = %d", i, res);
    return 0;
}
举报

相关推荐

0 条评论