第26讲 项目4:本月有几天?
2015-11-13 00:10
274 查看
任务和代码:
/*
*Copyright (c)2015 CSDN学院
*All rights reserved
*文件名字:main.c
*作者:修红国
*完成日期:2015年11月12日
*版本号:V1.0
*
*问题描述:编程序,输入年份和月份,输出本月有多少天。合理选择分支语句完成设计任务。
样例输入1:2004 2
输出结果1:本月29天
样例输入2:2010 4
输出结果2:本月30天
*/
#include <stdio.h>
#include <stdlib.h>
int main ( )
{
int years,months,day;
printf("输入年份和月份:");
scanf("%d %d",&years,&months);
months=months/1;
switch(months)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day=31;break;
case 4:
case 6:
case 9:
case 11:
day=30;break;
case 2:
if(((years%4==0)&&(years%100!=0))||(years%400==0))
{
day=29;;
}
else
{
day=28;
}
}
printf("%d 年 %d 月共有 %d 天。\n", years, months, day);
return 0;
}
运行结果:
/*
*Copyright (c)2015 CSDN学院
*All rights reserved
*文件名字:main.c
*作者:修红国
*完成日期:2015年11月12日
*版本号:V1.0
*
*问题描述:编程序,输入年份和月份,输出本月有多少天。合理选择分支语句完成设计任务。
样例输入1:2004 2
输出结果1:本月29天
样例输入2:2010 4
输出结果2:本月30天
*/
#include <stdio.h>
#include <stdlib.h>
int main ( )
{
int years,months,day;
printf("输入年份和月份:");
scanf("%d %d",&years,&months);
months=months/1;
switch(months)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day=31;break;
case 4:
case 6:
case 9:
case 11:
day=30;break;
case 2:
if(((years%4==0)&&(years%100!=0))||(years%400==0))
{
day=29;;
}
else
{
day=28;
}
}
printf("%d 年 %d 月共有 %d 天。\n", years, months, day);
return 0;
}
运行结果:
相关文章推荐
- Python学习笔记(3)
- 双十一,一场空虚的高潮
- BlockingQueue队列详解
- python搜索引擎之搜索系统的建立——根据关键字命中次数排分给出前若干个答案
- 构件工具Maven----坐标、依赖、仓库、生命周期的简单学习
- vim 跨文件复制
- 数据库
- 事件过滤器 不是很明白
- UVA 10033 Interpreter (模拟)
- JQuery插件Mmenu使用入门
- 《二分》hdoj acm 4.1.2
- (加入显示电量功能)模仿魅族、华为、小米电池续航管理软件, 动态水波纹滚动的圆形小球View
- 龙贝格算法
- Objective-c:封装、继承与多态
- Windows Azure下Exchange Server2016高可用性配置介绍
- 《动态规划》hdoj acm 3.3.7 二维费用背包
- 个人博客作业_week7
- Cardboard对像的公共方法与属性
- 常用控件的事件监听
- 网页视频下载方法二:手机浏览器下载