Professional Documents
Culture Documents
2022 Midterm
2022 Midterm
Submit your answers all in *.c file format to LearnUS before the deadline. No late submissions will be
accepted. You must also compress all answers as a single file in *.zip format prior to submission. There are
a total of three questions in this exam.
------------------------------------------------------------------------------------
실행 예시
Enter the length of the array: 3
Enter the elements of the array:
1
3
5
The second largest element in a is: 3
The average of all elements in a is: 3
The number of negative elements in a is: 0
실행 예시 1 실행 예시 2
Please enter an alphabet: @ Please enter an alphabet: 1
Please enter an alphabet: 3 Please enter an alphabet: -
Please enter an alphabet: w Please enter an alphabet: Q
Conversion result: W Conversion result: q
*밑줄 친 부분은 사용자의 입력을, 그 이외의 부분은 출력을 나타냅니다.
P3. hourglass.c (40 Pts)
연돌이는 아래 규칙에 따라 동작하는 모래시계를 가지고 있다고 합니다. 전체 모래 무게, 1초당 떨어지는 모래 무게,
모래시계를 뒤집은 후 관측할 시각을 입력 받고 (예: X초 후), 그 때에 모래시계 아래쪽에 쌓인 모래의 무게를
출력하는 프로그램을 작성하세요.
규칙
1. 사용자는 모래시계의 전체 모래의 무게(g), 1초당 떨어지는 모래의 무게(g), 모래시계를 관측할 시각(초)를 각각
자연수로 입력합니다. 자연수 이외의 입력은 고려하지 않아도 됩니다.
2. 모든 모래는 0초 시점에 모래시계의 위쪽 부분에 있고, 1초가 지날 때마다 사용자가 입력한 양만큼의 모래가
떨어집니다. 단, 위쪽에 남아있는 모래의 양이 1초당 떨어지는 모래양보다 적을 경우 남아있는 모래만이 아래쪽으로
떨어집니다. (아래 그림의 1초후 부분)
3. 모래시계 옆의 연돌이는 매1초의 시작마다 시계를 지켜보다가, 위쪽 모래가 모두 떨어졌을 때 시계를 뒤집습니다.
이때 시계를 뒤집는데 걸리는 물리적인 시간은 무시합니다. (아래 그림의 3초후 부분)
4. 프로그램은 사용자가 입력한 관측시각 직후에 모래시계 아래쪽에 남아있는 모래의 무게를 출력합니다.
실행 예시 1
Total sand amount (g): 5
Weight of the sand falling per second (g): 3
Observation time (seconds): 3
Weight of the sand in the downside after 3 seconds is: 3g
실행 예시 2
Total sand amount (g): 512
Weight of the sand falling per second (g): 15
Observation time (seconds): 3600
Weight of the sand in the downside after 3600 seconds is: 450g