how can I make a program that inputs the month and year. and then should output the days of the month.
-january, march, may, july, august, october, and dicember have 31 days.
-april, june, september, and november have 30 days.
-february has 28 days in non-leap years and 29 in leap years.

please I need the code...

Take it in small steps. First write a program that just lets you enter the year. Get that working then add more that lets you enter the month and day of month. If you enter the month as a number you can then create a switch statement that calculates the number of days in the month, as you have already posted.

I doubt you'll get any code for free here. So here's an outline of how you might go about it.
Grab the input from the user and compare strcmp() it against references, i.e. "January", etc (might want to consider how you'd work with upper and lower case letters).
Then grab the year and see if it's a leap year (only necessary if the month is Feb though.

Have a go at trying this and get back to us with problems.

start the main function

declare two int variables

int year, month;
read the year and month values
just a scanf statement with to arguments .

now starts the procedure:

first check whether given year is a leap year or not
a leap year comes for every four years.(so it is divisible by four)

a century year is a leap year if its divisible by 400.
that means any year divisible only by 100 is not a leap year, if not divisible by 400.

so club all these conditions in if ( year % 4 ==0 || !( year %100==0)&&year %400 ==0)

so the year is a leap year
take a two dimentional array
int years[2][12];

and assign the value starting form january,
years[0][0] =31, years[0][1]=28 (non leap) till years[0][11]=31 december
january , years[1][0] =31, years[1][1]=29 (leap) till years[1][11]=31 december

from the pogram find out what is the month

so chose the appropriate index for the year and month

you should get it with above hint!

ive been learning this on my math lesson, so if you want i can give you the math algorythm for this problem, and then you should be able to code that without any problem

ive been learning this on my math lesson, so if you want i can give you the math algorythm for this problem, and then you should be able to code that without any problem

There is no math involved.

There is no math involved.

you can look at this problem from math side, as we did in my class :)

This article has been dead for over six months. Start a new discussion instead.