描述
给定非负整数n,求2n。
输入
一个整数n。0 <= n < 31。
输出
一个整数,即2的n次方。
样例输入
3
样例输出
8
#include
#include
using namespace std;
int main()
{
int n,a=1;
cin>>n;
for (i=1,i<=n,i++)
{
a*=2
};
cout<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 ‘’; did you forget to ‘#include ’?
2 | #include
+++ |+#include
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</home/runner/temp/35942998.6489/Main.cc:12:2: note: ‘std::cout’ is defined in header ‘’; did you forget to ‘#include ’?
/home/runner/temp/35942998.6489/Main.cc:12:9: error: expected ‘)’ before ‘;’ token
12 | cout</home/runner/temp/35942998.6489/Main.cc:8:6: note: to match this ‘(’
8 | for (i=1,i<=n,i++)
显示Compile Error
有人看看这是错哪了?
#include <iostream>
using namespace std;
第9行,for(int i=1;i<=n;i++)
11行,a*=2; 末尾要加分号