Question: C program : Write a function daysIntoYear that, given a valid date, determines which numbered days of the year that is. For example, 3/1/2009 is
C program :
Write a function daysIntoYear that, given a valid date, determines which numbered days of the year that is. For example, 3/1/2009 is day #60 of the year 2009, whereas 3/1/2008 is day #61 of the year 2008. Also, add add the following code to main, just before the return statement:
What type does leapyear return
What is the type of leapyears parameter?
if (validDate(month,day,year))
printf("%d/%d/%d is a valid date ", month, day, year);
else
printf("%d/%d/%d is not a valid date ", month, day, year);
********C - CODE************************************************************************************************************************************
#include "pch.h"
#include
/*dates.c This program includes several functions relating to dates.*/
/* leapyear Determine whether year is a leap year: returns 1 for leap years, and 0 otherwise. (Assumes valid year)*/
int leapyear(int year)
{
if (year % 2000 == 0 || (year % 4 == 0 && year % 100 != 0))
return 1;
else return 0;
}
/* howManyDays Determine how many days are in a given month in a given year.Returns that number of days. (Assumes valid dates)*/
int howManyDays(int month, int year)
{
int days;
switch (month)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
days = 31;
break;
case 4: case 6: case 9: case 11:
days = 30;
break;
case 2:
if (leapyear(year))
days = 29;
else
days = 28;
break;
default:
days = 0;
break;
}
return days;
}
/* validDateDetermine whether given month/day/year combo is a valid date:returns 1 for valid date, and 0 otherwise.*/
/* Your function validDate goes here */
/* daysIntoYear Given a valid month/day/year combo, determines how many days into the year that date is: for example, 3/1/2009 is day #60. Returns
that number. (Assumes valid date)*/
/* Your function daysIntoYear goes here */
int main(void)
{
int month, day, year;
printf("Please enter date (mm/dd/yyyy): ");
scanf_s("%d/%d/%d", &month, &day, &year);
printf("The date you entered was: %d/%d/%d ", month, day, year);
if (leapyear(year))
printf("Year %d is a leap year. ", year);
else
printf("Year %d is not a leap year. ", year);
printf("Month #%d in year %d has %d days. ",
month, year, howManyDays(month, year));
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
