0 like 0 dislike
8k views

Write a program that prints a one-month calendar. The user specifies 2 numbers in the input:

- The number of days in the month

- The day of the week on which the month begins ( starting day of the week: 1=Sun;2=Mon;3=Tue;4=Wed;5=Thu;6=Fri;7=Sat)

寫一個程式 印出指定月份的月曆:

- 輸入一整數代表這個月有幾天

- 輸入一整數代表這個月一號星期幾 (1=星期天,2=星期一,...)

Example input:

31
3

Example output:

       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

Hint: 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 a month, 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 newline.

[Exercise] Coding (C) - asked in Chapter 6: Loops by (5.2k points)
ID: 31047 - Available when: 2017-11-09 18:00 - Due to: Unlimited

edited by | 8k views

71 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
    int a,b,i,j;
** **** ** ** * **** ** ** * **** * *** * ***
    for(j=1;j<b;j++)
    {
    if(j==1)
* ** ** * **** * ** * **** * *** * * ** * *** * **** * **  ");
    else
** ** ** ** *** * **** *** ** ** ** * * ** * * **   ");}
* **** *** * * *** *** ** **** *
** * * * * ** **** * ** * * ** ***
* * **** ** * * * * *** * ** *** ** ** * ******* ** * **** ** *** *** * * *** ** * **** * *
** ******** * ** * * * * * ***** * * ** * *** * * *** * ***** **** ** * * * ** ** * ** * ********* ***** * *** **** ** **
* * **** * ********** **** * ** * *** **** * * * ****** ** *** * *** ** *** * * *** * ***
** **** *** *** * ** ** * ** ** * * ** * * ***** *** * * * * * ***** ** * *** * ***** * * *** * * **** *** ****** * *
** * ** ** * * ** * * ** **** *** **** *** *** **** * * * * * * ** *** * * ** ****** *
****** **** *** * * * * * * ** ** * * * * *** * * * **** * *** *** ***** * * ** * ** * ****
* * ** ******** * *** * * *** ** ** *** * *
return 0;
}
answered by (-196 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
    int days, first,i;
    scanf("%d %d",&days,&first);
    for(i=1;i<first;i++)
    {
* * ****** ** *** ** ****** *** ** *** *** *** **** *   ");
    }
    for(i=1;i<=days;i++)
    {
** *** * *** **** ***** **** **** *** * * * ***
        {
*** * * * ** ** ****** * * * ***** * * **** ** * *** * ** * **** * ** * * *
**** * * * ** ** ** ** * * ** ** ***** ** * * * ** * * ***
* * * ** * ** *** * ** ** * ** * ** * ** *** * * * ** ** *** * * ***** ** ** *** ** * *
* * ****** ** ** * * *** * * * * ** * ** * * * * ** * * * ** *** * * * * * **** **** *
** ** * * ** ** * ** * ** * *** ***** *** ** * ** * ** * *** * * * ** *** * ****** * ** **** * **** * ** ** ** * ** ",i);
* *** ** * * * * ** * * * ** ** ** * * **** ** * * * *** ** * **
* * * * **** * * **** * * ** **** ** ***** * *** ** ** *** *** ********* * * *** **
*** * * * ** ** * ** * *** * ** ** ** * * ** * *** **** * * ** * * ** * ** *
* *** * ** * * * * * **** * *** ***** ***** ** **** * ** * * * ******** * * ** *** ****** * * * *** ** %d ",i);
**** * * * * * * ** ** * ** * * * ** * * ** * * * * *** * ** * *** *** *
**** * **** ***** ** ****** ** ** * ** * * * *** * * * * *****
**** ** **** * * * ** *** *** * ** * * ** * ** * * ** ****
* * *** * *** * *** ** *** *** ** * *** * *** **** *** * **
* * *** * *** * ** * * **** ** * **** * **** * ***** *** * * ***** * * ** * **
** *** * * ** * ** * ****** * ********** **** ** * * ** ** * *** * ** * * ** *
*** * ** *** * * * * **** * ** *** ** ** * ** * * * ** * ***** ** * * * **** **** ** * * ** * ** * * * ** %d\n",i);
* * * ** * *** ** * ** ** * * * * * * * * ** * * * * ***** * *** ** * *** **
*** * ***** * * * * ** * * * * * * * * **** ** ** ** ** ** * ** * * ** * * * * ***
** * ** * ***** *** *** ** * ***** ** * * * * * * * ** ***** *** **** ** ** *** * *
** * **** ***** * * ** *** * * * * * * ** * ** ** * * * * ***** ******* ** ** ********* * ** * *** *****
* ** ** * ** *** * * ** ** * ********** * ***** * ** * * *** ** *** * **
* * **** ****** *** * * ** ** * **** ** ** * ** ** * * *
        }
* ** * *** * ** ** *** * * * * **** * ******
******* ** * * ** *** * * * ** * * ****** ** *
*** ** * ********** * * ***** * * **** * * * * ** * * * * *** ** ** ****
        }
    }
    return 0;
}
answered by (-255 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
prog.c: In function 'main':
prog.c:6:5: error: expected ',' or ';' before 'scanf'
     scanf("%d %d",&days,&first);
     ^~~~~
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()

{
    int i=1,day,j,jj,a=1;
* * * ** * * *** ***** **** * * * * * * **** ***

    jj=j;
    for (i;i<=day;i++)
    {
***** * ** * * *** ***** **** ** ** *** (a;a<j;a++)
*** **** **** * * * ** * ** * * * ** **
** * *** *** ** **** *** * *** * ** * * ** * ** ** ** **** ** ** * (a<)
** * * *** ** **** * * * * ** ** ** ******* ** * * ** ** * * *** * *** * **  ");
* * *** * * **** * ** *** *** * * * ** ** * * * ** ** *** (a!=7)
* ** ** ******** * * * ** **** ** *** ** * ** * ***** *** * * *** * * *** * ");
* * * * ** * **** ** **** ** **** * ***
*** * ** ***** * **** * ** ** * * *
*** * * * * * *** *** *** *** * * * ***** * ** * (jj!=2 && i!=1)
* ** * **** * * * * *** ** * ***** *** * ** * * * %2d",i);
** ** *** * * ** * * * * **** *** * *
* * ** * *** ** ** * * ** * * * * * * ** **** **
*** * * **** * * ** ** **** ** ***** * ** * (jj==8)
** * ***** ** ** ** * *** * * * * * *
***** * **** ** **** * ** * *** * * ** * *** **** ** ** ** *** * * *** ***** ***
***** * * * * *** * **** * * *** ** **** **** * *** **** ** **
* * * ** * * * *** * ***** *** * *** * **
    }
* ** ** * * ** * * * * * *

* * * ** ** ** * * * 0;
}
answered by (1.1k points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()

{
    int i=1,day,j,jj,a=1;
** *** * * *** * ** **** **** *** * * * * * * **

    jj=j;
    for (i;i<=day;i++)
    {
*** **** ** **** * * * ** **** *** * ***** ** (a;a<j;a++)
*** ** * ** * * * * * *** **** ** * * ***** * * **
** * * *** * ** ******* * * *** ** * **** ** * *** * *** *** (a<)
* ** * * **** * ***** * * * * ** * * ** ** * ** ** *** * **** ** ** * *** ***** * * **  ");
***** * *** ** ** * ***** *** ** * * * ** * ***** ** * * * * **** (a!=7)
** * *** * * * * * * ***** ** * * * * * * ** *** * *** **** ** * ***** ** * * ");
* * * * * ** ** ** *** *** ** ** ** *** *** *
* *** ***** *** ********* ** ** *** * *** *
* ** *** * * * ** ** **** * * ** * * (jj!=2 && i!=1)
** * * * ** ******* ** * ** ***** * ** * * * * * %2d",i);
** *** * * * * * ** ** * *** *** ** ** **** ****
* *** *** * * * * * * ** * *** ***** * ** **** * * ****
** ** * * * * * *** ** ** * * * * (jj==8)
* ****** * ** ******** * ** * * * ***
* * * * * **** * ** ** * * **** *** ** ** ** * * **** * * ** **** *** ** *
* ** ** ** ** * * ** * * * ** * * *** ** *** * * * ******** * *
** * * *** *** * * * ******* *** ** *
    }
* * * * * * * **** * *
* * * ** * * * *** * *** * * ** * ** **
* *** *** ** ** ** ** * * 0;
}
answered by (1.1k points)
0 0
prog.c: In function 'main':
prog.c:31:5: warning: implicit declaration of function 'system' [-Wimplicit-function-declaration]
     system("pause");
     ^~~~~~
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
    int day,space,x,y=1;
    scanf("%d %d",&day,&space);
    space=space-1;
*** * ***** * * * * * * ** * * *
** *** **** ** ** * *** * *** * * * * * *
* * **** *** * * ***** ****** * * ** * *** **** * * * * **
** ** * * ***** *** * * ** * * * * **** ** *** * **** *** * **** ** * * ** * * *  ");
*** ** * * * ** * * *** * * *** ** *** ** * * **** * * * * ***
**** *** * *** * *** * ** ***** * ** * *** * ***** ** *** ** *** * *** * *** ** *   ");
* * ***** * ** * **** *** * * **** * ** * ***
**** ** * ** **** * *** * *** * ***** ** * ***
** *** **** * **** * * * * *** * * ** *** ** ** * **** *** * * *** ** * **
** *** ** * * * * **** * ** *** * ***** * * *** * * * * *** * * ** * * *** ***** * * %2d\n",y++);
* * * ** * *** * * ***** * * ** * * * * * ***** * **** *** **
** **** *** * * ** ** ***** * ** * * * ** * *** * ** * ** * *** if (x%7==1){
** *** * ** * * * **** * * * * ***** * *** * ** *** * * **** * * ** *** ** ********* ****
* * * * ** * * * *** * ** **** * ***** *** * ** ** ** *
** * * * ** ** ** ** ** * ****** **** *** * ** ** ** **
* ** * * * * **** ** * * **** *** * * * * * * * ** ***** ** *** * ** ** *** * *** ** * * * * ** ** * ** ** %2d",y++);
* ** *** ******** * * ** * * ***** *** * * *** * * * ** ** * * *
** * * * * ***** ** * ** * **** * ***

    }
    return 0;
}
answered by (54 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()

{
    int i=1,day,j,jj,a=1;
* ** * * ** ** * * ** **** *** * * **** ***** **

    jj=j;
    for (i;i<=day;i++)
    {
* **** ** * ** * ** ** *** *** * ** (a;a<j;a++)
** ***** * * * * ** * * ***** ** ** ***
*** ** * ** * *** * * ** * *** * *** ** * **** *** * * * (a<)
**** * **** * * ** * ** ** ** * ***** ** * * **** * * * *** * * * * *  ");
**** * * * * ** * * **** ***** ** ** * * *** * ** ** * * * * (a!=7)
* * * * * ** ** ***** *** *** * ****** ** ***** ***** ** * ** * *** * * * ******* ** * * * ");
* * * * *** ** * * ** ** ** * * ** ***
*** * * *** * ** * ** * * ********* * *
***** ** * ** * * ** * * *** ** (jj!=2 && i!=1)
****** * ***** * ** ** * ** ******** *** * * * ** * %2d",i);
* ** * ** ** ** ***** ** * * * ** * *** **
*** * **** * *** *** * * * * ** * * * ** **** * * * *** **
* **** ** *** * ** **** ** * * ** * ** * (jj==8)
* ** * ** *** ** * *** ****** ** *** *
* * * * ****** ** **** **** ** * ****** ** * * ** ** *** * *********
***** *** *** * * ******* *** ****** ***** ** ** * * * ** * ** *
** *** * * ***** * *** *** ****** *** *** * ** * *
    }
**** **** ***** * ** *** 0;
}
answered by (-249 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()

{
    int i=1,day,j,jj,a=1;
* ** ** * * ** * * * * * ****** ****** ***** ******** *** *

    jj=j;
    for (i;i<=day;i++)
    {
****** **** *** * * * ** * ***** * ** ** ** (a;a<j;a++)
** * * *** * *** * *** ** ** * ** ** *
* * ****** *** ** *** * * ** ** ** ** *** *** * ** ***** (a<)
* ** ******** ** * * * * *** * * * * * *** ***** * * * * ** * * * * * * *
* ** ** * ** ***** ** * * * ** * * * * ** ***** * ** *** (a!=7)
* ** * * ** ** ** ********* * ***** * * * * * *** ** *** * ***** * ** * *** **** *** * *** *** ** **
*** * * **** *** ***** * * * ** * *** ** **
* ** * **** ****** * ** * ** ** *
* ** *** **** **** *** ** * * * * * * * ** * (jj!=2 && i!=1)
* * ** * * * * ** * * ** * **** ** * * * *** * ** * * **
*** ** * * ** *** ** * **** * **
** **** * *** ** * **** * * * **** ** ****** **** **** * *** *
* *** * ** * ** * * ** **** * * * (jj==8)
* * *** *** * * ** * * * * * *** ** * * ****
*** ****** * ** ** *** * ** * * *** * * *** *** * * * * * *** * * * * **
*** *** *** * ** **** ***** * * ** * * * ** *** *** * ** * ** *
** *** * * * * * ** ******* *** * *** *
    }
    return 0;
}
answered by (-249 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
    int day,space,x,y=1;
* * * * * * *** * * * ** * %d",&day,&space);
    space=space-1;
*** *** * * * * * ** ** **** * * ** * *
** ** * ** * *** ****** * * * * * * *** *** **** *** * ");
**** * * ** * ** * * ** ** *** *** ******** ***** *
** * * * **** * * * * * **** * * * * ** *** * **** * ** * *** ** * *  ");
* *** *** * ** *** *** *** ******* * *
**** * * * * *** * ** * *** **** ** **** **
** * ** *** * * ******* ** * ** **** * * * * * ** * ****
* ******* * ** ****** **** ** ***** * ** * * ******* * ***** ** * ***** ** **** * * * * * *** * ** *** * * ** **
*** * *** * ** ******* * * ** ** * ** * *** * * * * * *
* * *** ** ** * ** * * *** **** ** ** * * * ** ** * * **
*** ** ** * * **** * *** ** *** * * * * **** ** * **** * ***** * *** * * * * *** ** * ***** * *** *
********* * * ** *** *** **** * ***** **** * * * * * * * * * *
** ** *** * * * * * * *** * * ** * * ****

    }
    return 0;
}
answered by (54 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main(){
    int days,weekb,i;

** * * * * **** * * * ** * %d", &days, &weekb);
* ** ** * ***** * ****** *** *
*** *** ** * * * * *** * ** * * **** * * ** ** * * *   ");
* * ** ** *** * * * * * * ** * ** * *** ** i=0;
    }

* ** * * * ** * * * * * ** *
**** **** * ** * * * *********** * * *** *** ** ** * ** * ** * * **

* * ** * * ** * * ** * *** * *** ****** ** ** ** * *
* * * **** *** ***** * * * ** * *** * ** * * ** ** **** * * * ***
** * ** * * * * * **** * ** ** ** * ** * **** * ******* * *****
* ** *** ** * * ** *** ** ** * ** ** **** * ** * *
** ** * ** **** * ** ** * ****** * * * ** ** ****
** * **** * * ** * * * * ** ** **** * ****** ** * ** ** * * ** * ****** *** * * ******** ");
** ** * ** ** * * * * * ** * * ** * * **
* * * * ** ** **** * * * *** * * ** *** *** **

    }

******* ** * ** ***** *** 0;
}
answered by (-116 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
* *** * * ***
int m,w,i,j=0,k;

int main()
{
* * ** * ** ***** *** **
** ** ** **** * ****

for(k=1;k<w;k++)
{
** * ** ** *** ** * *** * * *** * **** * * * **
* * ** ** * * * * *

}



for(i=1;i<=m;i++)
{

**** ** *** *** *** ***** ** * **** ** ****** * * **
* ** ***** ** * ** * ** ");}
***** * * * * * * * * ** * **** ** * ***
  j++;
** *** * ***** ** * (j==7)
* * ** ** ** * * ** *
* * *** ** * *** ** * * * ** ** ** * *****
**** *** * * * ** * * **** ** **** * * * * ** * **
* *** ** * * * ** *

}
** * ** ** * * *

}
answered by (-336 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.6.236
©2016-2025

Related questions

2 like 0 dislike
67 answers
[Exercise] Coding (C) - asked Nov 9, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 31048 - Available when: 2017-11-09 18:00 - Due to: Unlimited
| 7.7k views
0 like 0 dislike
99 answers
[Exercise] Coding (C) - asked Nov 2, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 29829 - Available when: 2017-11-02 18:00 - Due to: Unlimited
| 11.4k views
12,783 questions
183,442 answers
172,219 comments
4,824 users