Write a program that prints the day of the year,given the date in the format mon
ID: 3622277 • Letter: W
Question
Write a program that prints the day of the year,given the date in the format month-day-year.?For example,if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359.the program should check for leap year. a year is a leap if it is divisible by 4 but not divisible by 100.for example, 1992 and 2008 are divisible by 4 ,but not divisible by 100. a year that is divisible by 100 is a leap if it is also divisible by 400. for example, 1600 and 2000 are divisible by 400.however,1800 is not a leap year because 1800 is not divisible by 400.
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,n1;
struct date
{
int month;
int day;
int year;
};
struct date event = {12,25,2006};
n = 1461*(event.month<=2 ? event.year-1 : event.year)/4
+ 153*(event.month<=2 ? event.month+13 : event.month+1)/5
+ event.day;
printf("n = %i ",n);
n1= 1461*(event.year-1)/4
+ 153*(1+13)/5
+ 1;
printf("n1 = %i ",n1);
printf("%i/%i/%i is %i th day of year ",event.year, event.month,event.day,n-n1+1);
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.