Implement a function that prints the calendar for a given month and year. First, prompt the user:
Enter the month and year:
Once the user enters a valid input (two integers separated by a space), print out the calendar in a format be similar to the output of the UNIX cal command. For example, if the user enters 03 2014, the output should be:
http://imgur.com/3LXleAr
An updated version of my code, sorry about indentation im new to stackflow, it wont let me simply just copy and paste my code says i have indentation problems:
#include<stdio.h>
int main(){
int year;
int month, day;
int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char *months[]=
{
" ",
" January",
" February",
" March",
" April",
" May",
" June",
" July",
" August",
" September",
" October",
" November",
" December"
};
printf("Please enter a month and year: ");
scanf("%d %d", &month, &year);
if(((year%4==0) && (year%100!=0)) || (year%400==0))
{
days_in_month[2] = 29;
}
else
{
days_in_month[2] = 28;
}
printf("%s", months[month]);
printf("\nSun Mon Tue Wed Thu Fri Sat\n" );
for ( day = 1; day <= 1; day++ )
{
printf(" ");
}
for ( day = 1; day <= days_in_month[month]; day++ )
{
printf("%2d", day );
if ( ( day ) % 7 > 0 ){
printf(" " );
}
else{
printf("\n " );
}
}
return 0;
}
What i need help with is that, i can print the correct year and month and the amount of days for each month, however im am completely stuck as to what to do to the code so that the progrma itself knows where to start printing the first day of the month i enter. For example if i put in 01 2014 the calendar should print january and put a 1 under wensday, 2 under thursday... and so on. Thanks for the help.