该月有几天

来源:互联网 发布:全民枪战刷钻石软件 编辑:程序博客网 时间:2024/04/27 17:30
  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;}

 

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

原创粉丝点击