当前位置:网站首页>电子协会 C语言 1级 32、计算2的幂
电子协会 C语言 1级 32、计算2的幂
2022-07-02 01:29:00 【dllglvzhenfeng】
方法一:
/*
电子协会 C语言 1级 32、计算2的幂 方法一
给定非负整数 n,求 2n。
输入
一个整数 n。0 <= n < 31。
输出
一个整数,即 2 的 n 次方。
样例输入
3
样例输出
8
*/
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
cin>>n;
cout<<pow(2,n);
return 0;
}
/*
12:计算2的N次方
http://noi.openjudge.cn/ch0106/12/
2809:计算2的N次方
http://bailian.openjudge.cn/practice/2809/
13:乘方计算
http://noi.openjudge.cn/ch0105/13/
*/
方法二:
/*
电子协会 C语言 1级 32、计算2的幂 方法二
给定非负整数 n,求 2^n。
输入
一个整数 n。0 <= n < 31。
输出
一个整数,即 2 的 n 次方。
样例输入
3
样例输出
8
*/
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,ans=1;
cin>>n;
for(int i=1;i<=n;i++)
{
ans*=2;
}
cout<<ans<<endl;
return 0;
}
/*
12:计算2的N次方
http://noi.openjudge.cn/ch0106/12/
2809:计算2的N次方
http://bailian.openjudge.cn/practice/2809/
13:乘方计算
http://noi.openjudge.cn/ch0105/13/
*/
相关的题目的链接:
12:计算2的N次方
2809:计算2的N次方
13:乘方计算
啊哈C语言 第1章 编程改变思维(第0讲)
啊哈C语言 第1章 编程改变思维(第0讲)_dllglvzhenfeng的博客-CSDN博客
啊哈C语言 第2章 梦想直航(第1-8讲)
啊哈C语言 第2章 梦想直航(第1-8讲)_dllglvzhenfeng的博客-CSDN博客_啊哈c语言
啊哈C语言 第3章 较量才刚刚开始(第9-15讲)
啊哈C语言 第3章 较量才刚刚开始(第9-15讲)_dllglvzhenfeng的博客-CSDN博客
啊哈C语言 第4章 重量级选手登场(第16-23讲)
啊哈C语言 第4章 重量级选手登场(第16-23讲)_dllglvzhenfeng的博客-CSDN博客
啊哈C语言 第5章 好戏在后面(第24-25讲)
啊哈C语言 第5章 好戏在后面(第24-25讲)_dllglvzhenfeng的博客-CSDN博客
啊哈C语言 第6章 天啊!一大串数正在接近(第26讲)
啊哈C语言 第6章 天啊 一大串数正在接近(第26讲)_dllglvzhenfeng的博客-CSDN博客
啊哈C语言 第7章 有了它你能做更多的事(第27-28讲)
啊哈C语言 第7章 有了它你能做更多的事(第27-28讲)_dllglvzhenfeng的博客-CSDN博客
啊哈C语言 第8章 游戏时间到了(第29讲)
边栏推荐
- SQL injection for Web Security (2)
- I Brief introduction of radio energy transmission technology
- Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
- Basic number theory -- Gauss elimination
- Leetcode, 3 repeatless longest subsequence
- [Floyd] post disaster reconstruction
- [WesternCTF2018]shrine writeup
- CTF daily question day45 sensor
- Using tabbar in wechat applet
- ACM教程 - 快速排序(常规 + 尾递归 + 随机基准数)
猜你喜欢
[IVX junior engineer training course 10 papers] 06 database and services
KS006基于SSM实现学生成绩管理系统
How does schedulerx help users solve the problem of distributed task scheduling?
[IVX junior engineer training course 10 papers to get certificates] 0708 news page production
matlab 使用 resample 完成重采样
学习笔记24--多传感器后融合技术
LeetCode、3无重复最长子序列
Android: how can golden nine and silver ten squeeze into the first-line big factories from small and medium-sized enterprises? The depth of interview questions in large factories
[image enhancement] vascular image enhancement based on frangi filter with matlab code
6-3 vulnerability exploitation SSH environment construction
随机推荐
Feature extraction and detection 16 brisk feature detection and matching
MySQL application day02
微信小程序中使用tabBar
[Floyd] post disaster reconstruction
ACM教程 - 快速排序(常规 + 尾递归 + 随机基准数)
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd
Unity AssetBundle subcontracting
Global and Chinese market of ancillary software 2022-2028: Research Report on technology, participants, trends, market size and share
Part 29 supplement (XXIX) basis of ECMAScript
II Basic structure of radio energy transmission system
Android high frequency network interview topic must know and be able to compare Android development environment
Penser au jeu 15: penser au service complet et au sous - service
Finally got byte offer, 25-year-old inexperienced experience in software testing, to share with you
Appium inspector can directly locate the WebView page. Does anyone know the principle
[IVX junior engineer training course 10 papers] 06 database and services
CEPH buffer yyds dry inventory
Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)
学习笔记3--高精度地图关键技术(上)
Learning notes 25 - multi sensor front fusion technology
Exclusive delivery of secret script move disassembly (the first time)