PTA L1-012 计算指数 C++实现

计算指数

真的没骗你,这道才是简单题 —— 对任意给定的不超过 10 的正整数 n,要求你输出 2​n​​。不难吧?
输入格式:
输入在一行中给出一个不超过 10 的正整数 n。
输出格式:
在一行中按照格式 2^n = 计算结果 输出 2​n​​ 的值。
输入样例:

5

输出样例:

2^5 = 32

Talk is cheap. Show me the code.

#include<iostream>
#include<cmath>

using namespace std;
int main()
{    
	int n;    
	cin>>n;    
	cout<<"2^"<<n<<" = "<<pow(2,n);
} 

测试结果

在这里插入图片描述

发布了24 篇原创文章 · 获赞 1 · 访问量 220

猜你喜欢

转载自blog.csdn.net/weixin_43646424/article/details/104432874