0 like 0 dislike
3.4k 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.

[Exam] asked in Final Exam
ID: 43463 - Available when: 2018-01-20 09:00 - Due to: Unlimited
| 3.4k views

13 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
  int cal[100];
  int daysinmonth;
  int dayofweek;
  int i,j,k;
  int nextline;
  int newline;

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

** ** **** * ** *
  {
***** *** ** ** * ** ** ** ** * ** *** **** * * ** *
  }

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

** ************* * **** * ** *** **** ** *
    {
** * * * **** *** * * ** ** ** ** ** ***
    }

* * ** * ** ** **** * * * **** ** *
**** ** **** *** * * *** ** ****
** * ** *** * ****** *** * * ** * * (i<10)
** *** *** * * * * *** ******* *** * * * **
* ** * ** * * * ****** * * * ** * ** ** * * ** ** * *** * ** ",cal[i]);
** *** * ** ** **** ****** * * * * * * **

**** ** **** * * * * *** * * * * * * ****** ** * * if(i>=10 || i<daysinmonth)
* ** * ** ** * * * *** * ** ****** * ** * **** ** * ** ********
** * ** ** *** ** **** * * ** ***** **** ** * ** * * * * * ** **** ** * * ",cal[i]);
*** ** * * ** * * * * * * ** *** ****** ** ** * *** * ** * *** *** * * *

** * * **** * * ** ** * **** * ** ** * ** * if(i=daysinmonth)
* ***** * * * **** ** * * * ** * * * * **** * *** *
** *** ** ** ** ** ** * **** ** ****** *** * *** *** * * *** ******* * ** *** * *** * ***
** **** ** *** * **** *** * *** * * * * * * **** *** *



* **** *** * * * * * * ** ** * ********** **** *
**** *** ** ** * * ***** * * * *
*** ** ** * *** *** * **** *** * ** * * * ** ** * ***** ** * ** * == k )
*** ** *** * *** **** * *** * *** * * ** ** ** * *** ******* ***
* *** * ** **** *** * * * * * * * * **** ** ***** *** *** * ***** * * * * * * *** ***
***** ** * * **** *** ** **** *** ** * * * ** ***** ** ** ** * *
* * *** * * ** * * * * **** * ** * **
    }



* * * **** * **** ** **** *** 0;
}
answered by (-193 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 (void)
{
    int i,j,n,s,cpt,c,m,b;
** *** ** * *** **
** * * * * * *** ** *** * * * ****** *
**** ** * *** ** * *** ** * *** * ** **
* ** * * * ** * ** *
* * * * **** * ** **** (i=0;i<=n;i++)
    {
** * * **** * * * * ** ** * * * * * * **
**** ** * * *** * * ** *** ** * * *** *** ");}
** ** * ** * * *** ** **** * ** ** *** * **
* ** * * * ** * ** ** * ***** *** ** *** * *** *  ");}
    }
** ** **** * ** * * * *** (i=1;i<=c;i++)
    {
* ** ****** * ***** * * * * *** ******* * ** * * * * *** *
*** ******* * **** *** * ** * ** * * * **** * *  %d",i);}
** * ** ** ** *** * ** *** * * *** ** * * ** *
* * * * * * * * * ** ***** * ***** *** ** * * * ** * ****** ****
    }
** * ** *** **** ***** *** * ** * * * *
* * * *** *** * * * * * **
** * * * * * * ** * * ** * * ****
** *** *** * *** **** **** * ******* ** ** ** *
{

******* * ** **** ** **** * ** * *** * * * * * ***
* * * ***** *** ** **** * * **** * **** ***** * * ** && m<1)
*** ** * ** * ** * * * * ** ** ** * *** **  %d",cpt);}
* * * ** ****** ** **** * ** * * *** * * *** * ** ** && m>0)
** * * * ***** *** * ****** * * * * **** %d",cpt);}
* * * * **** * * ** * * ** * * * * * ** * * ** && m<1)
** * ** ** ** ** ** * * ** * * * ** **** **** * * * * ** * * * * * * * * %d",cpt);}
* * **** **** * *** * * *** ** * ***** *** *** ** && m>0)
* ********* * * * *** *** * * * *** * ** ***** ******** * * ***
* * ** * ***** * *** * * ****** *** ** * * ** *** * ****** * ((cpt+n-1)%7==0)
* *** **** ** ** * *** * * *** ******* *** * * *
** * ***** ** ** **** * * * *** *** ** * * ** ** * ** *
*** * ** * * ** * ** ** * ** * * * ** * * *


}

* *** * ** * * **** ** ** 0;

}
answered by (-168 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
  int cal[100];
  int daysinmonth;
  int dayofweek;
  int i,j,k;
  int nextline;
  int newline;

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

** ** **** ** **** ** ** *
  {
** ** ***** * ** * ** *** * ** *   ");
  }

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

**** * * * ***** * ***** ** ** * * * **
    {
* * **** * ***** ** *** **** *
    }

* **** *** *** *** ** ** * * ****** * * *
    {
***** * * * *** *** ** ***** * * * *** *** *** (i<10)
* * * *** ***** ** * ******** ** ** * ***
* * * ** * ** ******* * * *** ****** ** *** *** * ** * **** *** * ** ** ",cal[i]);
* * * ** ** ** * ** *** ** ** * ** ****
** *** ***** * * * **** * * ** ** ***** ** *
* ** ** **** **** ** * ****** *** **** *
** ****** * *** ** * * * * * ** * * * **** **** *** **** * **** ***** * **** * ** * ",cal[i]);
* ** **** ** * *** * *** * * *** ** ** ** * * ***

* ** * * * **** **** ** ** *** * * (i == daysinmonth)
* * * *** ** **** ** * ** * ** * **** ** ** **
* * * * * ********* ** * **** ******** * * * * * * *** * * * ** ***** * *** **
* * *** *** ** * * * * ** * **** **** ****

***** ** ** ** * * *** ** * * * ** * * ** * * *** ** * ** * *
** * * * * ** ** ** *** **** * ** **
* * * * **** **** * ** * * ** ** *** * * *** ** * ** * * **** == k )
********* ** * * * ** * *** ** * * * ** * * ** * ** *
** * * * **** * * * *** ** * * *** ** ** **** * ***** * *** ****** * ***** ******* * ** * ** **
** * * ******** ****** * * * **** * * *** ** ** * * * **** * ** * ** ****
* * *** * * * *** * ** ** * * * ** * * ** * **
** * * ******** * ******



**** * * * * * * **** 0;
}
answered by (-193 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
  int cal[100];
  int daysinmonth;
  int dayofweek;
  int i,j,k;
  int nextline;
  int newline;

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

** * * *** * * **** ***** **
  {
*** **** ** * ** * * *** ** * ** ******* *   ");
  }

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

*** * ***** ** * * **** ** ** * * *
    {
* *** *** ** ** * * * * **** ** * ******
* ** * * * * * **

* ** *** * * * *** * * ** * **
* ** ** * * ** * ** *
** * * ** * * * ** * *** * *** (i<10)
*** * * *** ** ****** * * **********
** * ** * * * * ** **** ** ** ***** * ** ***** ** *** ** * * ",cal[i]);
* * **** * ** * * ** * ** *** ** **** ** *
* * * ** * *** * * ** * ****** * *
** * ** ** * ******** * ** ** ** *
* ** *** * ** *** ** * * *** * ** ** ***** * *** * * * ***** ** **** *** ",cal[i]);
* * * * * * * * * **** * * *** ** *** *

* * ** * ****** ** ** * *** ** ** ** * * * * ** * * * *
* * ** ** * * ** ****** * ** * ** *****
** * * *** ** *** ** * ** ** * **** * **** ** * * * *** == k )
** ****** * * ** ** ** * ** *** *** ** ** * *** * * * * **** ***** * ** ***
** * ** * ** ***** * ** ** *** ** * ****** * ** **** ** * *** ** *** ** ** * * ** * * *** ****** * ** *
* *** ** ****** * *** * ** *** *** * * * * * ** * * * ** * * * **
* * * *** * * * **** * *** * * *
* * ** *** * *** *



** *** * * * * * * *** 0;
}
answered by (-193 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
  int cal[100];
  int daysinmonth;
  int dayofweek;
  int i,j,k;
  int nextline;


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

****** * * * ** * * ** ****
  {
* ** *** ** ****** *** ** * ** *   ");
  }

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

* ** * ** * * * * *** ** * ******
    {
****** * * * * * ** * * * *** * *** * ***
    }

** **** * * * *** *** ***** *** ** **
* ***** ** ****** ***
* **** * * * * * ** ** ****** *** *** * (i<10)
** ** * * *** ** * ** **** ** *** *
** * **** *** * ** *** ** *** * **** **** ** ** * ***** ** * ***
** ** * * **** * ***** ** * * * * *
* * **** ** ***** ** * **** * * ** * *** * * *** ** *
* * *** ** * * * * ** * * * * *** ****
** ** * * ** * * ** * * * ** * ** *** ** ** ** * ** * * *** * * ** ** * * ** * * * * *** ** **
**** * * ** ** * *** * * ** ** * ** * * **

** * * *** ** * **** * * ** * **** *** * * * *** *** ****** * *
* *** * ** ***** ** * * * *** * *** **
**** * * * *** * ** * * * ***** * * * * ** * * * * * ** ** == k )
* * ** * ****** * **** **** ** ***** *** ** ** ** ** **** * **** * ***
* * ** *** * * * ** *** ** * * *** * ***** *** * * * * *** * * * ** ** * * * * * ** ** *** **** * *
* * * ** **** ****** * ** *** * * *** ** ** **** ** * * *** ** * *
* * ***** ** ** * ** ** ****** * **
    }



** ** ** *** * ** * **** *** 0;
}
answered by (-193 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 n,m,i,j=0;
* ** * **** *** ** ** * * ** ***** * * ** *
*** * * *** * * ***** ***** * * ***
* * ** ** *** * * * *
    for (i=1;i<(m+1);i++)
    {
* ** * *** * * ** ** ** * ** ***** ** * *** *** (j==0)
* *** * ***** * * ** * * *** *** * **
* ** * * * *** ** **** **** ** * ** ** ** * * **** ** ** * *** **  ");
* * * * ** * * ** *** ** ** ***** *** ** ** * ** *** *** **
* ** * * * * *** *** **** ** * **** *
* ** ** ** * ** * ** ***** * ** *** * * *
**** *** * * * ** *** *** ** ** *
* *** * ** ** ** ** * *** * ** *** * * *** * * ** * * **** **** **** **** *   ");
* * **** ** ****** ** **** * ** * *** * ** *** * * * *
    }
    for (i=1;i<n+1;i++)
    {
** ***** * * ** * **** * * * * * * * ** * ((i+m)%7==1)
* ** *** * * *** ** * ** ** ***** * * **** ****
* ** ** * * * * * * * ** ** * * ** ***** * ** ** * **** ***** ** ** *** *
***** *** ** **** ** * ** ** *** * * *
*** * * ** ** ** * ** * ** * * * * * ** * if ((i+m)%7==0)
* ****** * * ** ** *** ** **** *** * * * ** *** **** * * **
* ** *** ******* ** * ** * ** * * ** ** * ** ** *** * ** * * **** ** *** ** * ** * ** * %2d\n",i);
* *** * ********** *** ** *** ** * * * * * ** ** * ** *** **
** ** * * * ** ** * * *** **** ****** ** * *
** * * * *** * * **** **** ** * * ****
* ** ***** * *** * **** * * ** ***** * * *** * * ** ** * ** * ** ** %2d",i);
* * ** ****** * * * ** * * * * ** *** *
    }
**** ********* ** * * * 0;
}
answered by (-229 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
  int cal[100];
  int daysinmonth;
  int dayofweek;
  int i,j,k;
  int nextline;
  int newline;
  int q = 10;
  int *p = &q;

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

* **** ** **** * * * *
  {
** * * * * ** ** * * *** * ***   ");
  }

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

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

* **** * * * * * ** ******* * * * ****** ******
** ***** * ** ****** **
* **** ** ** ** * **** * * * ** * ** *** (cal>=q)
* ** *** ** ** ** ** * **** * * * * *
** **** *** ** * * * ** *** **** * * * *** *** * * * ** **** * **** **
*** * ** * * **** * * ** * * * * ** ** *
** *** *** * * ** * * * ** * * ** ****
* * * * *** * **** * ***** * ** * **
* *** * * ** * ** *** * ** ** * * **** *** *** * * * ** ** ***** *********
* * * * * ** ** * ** ****** * ** * * * **

** ** ** ** * * * * *** **** *** * * * * * * * * * *
* * **** * *** ** * *** * *** * *** * * *
*** * * * * * * *** * ** * *** **** ***** * *** * * ** * == k )
**** ** *** * ** ** * *** * ** * * *** ** * ** ** *** *** *
* * ** * ** * * ** ***** * * * **** ** * ** ** * * * * * * * * ** ** **** **** ** ** **** **** * * * ***
****** * * * ** * ** *** * ** **** *** ** ** * * * **
*** * * ********** * * *** ***** * ** ** *
** * * * ***** * * * ****



****** * ** **** ** ** 0;
}
answered by (-193 points)
0 0
prog.c: In function 'main':
prog.c:32:16: warning: comparison between pointer and integer
         if (cal>=q)
                ^~
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
  int cal[100];
  int daysinmonth;
  int dayofweek;
  int i,j,k;
  int nextline;
  int newline;
  int *p =10;

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

* * * ** **** ** * *** * * *
  {
* **** ** * *** ** * **** ** ****** ******* * *   ");
  }

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

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

**** * * * * * * * ** *** ** *** **
**** ** ** *** * **
*** ** * * ********* * ****** * **** * * (cal>=p)
* ** *** * ** * ** * *** *** ********
*** * * * ** * * * ** * * ** * *** **** ** * ** ** * * *** * * * * * **
* * * * ** * ***** * * ** * * ***** *** *
** * ** * *** * * * ** ** * *** *
** * ** * * ** * ** ** ** * * * ** * ** **
**** ** * * ***** ** * * * * * ** * *** ** * ** *** *** * *** * ** * ** ***** **
*** *** * **** * ** ** * * * * ** *

* ** ** **** *** *** ** ** ** *** * *** ** *** ** * **** * *** ***
** *** * *** **** * ******* * * ** *** *
* * * * * ** * * * **** ****** * * ******* * * * * ** * * ** *** * **** == k )
*** * ** * * * * ** *** ***** * * *** *** *** ** * **
** * * *** ** * * * ** ***** * ***** ** **** * * * * * * * * * *** ** * * * * **** * ***
** * * * ** ** * * * *** * ** * * *** *** ** * *** * ** **** * *****
* ** ** ** * * ** * * ******* * * * ** ** * **
    }



* **** ** ******* * * *** 0;
}
answered by (-193 points)
0 0
prog.c: In function 'main':
prog.c:12:11: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
   int *p =10;
           ^~
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
  int cal[100];
  int daysinmonth;
  int dayofweek;
  int i,j,k;
  int nextline;
  int newline;

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

* * * ** * * *** * * *** *
  {
* ***** ** * *** ** ***** * ** **** ** **   ");
  }

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

*** * ** ***** ** ** * **** * *
** *** * ** **** * *
* * * * ** * * * ******** * ******* ** *
    }

** ** ** * ***** * ** ** ** ** **
*** * ** * * ** ** * * *
* **** * * * *** * ***** **** * ** ** * (cal>=10)
** * * **** * * ***** **** * * ***** * ** ** * **
***** *** *** * *** * * ** ** ** * * * ** * * * ** ** * ** * * *** ** *** ****
* ** ***** ** ****** * * **** ** * * *
* ** * * * ** ** ** *** * ** * ** ** * * *
** * * ** * * * * *** *** * * ******* ** **
**** *** * ** * ** **** * * ** * * ** **** ** * * **** ** * ** * *** ** *
* ** ** *** ** * ** ** * *** *** * * ****

* * ** * ** * * *** ** * * * ** * ** * ** * *** * ** * * * ** * **
** * *** *** *** **** ** * * ** * * *
*** * **** **** * * * ** * ** * ** * * **** * * ** ***** * * * ** * ***** * == k )
* *** * * ** **** ** ** ** ******** * ****** *** ** ***** * *
* * * * * *** * * * * ** ** ********* ** * ** **** * * * ** * **** * ** * *** **** ** * * **** *
* *** ** **** * * * ** * * * ** * ** ** * * *** * *
** ** * * * * * * * * ** ** * * ** * *****
    }



* *** * ***** ** ** 0;
}
answered by (-193 points)
0 0
prog.c: In function 'main':
prog.c:30:16: warning: comparison between pointer and integer
         if (cal>=10)
                ^~
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
    int n,m,i;
***** * ** ** *** * **** *********** * *** **
* * * ***** ** * * * * ***** ***
    for (i=1;i<n+1;i++)
    {
* ** * ** ******** ** **** * ** * ** * (i%7==1)
* * * ****** ** *** ** * ** *** * *** *
* ** * ** **** ** * ** * ***** *** **** * ** * *** *** ** * *** ** ** *** *
** * * * * * ** *** **** ** *** **** * * *
* ***** * * * **** * *** *** * * ****** if (i%7==0)
*** * * *** * *** * ** * ** ***** *** **** *** *** * **
** *** *** **** ***** * *** * ** * *** ** ** * *** * * *** *** ** * *** ** * * ** * * * ** %2d\n",i);
* * **** ** * *** ** ** ***** * * * * ***** * * ** * ** *
***** * * ** *** **** *** * * * ** * * * **
* * * * * * **** * *** * ** *** **** **
*** ** * *** ** * * * ** * * *** * * *** * * * ***** *** * * * * * %2d",i);
* ** ** *** * * ** *** ** * * ** **** * **
    }
* ****** ** * * * * ****** * * 0;
}
answered by (-229 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.194.138
©2016-2025

Related questions

0 like 0 dislike
6 answers
[Exam] asked Jan 19, 2018 in Final Exam
ID: 43462 - Available when: 2018-01-20 09:00 - Due to: Unlimited
| 1.8k views
0 like 0 dislike
8 answers
[Exam] asked Jan 19, 2018 in Final Exam
ID: 43461 - Available when: 2018-01-20 09:00 - Due to: Unlimited
| 2.1k views
0 like 0 dislike
4 answers
[Exam] asked Jan 19, 2018 in Final Exam
ID: 43460 - Available when: 2018-01-20 09:00 - Due to: Unlimited
| 2k views
0 like 0 dislike
12 answers
[Exam] asked Jan 19, 2018 in Final Exam
ID: 43459 - Available when: 2018-01-20 09:00 - Due to: Unlimited
| 3.5k views
1 like 0 dislike
37 answers
[Exam] asked Jan 16, 2018 in Final Exam
ID: 42302 - Available when: 2018-01-17 14:00 - Due to: Unlimited
| 10.8k views
12,783 questions
183,442 answers
172,219 comments
4,824 users