描述
给定非负整数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
有人看看这是错哪了?