判断摩天是该年第几天【数组】;

来源:互联网 发布:管家婆数据导入工具 编辑:程序博客网 时间:2024/04/28 02:33


#include <iostream>



using namespace std;




struct ymd
{
    int year;
    int month;
    int day;


};
int days(struct ymd date)
{
    int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    int sum=0;
    int sums;
    int i;
    cin>>date.year>>date.month>>date.day;
    if(date.year%400==0||(date.year%4==0&&date.year%100!=0))
        for (i=1;i<date.month;i++)
            sum = sum +a[i-1];
        else
            for (i=1;i<date.month;i++)
            sum = sum +b[i-1];


        sums=sum+date.day;


        return sums;


}


int main()
{
    ymd date;
    int days(ymd date);
    int sums;
    sums=days(date);
    cout<<sums<<endl;
    return 0;

}


// 注意函数声明中的 struct 关键字;



0 0
原创粉丝点击