码迷,mamicode.com
首页 > 编程语言 > 详细

C++程序题

时间:2014-09-28 17:55:13      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   sp   div   c   

1.判断是否是闰年(多行输入)

分析:是闰年的条件:year%4==0 && year%100 !=0 或者 year%400==0

#include <iostream>
using namespace std;
int main(){
    int year;
    bool isLeapYear;
    cout<<"Enter the year:"<<endl;
    cin>>year;
    while(year!=-1){
        isLeapYear = ((year%400==0)||(year%100!=0 && year%4==0 ));
        if(isLeapYear)
            cout<<year<<" is a leap year"<<endl;
        else
            cout<<year<<" is not a leap year"<<endl;
        cout<<"Enter the year:"<<endl;
        cin>>year;
    
    }
    return 0;
}

 

C++程序题

标签:style   blog   color   io   os   ar   sp   div   c   

原文地址:http://www.cnblogs.com/yanyangbyou/p/3998301.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!