这是我的代码
#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 “
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.
----------------解决方案--------------------------------------------------------
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]);
}
}
----------------解决方案--------------------------------------------------------