For this question: Write a C 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, day, and year as integers. Include a function leap that returns 1 if called with a leap year, 0 otherwise. Example running the code: Please enter day [1=31], month [1-12], and year [e.g. 2020] as integers: 12 2 2021 Output: Day Number: 43

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

For this question:

Write a C 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, day, and year as integers. Include a function leap that returns 1 if called with a leap year, 0 otherwise.

Example running the code:

Please enter day [1=31], month [1-12], and year [e.g. 2020] as integers:

12 2 2021

Output:

Day Number: 43

I wrote this code but whenever I run it and enter the day, month, and year values, it returns blank.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int leap_year(int year);
int main()
{
int day,month,year;
printf("Enter the date:(DD MM YYYY)\n");
scanf("%d%d%d",&day,&month,&year);
if ((day>31 || day<1) || (month<1 || month>12))
printf("Error! Invalid day or month.\n");

else
{
switch(month)
{
case '1':
printf("Day Number: %d.\n",day);
break;
case '2':
if ((leap_year(day)==1 && day>29)|| (leap_year(day)==0 && day>28))
printf("Error! Invalid day.\n");
else
printf("Day Number: %d.\n",day+31);
break;
case '3':
if (leap_year(year)==1)
printf("Day Number: %d.\n",day+60);
else if (leap_year(year)==0)
printf("Day Number: %d.\n",day+59);
break;
case '4':
if (day>30)
printf("Error! Invalid day.\n");
else if (leap_year(year)==1)
printf("Day Number: %d.\n",day+91);
else if (leap_year(year)==0)
printf("Day Number: %d.\n",day+90);
break;
case '5':
if (leap_year(year)==1)
printf("Day Number: %d.\n",day+121);
else if (leap_year(year)==0)
printf("Day Number: %d.\n",day+120);
break;
case '6':
if (day>30)
printf("Error! Invalid day.\n");
else if (leap_year(year)==1)
printf("Day Number: %d.\n",day+152);
else if (leap_year(year)==0)
printf("Day Number: %d.\n",day+151);
break;
case '7':
if (leap_year(year)==1)
printf("Day Number: %d.\n",day+182);
else if (leap_year(year)==0)
printf("Day Number: %d.\n",day+181);
break;
case '8':
if (leap_year(year)==1)
printf("Day Number: %d.\n",day+213);
else if (leap_year(year)==0)
printf("Day Number: %d.\n",day+212);
case '9':
if (day>30)
printf("Error! Invalid day.\n");
else if (leap_year(year)==1)
printf("Day Number: %d.\n",day+244);
else if (leap_year(year)==0)
printf("Day Number: %d.\n",day+243);
break;
case '10':
if (leap_year(year)==1)
printf("Day Number: %d.\n",day+274);
else if (leap_year(year)==0)
printf("Day Number: %d.\n",day+273);
break;
case '11':
if (day>30)
printf("Error! Invalid day.\n");
else if (leap_year(year)==1)
printf("Day Number: %d.\n",day+305);
else if (leap_year(year)==0)
printf("Day Number: %d.\n",day+304);
break;
case '12':
if (leap_year(year)==1)
printf("Day Number: %d.\n",day+335);
else if (leap_year(year)==0)
printf("Day Number: %d.\n",day+334);
break;
}

}


}

int leap_year(int year)
{
int leap_day;
if
(year%100==0 && year%400==0)
{leap_day=1;
return leap_day;}

else if(year%4==0)
{leap_day=1;
return leap_day;}

else
leap_day=0;
return leap_day;
}

Any idea why? Please use if statements and switch cases and not arrays.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education