Calculate the day of a certain month in a certain year as the day of the year.

Write a program to calculate that a certain day of a certain year is the day of the year.
(Input format: Enter the date in one line in the format "yyyy/mm/dd" (ie "year/month/day").
Note: The criterion for a leap year is that the year of the year is divisible by 4 but not divisible by 100 , Or can be divisible by 400.

#include<stdio.h>                         
int main()                         
{
    
     
     int y,m,d,days=0;                            
     scanf("%d/%d/%d",&y,&m,&d);                  
     int a[12]={
    
    31,28,31,30,31,30,31,31,30,31,30,31};  
   //定义整形数组并赋值    
     if(y%400==0||(y%4==0&&y%100!=0))            
	 a[1]=29;                                               
     for(int i=0;i<m-1;i++) {
    
                                        
         days+=a[i];                                          
          } 
      days+=d;                                                      
 printf("%d",days);                                          
 return 0;                                                        
 }

Insert picture description here

Pay attention to the input method: year/month/day;
if you have any good suggestions, leave your steps in the comment area.

Guess you like

Origin blog.csdn.net/qq_51932922/article/details/112350432