源代码:
- [linuxer@mydesktop bmp]$ cat year.c
- #include "stdio.h"
- main()
- {int year;
- printf("\n1900-2100的闰年有:\n\n");
- for(year=1900;year<=2100;year++)
- if((year%4==0&&year%100!=0)||(year%400==0))printf("%d,",year);
- printf("\n\n1900-2100的平年有:\n\n");
- for(year=1900;year<=2100;year++)
- if(!((year%4==0&&year%100!=0)||(year%400==0)))printf("%d,",year);
- }
- [linuxer@mydesktop bmp]$
复制代码
编译与运行:
- [linuxer@mydesktop bmp]$ gcc -o year.o year.c
- [linuxer@mydesktop bmp]$ ./year.o
-
- 1900-2100的闰年有:
-
- 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,2004,
- 2008,2012,2016,2020,2024,2028,2032,2036,2040,2044,2048,2052,2056,
- 2060,2064,2068,2072,2076,2080,2084,2088,2092,2096,
-
- 1900-2100的平年有:
-
- 1900,1901,1902,1903,1905,1906,1907,1909,1910,1911,1913,1914,1915,
- 1917,1918,1919,1921,1922,1923,1925,1926,1927,1929,1930,1931,1933,
- 1934,1935,1937,1938,1939,1941,1942,1943,1945,1946,1947,1949,1950,
- 1951,1953,1954,1955,1957,1958,1959,1961,1962,1963,1965,1966,1967,
- 1969,1970,1971,1973,1974,1975,1977,1978,1979,1981,1982,1983,1985,
- 1986,1987,1989,1990,1991,1993,1994,1995,1997,1998,1999,2001,2002,
- 2003,2005,2006,2007,2009,2010,2011,2013,2014,2015,2017,2018,2019,
- 2021,2022,2023,2025,2026,2027,2029,2030,2031,2033,2034,2035,2037,
- 2038,2039,2041,2042,2043,2045,2046,2047,2049,2050,2051,2053,2054,
- 2055,2057,2058,2059,2061,2062,2063,2065,2066,2067,2069,2070,2071,
- 2073,2074,2075,2077,2078,2079,2081,2082,2083,2085,2086,2087,2089,
- 2090,2091,2093,2094,2095,2097,2098,2099,2100,
- [linuxer@mydesktop bmp]$
复制代码 |