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

Sub-Task : Write a function: This function is given the day, month and year and

ID: 3592407 • Letter: S

Question

Sub-Task: Write a function:

This function is given the day, month and year and returns the Julian date. The Julian date is the ordinal day number for that day. For example, 1 Jan is day 1 of any year, 31 Dec is day 365 for any non-leap year and 1 Feb is day 32 for any year. Use your days_in_month() function from the previous problem to calculate the Julian date. Put the code for the function julian_date() in the file julian.c, and the prototype in the file julian.h

Write a driver, main(), which asks the user to enter a month, day, year and prints the Julian date. Terminate with EOF. Put the driver in the file driver3.c. You will compile this program with the command:

which will create an executable called driver3.

This first code tells whether the year is a leap year or not

*/

/* this is function taking the year given and returning ir its the leap year
* or not */
#include <stdio.h>
#include "leap.h"

int is_leap(int year)
{
int leap;

leap = year % 400;

#ifdef debug
printf("debug: leap /400 = %d", leap);
#endif

if (leap == 0)
{
printf("True ");
}
else
{
leap = year % 4;
#ifdef debug
printf("debug: leap /4 = %d ", leap);
#endif

if (leap == 0)
{
leap = year % 100;
#ifdef debug
printf("debug: leap /100 = %d ", leap);
#endif

if (leap == 0)
{
printf("False ");
}
printf("True ");
}
else
{
printf("False ");
}

}

}

The second code tells how many ordinal days there are when inputted the month and day of that month

/* A program to find number of days given a month and year */

#include <stdio.h>

int main()

{

int days_in_month(int month, int year);

        int month;      /* month */

        int year;       /* year */

        int flag;       /* result of scanf flag */

/* Enter month and year */

printf("Enter a month and year(EOF to quit): ");

flag = scanf("%d%d", &month, &year);

/* While there are more months and years to check */

while (flag !=EOF)

{

/* when month is january, march, may, july, august, october, december */

if (month == 1)

{

       printf("31 days ", month);

}

else if(month == 3)

{

        printf("31 days ", month);

}

else if(month == 5)

{

        printf("31 days ", month);

}

else if(month == 7)

{

        printf("31 days ", month);

}

else if(month == 8)

{

        printf("31 days ", month);

}

else if(month == 10)

{

        printf("31 days ", month);

}

else if(month == 12)

{

        printf("31 days ", month);

}

/* when month is april, june, september, or november */

else if(month == 4)

{

        printf("30 days ", month);

}

else if(month == 6)

{

        printf("30 days ", month);

}

else if(month == 9)

{

        printf("30 days ", month);

}

else if(month == 11)

{

        printf("30 days ", month);

}

/* if month is february */

if (month == 2)

{

if

        (year%4 ==0)

{

if

        (year%100 ==0)

{

/* if leap year */

if

        (year%400 ==0)

        printf("29 days ", month, year);

/* if not leap year */

else

        printf("28 days ", month, year);

}

else

        printf("29 days ", month, year);

}

else

        printf("28 days ", month, year);}

/* Enter month and year */

printf("Enter a month and year(EOF to quit): ");

flag = scanf("%d%d", &month, &year);

}

}

Explanation / Answer

This first code tells whether the year is a leap year or not

*/

/* this is function taking the year given and returning ir its the leap year
* or not */
#include <stdio.h>
#include "leap.h"

int is_leap(int year)
{
int leap;

leap = year % 400;

#ifdef debug
printf("debug: leap /400 = %d", leap);
#endif

if (leap == 0)
{
printf("True ");
}
else
{
leap = year % 4;
#ifdef debug
printf("debug: leap /4 = %d ", leap);
#endif

if (leap == 0)
{
leap = year % 100;
#ifdef debug
printf("debug: leap /100 = %d ", leap);
#endif

if (leap == 0)
{
printf("False ");
}
printf("True ");
}
else
{
printf("False ");
}

}

}

The second code tells how many ordinal days there are when inputted the month and day of that month

/* A program to find number of days given a month and year */

#include <stdio.h>

int main()

{

int days_in_month(int month, int year);

        int month;      /* month */

        int year;       /* year */

        int flag;       /* result of scanf flag */

/* Enter month and year */

printf("Enter a month and year(EOF to quit): ");

flag = scanf("%d%d", &month, &year);

/* While there are more months and years to check */

while (flag !=EOF)

{

/* when month is january, march, may, july, august, october, december */

if (month == 1)

{

       printf("31 days ", month);

}

else if(month == 3)

{

        printf("31 days ", month);

}

else if(month == 5)

{

        printf("31 days ", month);

}

else if(month == 7)

{

        printf("31 days ", month);

}

else if(month == 8)

{

        printf("31 days ", month);

}

else if(month == 10)

{

        printf("31 days ", month);

}

else if(month == 12)

{

        printf("31 days ", month);

}

/* when month is april, june, september, or november */

else if(month == 4)

{

        printf("30 days ", month);

}

else if(month == 6)

{

        printf("30 days ", month);

}

else if(month == 9)

{

        printf("30 days ", month);

}

else if(month == 11)

{

        printf("30 days ", month);

}

/* if month is february */

if (month == 2)

{

if

        (year%4 ==0)

{

if

        (year%100 ==0)

{

/* if leap year */

if

        (year%400 ==0)

        printf("29 days ", month, year);

/* if not leap year */

else

        printf("28 days ", month, year);

}

else

        printf("29 days ", month, year);

}

else

        printf("28 days ", month, year);}

/* Enter month and year */

printf("Enter a month and year(EOF to quit): ");

flag = scanf("%d%d", &month, &year);

}

}