Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote