7-4 计算指数 (5 分)

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

输入格式:

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

输出格式:

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

输入样例:

5

输出样例:

2^5 = 32
水题
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    int n,t;
    cin>>n;t=n;
    int ans=1;
    while(t--)
    {
        ans<<=1;
    }
    cout<<"2^"<<n<<" = "<<ans;    
    return 0; 
} 

猜你喜欢

转载自www.cnblogs.com/fakecoderLi/p/10506076.html