本月有多少天

编程入门 行业动态 更新时间:2024-10-25 16:29:30

本月<a href=https://www.elefans.com/category/jswz/34/1769442.html style=有多少天"/>

本月有多少天

上机内容:编写程序计算某年某月多少天

上机目的:练习使用switch
 * Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* 作    者:  徐本锡
* 完成日期:2012 年 10 月27  日
* 版 本 号:v1.0
*
* 输入描述:输入  年  月

 
* 问题描述:无

* 程序输出:年  月   多少天

 

* 算法设计:无

 

程序代码: 

#include <iostream>
using namespace std;
int main()
{int year,month,days;cout<<"请输入  年  月"<<endl;cin>>year>>month;if(month==2){if(year%4==0&&year%100!=0 ||year%400==0)days=29;elsedays=28;}else{switch (month){case 1:case 3:case 5:case 7:case 8:case 10:case 12:days=31;break;case 4:case 6:case 9:case 11:days=30;break;}}cout<<year<<"年  "<<month<<"月  "<<"有  "<<days<<"天"<<endl;return 0;
}


结果(截屏):

我的总结:

ok!!!


更多推荐

本月有多少天

本文发布于:2023-06-27 19:09:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/915718.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有多少

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!