判断某年是否为闰年
2012-12-04 20:53
344 查看
/*
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* 作 者:赵兰
* 完成日期:2012 年 12月 4日
* 版 本 号:v1.0
* 输入描述: 无
* 问题描述:设计一个程序进行判断是不是闰年
* 程序输出: 闰年
* 问题分析:略
* 算法设计:略
* 我的程序:
输出结果:
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* 作 者:赵兰
* 完成日期:2012 年 12月 4日
* 版 本 号:v1.0
* 输入描述: 无
* 问题描述:设计一个程序进行判断是不是闰年
* 程序输出: 闰年
* 问题分析:略
* 算法设计:略
* 我的程序:
*/ #include <iostream> using namespace std; int main() { int year; bool leap; cout<<"请输入年份:"; //输出提示 cin>>year; //输入年份 if(year%4==0) //年份能被4整除 {if(year%100==0) // 年份能被4整除又能被100整除 {if(year%400==0) // 年份能被4整除又能被400整除 leap=true; //闰年,令leap=true(真) else leap=false; //非闰年,令leap=false(假) } else //年份能被4整除但不能被100整除肯定是闰年 leap=true; //是闰年令leap=true } else leap=false; //若为非闰年,令leap=false if(leap) cout<<year<<"is"; //若leap为真,就输出年份和"是" else cout<<year<<"is not"; //若leap 为真,就输出年份和"不是" cout<<"a leap year."<<endl; //输出"闰年" return 0; }
输出结果: