41_判断一年是否是闰年

来源:互联网 发布:防火墙软件测试报告 编辑:程序博客网 时间:2024/04/30 06:55
/*  * Copyright (c) 2011, 烟台大学计算机学院  * All rights reserved.  * 作    者:解晓东   * 完成日期:2012 年 10 月 20 日  * 版 本 号:v1.0  *  * 输入描述:输入年份 * 问题描述:判断一年是否是闰年* 程序输出:输出是或不是  * 问题分析:年份能被4整除又能被100和400整除和年份能被4整除但不能被100整除,肯定是闰年* 算法设计:  */  # include <iostream>using namespace std;int main(){int year;bool leap;cout<<"please enter year:";//输出提示cin>>year;//输入年份if(year % 4 == 0)//年份能被4整除{if(year % 100 == 0)//年份能被4整除又能被100整除{if(year % 400 == 0)//年份能被4整除又能被100和400整除leap = true;//闰年,令leap=trueelseleap = false;//否则,leap=false}else//年份能被4整除但不能被100整除,肯定是闰年leap = true;//是闰年,leap=true}else//年份不能被4整除,肯定不是闰年leap = false;//leap=falseif(leap)cout<<year<<" is";//若leap为真,输出是elsecout<<year<<" is not";//若leap为假,输出不是cout<<" a leap year."<<endl;return 0;}/*在VC++6.0中运行的结果是:-----------------------------please enter year:20002000 is a leap year.Press any key to continue-----------------------------*/

原创粉丝点击