Answer to Question #229354 in C for ABDUL RAZZAQUE

Question #229354
Develop a program that receives the month and year from the keyboard as integers and prints the calendar in the following format.
1
Expert's answer
2021-08-25T05:46:57-0400
#include<stdio.h>
#include<conio.h>


#define LEAP_YEAR (!(yr%4))


int main()
{
	int i, j, x, a, No_of_Days;
	int month, m, mn, curr, next = 0, year, yr;


	year=0;
	while(year<1900)
	{
		printf("\nEnter the Year>= 1900 (YYYY Format) : ");	scanf("%d", &year);
	}
	
	month=0;
	while(month<1 || month>12)
	{
		printf("\nEnter the Month (1 to 12) : ");		scanf("%d", &month);
	}
	
	for (yr = 1900; yr <= year; yr++)/*Traversing years*/
	{
		if (yr < year)
			m = 12; 
		else
			m = month;
		for (mn = 1; mn <= m; mn++)
		{
			if (mn == 2)
			{
				if (LEAP_YEAR)	No_of_Days = 29;
				else			No_of_Days = 28;
			}
			else if (mn == 4 || mn == 6 || mn == 9 || mn == 11)		No_of_Days = 30;
			else													No_of_Days = 31;
			int i = 1;
			curr = next;
			while (i <= No_of_Days)
			{
				next++;
				i++;
				if (next == 7)	next = 0;
			}
		}
	}


	j = 1, a = 7, i, x = 1;
	switch(month)
	{
		case(1):	printf("\n\t\tJanuary");		break;
		case(2):	printf("\n\t\tFebraury");		break;
		case(3):	printf("\n\t\tMarch");			break;
		case(4):	printf("\n\t\tApril");			break;
		case(5):	printf("\n\t\tMay");			break;
		case(6):	printf("\n\t\tJune");			break;
		case(7):	printf("\n\t\tJuly");			break;
		case(8):	printf("\n\t\tAugust");			break;
		case(9):	printf("\n\t\tSeptember");		break;
		case(10):	printf("\n\t\tOctober");		break;
		case(11):	printf("\n\t\tNovember");		break;
		case(12):	printf("\n\t\tDecember");		break;
	}
	printf("\t %d", year);
	printf("\n\n   Sun   Mon   Tue   Wed   Thu   Fri   Sat\n\n");
	for (i = 1; x <= No_of_Days; i++)
	{
		for (j = 1; j <= 7; j++, curr--)
		{
			if (x>9)	printf("    ");
			else		printf("     ");


			if (curr>0)	printf(" ");
			else
			{
				printf("%d", x);
				if (x <= No_of_Days)	x++;
				if (x>No_of_Days)		break;
			}
		}
		printf("\n\n");


		if (x>No_of_Days)	break;
	}
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS