Code:
/*
The fourth example of C language
Question: Enter a certain year, a certain month and a certain day, and determine what day of the year this day is?
Program analysis: Taking March 5th as an example, you should first add up the previous two months, and then add 5 days, which is the day of the year. In special circumstances, if it is a leap year and the input month is greater than 3, you need to consider adding an extra day. .
*/
#include void main(void) { int year,month,day,sum,temp; printf("Please enter date, month, day: n"); scanf("%d,%d,%d",&year,&month,&day); switch(month) //Assuming it is March, add the number of days in the previous two months and add the number of days in this month. { case 1:sum=0;break; case 2:sum=31;break; case 3:sum=59;break; case 4:sum=90;break; case 5:sum=120;break; case 6:sum=151;break; case 7:sum=181;break; case 8:sum=212;break; case 9:sum=243;break; case 10:sum=273;break; case 11:sum=304;break; case 12:sum=334;break; } sum=sum+day; if(year%400==0||(year%4==0&&year%100!=0)) //Determine whether it is a leap month. For leap months, add one day to this basis. { temp=1; } else { temp=0; } if(temp==1&&month>2) { sum++; } printf("%d, %d, %d, is the %d day n", year, month, day, sum); } operation result:
Previous article:The fifth example of one hundred examples of C language
Next article:The third example of one hundred examples of C language
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Five skills required for RF test engineers
- 【GD32L233C-START Review】Display driver for color OLED screen
- Would you choose the popular outdoor power supply?
- Solution to severe static heating of wireless network card
- China's latest classification catalogue of medical devices (No. 104, 2017)
- What is the function of the cross connection of the five tubes in the middle of this comparator?
- Understanding of TIMERA timing interrupt of MSP430F149
- What is the difference between pyb.delay and time.sleep?
- Stepper motor current test
- [RVB2601 creative application development] + light intensity detection