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

please show all of code 7. write a program that determines the day number (1 to

ID: 3793039 • Letter: P

Question


please show all of code

7. write a program that determines the day number (1 to 366) in a year for a date that is provided as input data. As an example, January 1, 1994, is day 1 December 31, 1993, is day 365. December 31, 1996, is day 366, since 1996 is a leap year. A year is a leap year if it is divisible by four, except that any year divisible by 100 is a leap year only if it is divisible by 400. Your program should accept the month, d and year as integers. Include a function leap that retums 1 if called with a leap year, o otherwise

Explanation / Answer

#include <stdio.h>
int leap (int );
int mon_cnt (int );
int day_count (int,int,int);
int res;
int main() {
int day,month,year; /*Display user instructions*/
printf("Enter a year=>");
scanf("%d", &year);
printf("Enter a month=>");
scanf("%d", &month);
printf("Enter a day=>");
scanf("%d", &day);
/*Determine if year is a leap year*/
int num = leap( year);
int month_cnt = mon_cnt(month);
res=day_count(month_cnt,num,day);
printf("The day number is %d", res);
return 0;
}
/* Determines if a year is a leap year and returns a value of 1 if it is a leap year or 0 if otherwise */
int leap (int year) {
int yr=year;
int no;
if((yr % 4) == 0)
no=1;
else {
if((yr % 100 == 0) && ((yr % 400)) == 0)
no = 1;
else no=0;
}
return no;
}
int mon_cnt (int mth) {
int month = mth;
int count;
if (month == 1)
count= 0;
else if (month == 2)
count = 31;
else if (month == 3)
count = 59;
else if (month == 4)
count = 90;
else if (month == 5)
count = 120;
else if (month == 6)
count = 151;
else if (month == 7)
count =181;
else if (month == 8)
count = 212;
else if (month == 9)
count = 243;
else if (month == 10)
count = 273;
else if (month == 11)
count = 304;
else if (month == 12)
count = 334;
return count;
}
/*Determine day count of the year*/
int day_count (int count, int num, int day) {
res = count + num + day;
return res;
}