早教吧作业答案频道 -->英语-->
acmRuntimeError为何会出现这个问题?该怎么改?DescriptionAspartofanarithmeticcompetencyprogram,yourstudentswillbegivenrandomlygeneratedlistsoffrom2to15uniquepositiveintegersandaskedtodeterminehowmanyitemsine
题目详情
acm Runtime Error 为何会出现这个问题?该怎么改?
Description
As part of an arithmetic competency program,your students will be given randomly generated lists of from 2 to 15 unique positive integers and asked to determine how many items in each list are twice some other item in the same list.You will need a program to help you with the grading.This program should be able to scan the lists and output the correct answer for each one.For example,given the list
1 4 3 2 9 7 18 22
your program should answer 3,as 2 is twice 1,4 is twice 2,and 18 is twice 9.
Input
The input will consist of one or more lists of numbers.There will be one list of numbers per line.Each list will contain from 2 to 15 unique positive integers.No integer will be larger than 99.Each line will be terminated with the integer 0,which is not considered part of the list.A line with the single number -1 will mark the end of the file.The example input below shows 3 separate lists.Some lists may not contain any doubles.
Output
The output will consist of one line per input list,containing a count of the items that are double some other item.
Sample Input
1 4 3 2 9 7 18 22 0
2 4 8 10 0
7 5 11 13 1 3 0
-1
Sample Output
3
2
0
#include
using namespace std;
int main()
{
\x05int n,sum=0,m;
\x05float a[15];
\x05while(a[0]!=-1)
\x05{
\x05\x05for(n=0;;n++)
\x05\x05{
\x05\x05\x05cin>>m;
\x05\x05\x05a[n]=m;
\x05\x05\x05if(m==0||m==-1)
\x05\x05\x05\x05break;
\x05\x05}
\x05\x05
\x05\x05if(a[0]==-1)
\x05\x05\x05break;
\x05\x05
\x05\x05for(int i=0;i
Description
As part of an arithmetic competency program,your students will be given randomly generated lists of from 2 to 15 unique positive integers and asked to determine how many items in each list are twice some other item in the same list.You will need a program to help you with the grading.This program should be able to scan the lists and output the correct answer for each one.For example,given the list
1 4 3 2 9 7 18 22
your program should answer 3,as 2 is twice 1,4 is twice 2,and 18 is twice 9.
Input
The input will consist of one or more lists of numbers.There will be one list of numbers per line.Each list will contain from 2 to 15 unique positive integers.No integer will be larger than 99.Each line will be terminated with the integer 0,which is not considered part of the list.A line with the single number -1 will mark the end of the file.The example input below shows 3 separate lists.Some lists may not contain any doubles.
Output
The output will consist of one line per input list,containing a count of the items that are double some other item.
Sample Input
1 4 3 2 9 7 18 22 0
2 4 8 10 0
7 5 11 13 1 3 0
-1
Sample Output
3
2
0
#include
using namespace std;
int main()
{
\x05int n,sum=0,m;
\x05float a[15];
\x05while(a[0]!=-1)
\x05{
\x05\x05for(n=0;;n++)
\x05\x05{
\x05\x05\x05cin>>m;
\x05\x05\x05a[n]=m;
\x05\x05\x05if(m==0||m==-1)
\x05\x05\x05\x05break;
\x05\x05}
\x05\x05
\x05\x05if(a[0]==-1)
\x05\x05\x05break;
\x05\x05
\x05\x05for(int i=0;i
▼优质解答
答案和解析
#include
using namespace std;
int main()
{
int n,sum=0,m;
int a[150]={0};//用整数,数组开大一点
while(a[0]!=-1)//赋个值,不然是随机值,不对的,有可能一开始就是-1了,就退出了
{
for(n=0;;n++)
{
cin>>m;
a[n]=m;
if(m==0||m==-1)
break;
}
if(a[0]==-1)
break;
for(int i=0;i
using namespace std;
int main()
{
int n,sum=0,m;
int a[150]={0};//用整数,数组开大一点
while(a[0]!=-1)//赋个值,不然是随机值,不对的,有可能一开始就是-1了,就退出了
{
for(n=0;;n++)
{
cin>>m;
a[n]=m;
if(m==0||m==-1)
break;
}
if(a[0]==-1)
break;
for(int i=0;i
看了acmRuntimeError...的网友还看了以下:
物理电学问题,求解答答案(1)Q=q(2)R<r:E=q/(4πεr*r):R>=r:E=qr*r/ 2020-03-31 …
设A是n阶矩阵A^2=E,证明r(A+E)+r(A-E)=n,的一步证明过程不懂由A^2=E,得A 2020-05-14 …
E^2*R/(R+r)^2=E^2/(R-r)^2/R+4r(某公式推导最后两行)本人只得:=E^ 2020-06-07 …
线性代数求解有n阶矩阵A,满足(A+E)(A-E)=0,怎么得出R(A+E)+R(A-E)≤n不懂 2020-06-28 …
matlab求解二阶导数方程,四个方程四个未知量>>symst>>E=32;G=10.81;b=2 2020-07-19 …
对的打对错的打错gowithuslikecollectdollsturntoleftonfootgo 2020-11-01 …
设A是2阶方阵,且A^2=E,A不等于±E,证明:r(A+E)=r(A-E)=1 2020-11-02 …
(e)(a)(r)thush(e)(r)sh(i)(r)tl(e)(a)(r)ncol(o)(u)( 2020-11-27 …
有四种短周期的主族元素R,E,X,Y,其在周期表中的位置如图所示R,X,Y的原子序数之和为37,下列 2020-12-05 …
这几个字母怎么拼才是单词呢?B-E-E-N-M-O-R-VA-E-R-T-WA-B-C-D-O-P- 2021-02-09 …