第一周项目三某天是该年的第几天

来源:互联网 发布:澳洲工资算法 编辑:程序博客网 时间:2024/05/16 09:48
/**Copyright (c)2013,烟台大学计算机学院*All rights reserved.*文件名称:test.cpp*作者:孙玲倩*完成日期:2014年3月6日*版本号:v1.0*问题描述:计算某天是该年的第几天问题分析:输入年月日,计算某天是该年的第几天。*/#include <iostream>#include <cmath>using namespace std;struct Date{    int year ;    int month;    int day;};int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int main(){    Date date;    cout <<"请输入年月日:"<<endl;    cin>>date.year>>date.month>>date.day;    int days=0,a;    for (a=1;a<date.month;a++)    days=d[a];    if ((date.year%4==0&&date.year%100!=0||date.year%400==0)&&date.month>=3)    days+=1;    cout<<date.month<<"月"<<date.day<<"日"<<"是"<<date.year<<"的第"<<days<<"天"<<endl;    return 0;}


心得体会:计算某天是该年的第几天这种程序曾经写过,现在用学习的新知识再写一遍,又有不同的收获。任何事物都有多种答案。应该有创新思维

 

0 0
原创粉丝点击