25.3k views
0 votes
Write a function that determines if a given year is a leap year. You can either pass a singleinteger year or your date structure to this function. Hint: Review Lab 2. 3. Write a function that returns the number of days in a month. Pass your date structure to this function and account for leap years using the function in #2.

1 Answer

5 votes

A function that determines if a given year is a leap year:

#include<stdio.h>

int main()

{

//fill the code

int year, month;

scanf(“%d %d”,&month,&year);

if(!Leapyear(month, year))

{

if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)

printf(“Number of days is 31”);

else if(month == 2)

{

printf(“Number of days is 28”);

}

else

printf(“Number of days is 30 “);

return 0;

}

}

int Leapyear(int month, int year)

{

if((month == 2) && (year%4 == 0) || ((year%100 == 0) &&(year%400 == 0)))

{

printf(“Number of days is 29”);

return 1;

}

else

return 0;

}

User Luca Masera
by
6.2k points