该月有几天


  
  
  1. /*           
  2. *程序的版权和版本声明部分:           
  3. *Copyright(c)2013,烟台大学计算机学院学生           
  4. *All rights reserved.           
  5. *文件名称:           
  6. *作者:王雅萍           
  7. *完成日期:2013年 10月31日           
  8. *版本号:v1.0           
  9. *对任务及求解方法的描述部分:           
  10. *输入描述:输入年月,显示本月多少天  
  11. *问题描述:输入年月,显示本月多少天 
  12. *程序输出:本月天数   
  13. *问题分析:           
  14. *算法设计: 先判断是否闰年          
  15. */      
#include<iostream>
using namespace std;
int main()
{
    int year,month,day;
    cout<<"请输入年,月:"<<endl;
    cin>>year>>month;
    if(year%4==0&&year%100!=0||year%400==0)                                              //先讨论是不是闰年
    {
        if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
            day=31;
        else if(month==4||month==6||month==9||month==11)
            day=30;
        else
            day=29;                                                             //闰年2月有29天
    }
    else
    {
                  if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
                 day=31;
        else if(month==4||month==6||month==9||month==11)
                 day=30;
        else
                      day=28;
    }
    cout<<"本月有"<<day<<"天"<<endl;
    return 0;
}

 

心得体悟:时间好紧呀。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值