216k views
3 votes
Write a program that prints a one-month calendar. The userspecifies the number of days in the month and the day of the weekon which the month begins. The numerical dates must line up sothat the rightmost digit of the date is aligned with the rightmostdigit of the date above or below it (if there are anysuch). Below is an example output showing theformat you should use. The user input is shown as underlinedtext.Enter number of days in month: 31Enter starting day of the week (1=Sun, 7=Sat): 3 1 2 3 4 56 7 8 9 10 11 1213 14 15 16 17 18 1920 21 22 23 24 25 2627 28 29 30 31This program isn’t as hard as it might seem. The mostimportant part is a for statement that uses a variable i to countfrom 1 to n, where n is the number of days in a month, printingeach value of i. Inside the loop, an if statement testswhether i is the last day in a week; if so, it prints anewline. Note that the two digit dates that start a week arealigned with the left margin.Here's what I have so far.#includeint main(){int i,days,start;printf("Enter number of days in month:",days);scanf("%d", &days);printf("Enter starting day of the week (1=Sun, 7=Sat):",start);scanf("%d", &start);for(i=1;i<=days;i++) { printf("%3d", i); if(i == 7 || i == 14 || i == 21 || i == 28) { printf("\\"); } }return 0;}

2 Answers

3 votes

Answer:

d

Step-by-step explanation:

d

User Thomas Jung
by
5.1k points
6 votes

Answer:

See explaination

Step-by-step explanation:

#include<stdio.h>

#include<conio.h>

int main()

{

int days,start,i;

printf("Enter number of days in month: ");

scanf("%d",&days);

printf("Enter starting day of the week (1=Sun, 7=Sat):");

scanf("%d",&start);

printf("\\Sun Mon Tue Wed Thu Fri Sat\\");

for(i=0;i<start-1;i++)

printf(" ");

for(i=1;i<=days;i++)

{ if (i<=9)

printf(" ");

printf("%d",i);

if ((start-1+i)%7==0&&i!=days)

printf("\\");

else

printf(" ");

}

printf("\\");

getch();

}

User Gordon Williams
by
5.2k points