用C++输出1000-2000之间的闰年

Petunia ·
更新时间:2024-09-21
· 632 次阅读

  在判断某一年是否为闰年时,可引入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;}



闰年 c+ 输出 C++

需要 登录 后方可回复, 如果你还没有账号请 注册新账号