C-列印(1000-2000的閏年)
阿新 • • 發佈:2022-03-24
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> int main() { //列印1000-2000的閏年 //1.能被4整除並且不能被100整除是閏年 //2.能被400整除是閏年 int year = 0; int count = 0; for (year = 1000; year <= 2000; year++) { if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { printf("%d ", year); count++; } } printf("\ncount=%d", count); return 0; }
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> int main() { //列印1000-2000的閏年 //1.能被4整除並且不能被100整除是閏年 //2.能被400整除是閏年 int year = 0; int count = 0; for (year = 1000; year <= 2000; year++) { if (year % 4 == 0 && year % 100 != 0) { printf("%d是閏年\n", year); count++; } else if (year % 400 == 0) { printf("%d ", year); count++; } } printf("\ncount=%d", count); return0; }