编写一个程序找出1890~2023的所有闰年年份并输出要求每行输出5个统计并输出在此间一共有多少年是闰年。 用C语言写
#include <stdio.h>
int main() { int count = 0; // 计数器 for (int year = 1890; year <= 2023; year++) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { // 判断是否为闰年 printf("%d\t", year); count++; if (count % 5 == 0) { // 每行输出5个 printf("\n"); } } } printf("\n共有%d个闰年", count); // 输出总数 return 0; }
原文地址: https://www.cveoy.top/t/topic/hbWv 著作权归作者所有。请勿转载和采集!