REQUIREMENT / ASSIGNMENT QUESTION
Write a C program that prints a one-month calendar. The user specifies the number of days in the month and the days of the week on which the month begins:
Output
Example
Enter number of days in month : 31
Enter Starting day of the week
(1=Sun, 2=Mon, 3=Tue, 4=Wed, 5=Thu, 6=Fri, 7=Sat) : 3
Tips: This program is not as hard as it looks. The most important part is a for statement that uses a variable i to count from 1 to n, where n is the number of days in the month, then printing each value of i. Inside the loop, an if statement tests whether i is the last day in a week; if so, it prints a new-line character.
My Question, How to create coding c++ --->>> Diplay C Program that print a one Month calendar. user must specifies the number of days in the month and the day of the week on which the month begins.
Enter number of days in month : 31
Enter Starting day of the week
(1=Sun, 2=Mon, 3=Tue, 4=Wed, 5=Thu, 6=Fri, 7=Sat) : 3
Tue 1,8,15,22,29
wed 2,9,16,23,30
thu 3,10,17,24,31
fri 4,11,18,25
Sat 5,12,19.26
Sun 6,13,20,27
Mon 7,14,21,28
It's not that hard that you think it is. You don't need an array.
Instead of
printf("Enter Starting day of the week : ") ;
it should read
1 2
printf("Enter the day of the week on which the month begins: ") ;
scanf("%d \n",&starting_day) ;
The loop would be:
1 2 3 4 5 6 7 8 9 10 11
printf("Enter number of days in month : ") ;
scanf("%d",&number_of_days);
...
for(int i = starting_day; i <=number_of_days; i++)
{
printf("%d",i); // Note no &
if((i%7) == 0) // This is the trick to place the correct end of line %=modulo
printf("\n");
}
what you have to do is to insert the correct number of spaces (especially at the beginning
Please don't try and hijack someone else's thread with a totally unrelated issue. Start your own thread instead, so that people can answer you without getting mixed up with the answers to the original poster's problem.