0% found this document useful (0 votes)
37 views

Enter A Month. Check How Many Days That Month Has (30 or 31 Days. If That Month Is February, Check If The Year Is Loop or Not For 28 or 29 Days)

The code takes in a month number from the user and checks how many days that month has. It first validates that a valid month number is entered. For months with 30 or 31 days, it prints the number of days. For February, it takes in the year and checks if it is a leap year, printing 29 days if it is a leap year or 28 days if it is not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Enter A Month. Check How Many Days That Month Has (30 or 31 Days. If That Month Is February, Check If The Year Is Loop or Not For 28 or 29 Days)

The code takes in a month number from the user and checks how many days that month has. It first validates that a valid month number is entered. For months with 30 or 31 days, it prints the number of days. For February, it takes in the year and checks if it is a leap year, printing 29 days if it is a leap year or 28 days if it is not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1. Enter a month. Check how many days that month has (30 or 31 days.

If that month is February,


check if the year is loop or not for 28 or 29 days).

#include <stdio.h>

main()

int m,y;

printf("Enter month: ");

scanf("%d", &m);

if (m < 1 || m > 12 )

printf ("No month.\n");

else if (m == 4 || m == 6 || m == 9 || m == 11)

printf ("Month %d has 30 days.\n", m);

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

printf ("Month %d has 31 days.\n", m);

else if (m == 2)

printf("Enter year: ");

scanf("%d", &y);

if (y == 0)

printf ("No year");

else if (y % 4 == 0 )

printf("%d is loop year and month %d has 29 days.\n", y, m);

else printf("%d is not loop year and month %d has 28 days.\n", y, m);

}
2. Example in book:

#include <stdio.h>

int inGlobal;

main()

int inLocal; /* local to main */

int outLocalA;

int outLocalB;

/* initialize */

inLocal = 5;

inGlobal = 3;

/* perform calculations */

outLocalA = inLocal++ & ~inGlobal;

outLocalB = (inLocal + inGlobal) - (inLocal - inGlobal);

/* print results */

printf("The results are: outLocalA = %d, outLocalB = %d\n", outLocalA, outLocalB);

You might also like