nzbfcsl 2022-09-08 22:14 采纳率: 100%
浏览 22
已结题

openjudge 20:计算2的幂

描述
给定非负整数n,求2n。

输入
一个整数n。0 <= n < 31。
输出
一个整数,即2的n次方。
样例输入
3
样例输出
8


#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
    int n,a=1;
    cin>>n;
    for (i=1,i<=n,i++)
    {
        a*=2
    };
    cout<<a;
    return 0;
}

错误信息如下

/home/runner/temp/35942998.6489/Main.cc: In function ‘int main()’:
/home/runner/temp/35942998.6489/Main.cc:7:2: error: ‘cin’ was not declared in this scope
    7 |  cin>>n;
      |  ^~~
/home/runner/temp/35942998.6489/Main.cc:3:1: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
    2 | #include<math.h>
  +++ |+#include <iostream>
    3 | using namespace std;
/home/runner/temp/35942998.6489/Main.cc:8:7: error: ‘i’ was not declared in this scope
    8 |  for (i=1,i<=n,i++)
      |       ^
/home/runner/temp/35942998.6489/Main.cc:12:2: error: ‘cout’ was not declared in this scope
   12 |  cout<<a;
      |  ^~~~
/home/runner/temp/35942998.6489/Main.cc:12:2: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
/home/runner/temp/35942998.6489/Main.cc:12:9: error: expected ‘)’ before ‘;’ token
   12 |  cout<<a;
      |         ^
      |         )
/home/runner/temp/35942998.6489/Main.cc:8:6: note: to match this ‘(’
    8 |  for (i=1,i<=n,i++)

显示Compile Error
有人看看这是错哪了?

  • 写回答

2条回答 默认 最新

  • 快乐鹦鹉 2022-09-08 22:18
    关注
    #include <iostream>
    using namespace std;
    
    

    第9行,for(int i=1;i<=n;i++)
    11行,a*=2; 末尾要加分号

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月18日
  • 已采纳回答 9月10日
  • 创建了问题 9月8日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度