program that determines the day number in a year for a date that is provided. Ja
ID: 3543817 • Letter: P
Question
program that determines the day number in a year for a date that is provided. Jan 1, 94, is day 1. Dec 31, 96 is day 366, since 96 is a leap year. a leap year is divisible by 4, except that any year divisible by 100 us a leap year only if it is divisible by 400. program should accept month, day, years as integers. Include function leap that returns 1 if called with a leap year, 0 otherwise.
here is the modfitd part for the porgram :
b. Write this program using input-output files. Name the input file lab5p3.in and the output file lab5p3.out.
c. As part of your solution, write and call the function leap() as described in the text. The year 1900 is not a leap year, whereas year 2000 is a leap year. Why?
e. Suppose the input file, lab5p3.in, contains three integers: 6 26 2000
f. For the input file above, the output file, lab5p3.out, should contain: 178
g. Do another example by hand for todays date.
Month = _______________ Day = ___________________
Year = _______________ Day Number = ______________ h. Check your program with the other examples in the book (1 1 1994, 12 31 1993, and 12 31 1994).
Explanation / Answer
// START OF PROGRAM.
#include<stdio.h>
int leap(int year)
{
if(year%400 ==0 || (year%100 != 0 && year%4 == 0))
return 1;
return 0;
}
int main()
{
int day,month,year;
int no_of_days = 0;
int count=0;
int days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
FILE* input = fopen("lab5p3.in","r");
FILE* output = fopen("lab5p3.out","w");
while (fscanf(input, "%d %d %d", &month,&day, &year) != EOF)
{
no_of_days = 0;
count=0;
while(count<month-1)
no_of_days = no_of_days + days_in_month[count++];
no_of_days = no_of_days + day;
if(leap(year))
no_of_days = no_of_days + 1;
// printf("no of days is %d ",no_of_days);
fprintf(output, "%d ",no_of_days);
}
fclose(input);
fclose(output);
return 0;
}
// END OF PROGRAM.
g. Do another example by hand for today
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.