在判断某一年是否为闰年时,可引入bool变量。若为闰年,则leap=true;若为平年,则leap=false。后判断leap是否为真,若为真,输出闰年。 #include<iostream> using namespace std; int main() { int year; bool leap; for(year=1000;year<=2000;year++) {if (((year%4==0)&&(year%100!=0))||(year%400==0)) leap=true; else leap=false;} if(leap) cout<<year<<" "<<endl; } return 0;}