C Language Experiment--the number of days in a certain year

Source: Internet
Author: User
Problem DescriptionEnter the year and month to determine how many days the month is. InputEnter the year and month, in the form of year \ Month. OutputThe number of days that the month is exported. Example Input
2009\1
Example Output

31



#include <stdio.h>
int main ()
{
int y,m,d;
scanf ("%d\\%d", &y,&m);
Switch (m)
{Case 1:
Case 3:
Case 5:
Case 7:
Case 8:
Case 10:
Case 12:d=31;break;
Case 4:
Case 6:
Case 9:
Case 11:d=30;break;
Case 2:
if ((y%4==0&&y%100!=0) | | y%400==0)
d=29;
Else
d=28;
}
printf ("%d\n", D);
return 0;
}
Or

#include <stdio.h>
int main ()
{
int y,m,d;
scanf ("%d\\%d", &y,&m);
Switch (m)
{
Case 1:printf ('%d\n '); break;
Case 3:printf ("%d\n");
Case 5:printf ("%d\n";);
Case 7:printf ("%d\n";);
Case 8:printf ("%d\n";);
Case 10:printf ("%d\n";);
Case 12:printf ("%d\n";);
Case 4:printf ("%d\n");
Case 6:printf ("%d\n");
Case 9:printf ("%d\n");
Case 11:printf ("%d\n");
Case 2:
if ((y%4==0&&y%100!=0) | | (y%400==0)) printf ("%d\n", 29);
Else printf ("%d\n", 28);
break;
}
return 0;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.