//编写一个程序,显示用户输入的一个日期是该年度的第几天。
2016-03-23 13:26
543 查看
//编写一个程序,显示用户输入的一个日期是该年度的第几天。
#include<iostream>
using namespace std;
int main()
{
int year=1,month=1,day=1;
int mo=0,i;
int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"请输入所在年份;";
cin>>year;
cout<<endl;
if(year%400==0||(year%4==0&&year%100!=0))
{
mon[1]=29;
}
cout<<"请输入所在月份;";
cin>>month;
while(month<1||month>12)
{ cout<<"输入月份非法!!!"<<endl;
cout<<"请重新输入所在月份;";
cin>>month;
}
cout<<endl;
cout<<"请输入所在本月日期;";
cin>>day;
while(day<1||day>mon[month-1])
{ cout<<"输入日期非法!!!"<<endl;
cout<<"请重新输入所在当月日期;";
cin>>day;
}
cout<<endl;
for(i=0;i<month-1;i++)
{
mo+=mon[i];
}
cout<<"今天是今年的第"<<mo+day<<"天"<<endl;
cout<<"珍爱当下,认真细致的生活"<<'\n';
}
#include<iostream>
using namespace std;
int main()
{
int year=1,month=1,day=1;
int mo=0,i;
int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"请输入所在年份;";
cin>>year;
cout<<endl;
if(year%400==0||(year%4==0&&year%100!=0))
{
mon[1]=29;
}
cout<<"请输入所在月份;";
cin>>month;
while(month<1||month>12)
{ cout<<"输入月份非法!!!"<<endl;
cout<<"请重新输入所在月份;";
cin>>month;
}
cout<<endl;
cout<<"请输入所在本月日期;";
cin>>day;
while(day<1||day>mon[month-1])
{ cout<<"输入日期非法!!!"<<endl;
cout<<"请重新输入所在当月日期;";
cin>>day;
}
cout<<endl;
for(i=0;i<month-1;i++)
{
mo+=mon[i];
}
cout<<"今天是今年的第"<<mo+day<<"天"<<endl;
cout<<"珍爱当下,认真细致的生活"<<'\n';
}
相关文章推荐
- 局
- 选择排序
- 有A,B,C三个学生,一个出生在北京,一个出生在上海,一个出生在广州。他们中一个学物理专业,一个学数学专业,一个学计算机。其中(1)A不是学物理的,B不是学计算机的;(2)学物理的不出生在上海;(3)
- 编写函数将字符串按逆序存放
- 递归和非递归实现斐波那契数列
- //7.4 对例 7.5 进行修改,将其中的友元函数 total 改为 max,即显示三个银行中存款最 //多的银行及其存款数
- //6.5 定义一个日期类 Date,该类对象存放一个日期,可以提供的操作有: //void GetDate(); //取日期值,格式如“2001 年 2 月 5 日” //void GetYear(
- //设计算法,将某个大于1的自然数n分解为其素因子的乘积,如6=2*3,7=7,8=2*2*2。
- /编写一个程序, 对于二维数组 b[2][3]={{1,2,3},{4,5,6}}, 验证*(*(b+i)+j)、 *(b[i]+j)、 //(*(b+i))[j]与 b[i][j]是相同的。
- //5.4 编写一个程序,求以下矩形两条对角线上的元素之和: //1 3 6 //7 9 11 //14 15 17
- 最大似然估计与最小二乘的解释
- VC(VS)的64位编程小结
- Java使用占位符拼接字符串
- poj 1018 Communication System(DP)
- html5文件上传
- android WebView加载html5介绍
- centos配置mutt跟msmtp发送邮件
- spring学习笔记(13)基于Schema配置AOP详解
- CSS边框盒子模型
- ListView常用小技巧