zoukankan      html  css  js  c++  java
  • C++计算出该日是本年中的第几天

    C++计算出该日是本年中的第几天

    任务描述

    定义一个结构体变量(包括年、月、日),编写程序,要求输入年、月、日,程序能计算并输出该日在本年中是第几天。注意闰年问题。

    测试输入:`

    2000 12 20
    

    预期输出:

    12/20 is the 355th day in 2000
    

    测试输入:

    1998 10 1
    

    预期输出:

    10/1 is the 274th day in 1998
    

    源代码:

    #include <iostream>
    using namespace std;
    struct
    { 
    int year;
    int month;
    int day;
    }date;
    
    int main()
    {
    int days;
    cin>>date.year>>date.month>>date.day;
    
    // 请在此添加代码
        /********** Begin *********/
    	days=0;
        int i;
    	int year1[12]={31,28,31,30,31,30,31,31,30,31,30,31};
        int year2[12]={31,29,31,30,31,30,31,31,30,31,30,31};
        if((date.year%4==0&&date.year%100!=0)||(date.year%400==0)){
    		for(i=0;i<date.month-1;i++){
    			days+=year2[i];
    		}
    	}else{
    		for(i=0;i<date.month-1;i++){
    			days+=year1[i];
    		}
    	}
        days+=date.day;
        /********** End **********/
    
    cout<<date.month<<"/"<<date.day<<" is the "<<days<<"th day in "<<date.year<<"."<<endl;
    return 0;
    }
    
  • 相关阅读:
    vuejs组件交互
    markdown table语法
    vue循环中的v-show
    apache跨域
    sublime text执行PHP代码
    PHP语法
    方法(method)和函数(function)有什么区别?
    PHP MVC单入口
    phpstudy部署thinkPHP
    MACD判断定背离,底背离
  • 原文地址:https://www.cnblogs.com/lightice/p/12691787.html
Copyright © 2011-2022 走看看