int year=0;
int count=0;
printf("闰年:\n");
for(year=1000;year<=2000;year++)
{
//判断是否为闰年:
//1.能被4整除并且不能被100整除是闰年
//2.能被400整除是闰年
if(year%4==0 && year%100!=0||year%400==0)
{
printf("%d ",year);
count++;
}//else if(year%400==0){
// printf("%d ",year);
// count++;
// }
}printf("count=%d\n",count);
结果:
闰年:
1004 1008 1012 1016 1020 1024 1028 1032 1036 1040 1044 1048 1052 1056 1060 1064 1068 1072 1076 1080 1084 1088 1092 1096 1104 1108 1112 1116 1120 1 1764 1768 1772 1776 1780 1784 1788 1792 1796 1804 1808 1812 1816 1820 1824 1828 1832 1836 1840 1844 1848 1852 1856 1860 1864 1868 1872 1876 1880 1884 1888 1892 1896 1904 1908 1912 1916 1920 1924 1928 1932 1936 1940 1944 1948 1952 1956 1960 1964 1968 1972 1976 1980 1984 1988 1992 1996 2000 count=243