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

Created this C language program for the following assignment: Write a program th

ID: 3585559 • Letter: C

Question

Created this C language program for the following assignment: 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 1st, 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, day, and year as integers. Include a function leap that returns 1 if called with a leap year, 0 otherwise. I cannot get it to run and execute. Help.

#include <stdio.h>

int GetDayNumber(char month[10], int day, int year);

int Leap(int Year);

int main()

{

char month[10];

int day, year, dayNumber;

printf("Enter a date (Ex. January 1, 2001):");

scanf("%s%d%d", &month, &day, &year);

dayNumber = GetDayNumber(month, day, year);

printf("Day number for this date: %d ", dayNumber);

getchar();

return 0;

}

int GetDayNumber(char month[10], int day, int year)

{

int days = 0;

if (month, "January" == 0)

days = day;

else

if (month, "February" == 0)

days = 31 + day;

else

if (month, "March" == 0)

days = 31 + 28 + day;

else

if (month, "April" == 0)

days = 31 + 28 + 31 + day;

else

if (month, "May" == 0)

days = 31 + 28 + 31 + 30 + day;

else

if (month, "June" == 0)

days = 31 + 28 + 31 + 30 + 31 + day;

else

if (month, "July" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + day;

else

if (month, "August" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + day;

else

if (month, "September" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day;

else

if (month, "October" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;

else

if (month, "November" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;

else

if (month, "December" == 0)

days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;

else

{

printf("Invalid Month Name.");

return 0;

}

if (month, "January") != 0 && (month, "February") != 0 && Leap(year))

days++;

return days;

}

int Leap(int year)

{

if ((year % 400 == 0)

|| (year % 4 == 0 && year % 100 != 0))

return 1;

else

return 0;

}

Explanation / Answer

#include <stdio.h>
int GetDayNumber(char month[10], int day, int year);
int Leap(int Year);
int main()
{
char month[10];
int day, year, dayNumber;
printf("Enter a date (Ex. January 1, 2001):");
scanf("%s%d%d", &month, &day, &year);
dayNumber = GetDayNumber(month, day, year);
printf("Day number for this date: %d ", dayNumber);
getchar();
return 0;
}
int GetDayNumber(char month[10], int day, int year)
{
int days = 0;
if (strcmp(month,"January")==0)
days = day;
else
if (strcmp(month,"February") == 0)
days = 31 + day;
else
if (strcmp(month,"March")==0)
days = 31 + 28 + day;
else
if (strcmp(month,"April") == 0)
days = 31 + 28 + 31 + day;
else
if (strcmp(month, "May") == 0)
days = 31 + 28 + 31 + 30 + day;
else
if (strcmp(month, "June") == 0)
days = 31 + 28 + 31 + 30 + 31 + day;
else
if (strcmp(month, "July") == 0)
days = 31 + 28 + 31 + 30 + 31 + 30 + day;
else
if (strcmp(month, "August") == 0)
days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + day;
else
if (strcmp(month, "September") == 0)
days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day;
else
if (strcmp(month, "October") == 0)
days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;
else
if (strcmp(month, "November")== 0)
days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;
else
if (strcmp(month, "December") == 0)
days = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;
else
{
printf("Invalid Month Name.");
return 0;
}
if (strcmp((month, "January") != 0) && strcmp(month, "February") != 0 && Leap(year))
days++;
return days;
}
int Leap(int year)
{
if ((year % 400 == 0)
|| (year % 4 == 0 && year % 100 != 0))
return 1;
else
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