Write a program that generates a simple calendar for one month given what day th
ID: 3641330 • Letter: W
Question
Write a program that generates a simple calendar for one month given what day the first day is and how many days there are in that month.For example:
- Input:
The first day is: Thu
The days in the month: 31
- Output
Sun Mon Tue Wed Thu Fri Sat
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Note: Probably you need to use character strings in this program,
to declare a char string s1 which can contain 9 characters at most: char s1[10];
to compare whether a char string s1 and another string s2 are equal: strcmp(s1, s2);
strcmp(s1, s2): The function returns an integer greater than, equal to, or less than 0, if the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2 respectively.
Explanation / Answer
#include #include #include void main(){ int i=0; int tab=0; // keep track of the tabs int total_days; // total number of days char first_day[10]; // the first day printf(" Enter the first day of the month :: "); scanf("%s",first_day); printf(" Enter the number of days in the month :: "); scanf("%d",&total_days); if(first_day[0]=='S' || first_day[0]=='s'){ if(first_day[1]=='U' || first_day[1]=='u'){ if( first_day[2]=='N' || first_day[2]=='n') tab=0; } } if(first_day[0]=='M' || first_day[0]=='m'){ if(first_day[1]=='O' || first_day[1]=='o'){ if(first_day[2]=='N' || first_day[2]=='n'){ tab=1; } } } if(first_day[0]=='T' || first_day[0]=='t'){ if(first_day[1]=='U' || first_day[1]=='u'){ if(first_day[2]=='E' || first_day[2]=='e'){ tab=2; } } } if(first_day[0]=='W' || first_day[0]=='w'){ if(first_day[1]=='E' || first_day[1]=='e'){ if(first_day[2]=='D' || first_day[2]=='d'){ tab=3; } } } if(first_day[0]=='T' || first_day[0]=='t'){ if(first_day[1]=='H' || first_day[1]=='h'){ if(first_day[2]=='U' || first_day[2]=='u'){ tab=4; } } } if(first_day[0]=='F' || first_day[0]=='f'){ if(first_day[1]=='R' || first_day[1]=='r' ){ if(first_day[2]=='I' || first_day[2]=='i' ){ tab=5; } } } if(first_day[0]=='S' || first_day[0]=='s'){ if(first_day[1]=='A' || first_day[1]=='a' ){ if(first_day[2]=='T' || first_day[2]=='t' ){ tab=6; } } } printf(" SUN MON TUE WED THU FRI SAT "); printf(" "); for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.