Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Answer correctly

0 votes
asked Oct 8, 2018 by Christina1 (310 points)

Write a program that asks the user to enter the month (letting the user enter an integer in the range of 1 through 12) and the four-digit year. The program should then display the number of days in that month. Use the following criteria to identify leap years:

  1. Determine whether the year is divisible by 100. If it is, then it is a leap year if and only if it is divisible by 400. For example, 2000 is a leap year but 2100 is not.
  2. If the year is not divisible by 100, then it is a leap year if and only if the year is divisible by 4. For example, 2008 is a leap year but 2009 is not.

More examples:
The following years are not leap years: 1700, 1800, 1900, 2100, 2200, 2300, 2500, 2600
The following years are leap years: 1600, 2000, 2400

The output should look something like this:
Enter a month (1-12): 2
Enter a year: 2016
29 days

1 Answer

0 votes
answered Oct 11, 2018 by Lukas (540 points)
its in german but you can translate it at your own

int main()

{

int jahr,monat,tage;

printf("\nBitte Jahr eingeben: ");
    scanf("%i",&jahr);
    printf("\nBitte Monat eingeben: ");
    scanf("%i",&monat);
    printf("\nBitte Tag eingeben: ");
    scanf("%i",&tage);
    if (monat>=1 && monat <=12 && jahr > 1582) {
        switch (monat) {
            case 2:
            if (!((jahr%100)%4) && (jahr%100)
            || !(jahr%400))
            tage = 29;
            else
            tage = 28;
            break;
            case 2*2:
            case 6:
            case 9: case 11:
            tage = 30;
            break;
            default:
            tage = 31;
        }
        printf("\n%i hat der Monat %i %i Tage", jahr, monat, tage);
    }
    
    else
    printf("\nFalsche Datumsangaben!");

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...