第三周第二篇 本月有几天?
2016-04-07 08:56
274 查看
/*
*Copyrigth(c)2015,烟台大学计算机学院
*All rights reserved.
*文件名称:main.cpp
*作者:汤善晔
*完成日期:2016年4月1日
*版本号:CodeBlocks12.11
*
*问题描述:编程序,输入年份和月份,输出本月有多少天。
*输入描述:输入两个数,年和月。
*程序输出:输出一个数,本月天数。
*/
#include<iostream>
using namespace std;
int main()
{
int year,month;
cin>>year;
cin>>month;
if(year%4==0&&year%100!=0||year%400==0)
{
if(month==2)
cout<<"29\n";
else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
cout<<"31\n";
else
cout<<"30\n";
}
else
{
if(month==2)
cout<<"28\n";
else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
cout<<"31\n";
else
cout<<"30\n";
}
return 0;
}
*Copyrigth(c)2015,烟台大学计算机学院
*All rights reserved.
*文件名称:main.cpp
*作者:汤善晔
*完成日期:2016年4月1日
*版本号:CodeBlocks12.11
*
*问题描述:编程序,输入年份和月份,输出本月有多少天。
*输入描述:输入两个数,年和月。
*程序输出:输出一个数,本月天数。
*/
#include<iostream>
using namespace std;
int main()
{
int year,month;
cin>>year;
cin>>month;
if(year%4==0&&year%100!=0||year%400==0)
{
if(month==2)
cout<<"29\n";
else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
cout<<"31\n";
else
cout<<"30\n";
}
else
{
if(month==2)
cout<<"28\n";
else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
cout<<"31\n";
else
cout<<"30\n";
}
return 0;
}
相关文章推荐
- 如何组织构建多文件 C 语言程序(二)
- 如何写好 C main 函数
- Lua和C语言的交互详解
- 关于C语言中参数的传值问题
- 简要对比C语言中三个用于退出进程的函数
- 深入C++中API的问题详解
- 基于C语言string函数的详解
- C语言中fchdir()函数和rewinddir()函数的使用详解
- C语言内存对齐实例详解
- C语言编程中统计输入的行数以及单词个数的方法
- C语言自动生成enum值和名字映射代码
- 使用C语言判断英文字符大小写的方法
- c语言实现的带通配符匹配算法
- C语言实现顺序表基本操作汇总
- C语言中计算正弦的相关函数总结
- 使用C语言详解霍夫曼树数据结构
- 探讨C语言的那些小秘密之断言
- C语言实现BMP转换JPG的方法
- 深入探讨C语言中局部变量与全局变量在内存中的存放位置
- C语言查找数组里数字重复次数的方法