当前位置: 代码迷 >> C语言 >> [求助]这个题结果对,但是提交错误,怎么回事啊
  详细解决方案

[求助]这个题结果对,但是提交错误,怎么回事啊

热度:88   发布时间:2007-10-11 23:28:07.0
[求助]这个题结果对,但是提交错误,怎么回事啊

这是我的代码
#include<stdio.h>
int main()
{
int i,a[10000],b[10000];
for(i=1;i<=10;i++)
{
scanf("%d",&a[i]);
if(a[i]==0)
break;
}
for(int k=1;k<i;k++)
b[k]=a[k];
for(int j=1;j<=i-1;j++)
{
if((b[j]-6)%4==0)
{
printf("%d is the sum of four consecutive integers.\n",b[j]); }
else
{
printf("%d]is not the sum of four consecutive integers.\n",b[j]); }

}
return 1;
}
这是题目
Input
A positive integer(<231), each case will be on a separate line. A zero (0) denotes the end of input.
Output
The phrase “ is not the sum of four consecutive integers.” or the phrase “ is the sum of four consecutive integers.”, where is the number in question.
Example
In this example, 2 = -1 + 0 + 1 + 2, and 82 = 19 + 20 + 21 + 22. 5 and 41 are not of the correct form.
Input
5
41
82
0
Output
2 is the sum of four consecutive integers.
5 is not the sum of four consecutive integers.
41 is not the sum of four consecutive integers.
82 is the sum of four consecutive integers.

搜索更多相关的解决方案: 结果  int  main  include  

----------------解决方案--------------------------------------------------------
1、A zero (0) denotes the end of input.你忘记看这句了

2、2的31次方超过int的范围了,用long类型(long的范围多少我也不记得了,或者应该用无符号的long)

3、何必从数组a复制到b呢?

4、判断的话用a[i]%4==2判断就好了
----------------解决方案--------------------------------------------------------

程序代码:

#include <stdio.h>
char* str[]={\" is not the sum of four consecutive integers.\",
\" is the sum of four consecutive integers.\"};
int main()
{
int n;
while(scanf(\"%d\",&n),n){
printf(\"%d%s\n\",n,str[n%4==2]);
}
}


----------------解决方案--------------------------------------------------------
  相关解决方案