输出1900—2020年中所有的闰年。每输出3个年号换一行
#include
main()
{
int y;
for(y=1900;y<=2000;y++)
{
if((y%4==0&&y%100!=0)||(y%400==0))
{
printf("%d ",y);
}
}
return 0;
}
写个变量计数,当count%3 == 0时,输出一个换行。代码和运行图如下,有帮助的话采纳一下哦!
#include<stdio.h>
main()
{
int y,count=0;
for(y=1900;y<=2000;y++)
{
if((y%4==0&&y%100!=0)||(y%400==0))
{
printf("%d ",y);
count++;
if(count%3==0){
printf("\n");
}
}
}
return 0;
}
写个变量计数不就行了