dongtian @ 2022-12-09 17:29:43
#include<stdio.h>
int main()
{
int a,b,i,j=0,m=0;
int c[10000];
scanf("%d%d",&a,&b);
for(i=a;i<=b;i++)
{
if(i%4==0)
{
m++;
c[j]=i;
j+=1;
}
}
printf("%d\n",m);
for(j=0;j<m;j++)
{
printf("%d ",c[j]);
}
return 0;
}
by ChrisWangZi @ 2022-12-09 17:31:56
@dongtian
不能只判断i%4==0
by alexander35 @ 2022-12-09 17:33:06
忘算100和400年特判
by ChrisWangZi @ 2022-12-09 17:36:15
可以这么写:
if((i%400==0)||(i%4==0&&i%100!=0))
{
m++;
c[j]=i;
j+=1;
}
by dongtian @ 2022-12-09 17:40:41
@ChrisWangZi 谢了!!
by dongtian @ 2022-12-09 17:41:07
@alexander35 谢了!!!