#include<stdio.h>intmain(){int year, month, daysInMonth, startingDay, dayOfWeek;// Input year and monthprintf("Enter year: ");scanf("%d",&year);printf("Enter month (1-12): ");scanf("%d",&month);// Calculate the number of days in the monthif(month ==2){// Check for leap yearif((year %4==0&& year %100!=0)||(year %400==0))
daysInMonth =29;else
daysInMonth =28;}elseif(month ==4|| month ==6|| month ==9|| month ==11){
daysInMonth =30;}else{
daysInMonth =31;}// Calculate the starting day of the month
startingDay =(year -1)*365+(year -1)/4-(year -1)/100+(year -1)/400;for(int i =1; i < month;++i){if(i ==2){if((year %4==0&& year %100!=0)||(year %400==0))
startingDay +=29;else
startingDay +=28;}elseif(i ==4|| i ==6|| i ==9|| i ==11){
startingDay +=30;}else{
startingDay +=31;}}
dayOfWeek =(startingDay +1)%7;// Incrementing the starting day by 1// Display the calendarprintf("\n==============================\n");printf(" %d-%02d\n", year, month);printf("==============================\n");printf(" Sun Mon Tue Wed Thu Fri Sat\n");// Print spaces for the days before the starting day of the monthfor(int i =0; i < dayOfWeek;++i){printf(" ");}// Print the days of the monthfor(int day =1; day <= daysInMonth;++day){printf("%4d", day);if((day + dayOfWeek)%7==0){printf("\n");}}printf("\n");return0;}