for(year=1000;year<=2000;year++) { if((year%4==0&&year%100!=0)||(year%400==0)) { printf("%d ",year); num++; } } printf("num=%d\n",num); return 0; } ()
void main(){ int yr,i=0;for(yr=1000,yr<=2000;yr++){ if(yr%4==o&&yr%100!=o||yr%400==0){ i++;if(i%5==0)printf("\n");printf("%-6d",yr);} } }
include <stdio.h> define IS_WANTED_YEAR(y) (((y)%400==0)||(((y)%4==0)&&((y)%100!=0)))?1:0)int main(void) { int year, n = 0;for (year = 1000; year <= 2000; year+=4) { if(IS_WANTED_YEAR(year)) { printf("%d\t", year);n++;if(n%5==0)putcha...
若为闰年,则leap=true;若为平年,则leap=false。最后判断leap是否为真,若为真,输出闰年。#include<iostream>usingnamespacestd;intmain(){intyear;boolleap;for(year=1000;year<=2000;year++){if(((year%4==0)&&(year%100!=0))||(year%400==0))leap=true;elseleap=false;}if(leap)cout<<year<<" ...