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)

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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