本帖最后由 八幽之哥 于 2019-10-2 14:46 编辑
题目:
我的解答:
但是运行失败:
求解答,谢谢
第二行输入1个整数n
要求:找出6个数里和整数n相同的数的个数
例如:
输入:1 2 2 2 3 4
输入: 2
输出:3
我的解答:
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
{ int n,i,a[6];
int sum=0;
for(i=0;i<6;i++)
{ cin>>a;}
cin>>n
for(i=0;i<6;i++)
{if(a==n)
sum++;}
printf("%d",sum);
return 0;
}
但是运行失败:
--运行失败--
Command failed: "C:\AhaCpp\resources\core\bin\g++.exe" "F:\AhaCpp\resources\code\作业.cpp" -o "F:\AhaCpp\resources\code\作业.exe" -static-libgcc -static-libstdc++
F:\AhaCpp\resources\code\作业.cpp: In function 'int main()':
F:\AhaCpp\resources\code\作业.cpp:11:6: error: expected ';' before 'for'
for(i=0;i<6;i++)
^
F:\AhaCpp\resources\code\作业.cpp:11:21: error: expected ';' before ')' token
for(i=0;i<6;i++)
^
F:\AhaCpp\resources\code\作业.cpp:16:5: error: expected '}' at end of input
}
^
求解答,谢谢
题目:
我的解答:
但是运行失败:
求解答,谢谢
2021.12 数据,可能有更多内容
题目:第一行输入6个整数第二行输入1个整数n
要求:找出6个数里和整数n相同的数的个数
例如:
输入:1 2 2 2 3 4
输入: 2
输出:3
我的解答:
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
{ int n,i,a[6];
int sum=0;
for(i=0;i<6;i++)
{ cin>>a;}
cin>>n
for(i=0;i<6;i++)
{if(a==n)
sum++;}
printf("%d",sum);
return 0;
}
但是运行失败:
--运行失败--
Command failed: "C:\AhaCpp\resources\core\bin\g++.exe" "F:\AhaCpp\resources\code\作业.cpp" -o "F:\AhaCpp\resources\code\作业.exe" -static-libgcc -static-libstdc++
F:\AhaCpp\resources\code\作业.cpp: In function 'int main()':
F:\AhaCpp\resources\code\作业.cpp:11:6: error: expected ';' before 'for'
for(i=0;i<6;i++)
^
F:\AhaCpp\resources\code\作业.cpp:11:21: error: expected ';' before ')' token
for(i=0;i<6;i++)
^
F:\AhaCpp\resources\code\作业.cpp:16:5: error: expected '}' at end of input
}
^
求解答,谢谢
本帖最后由 gooding300 于 2019-10-2 15:31 编辑
1.main函数有两个左括号,请去掉一个
2.cin后面的a改成a[ i ]
3.cin>>n之后加上;
4.a==n改成a[ i ]==n
5.iostream和stdio不建议混用
如果我的回答对您的问题有所帮助,请给予最高的评分!
1.main函数有两个左括号,请去掉一个
2.cin后面的a改成a[ i ]
3.cin>>n之后加上;
4.a==n改成a[ i ]==n
5.iostream和stdio不建议混用
如果我的回答对您的问题有所帮助,请给予最高的评分!