대학교 1-2/컴프

21 프논이 기말 3번째 문제

Launa 2023. 9. 11. 22:02

21  프논이 기말 3번째

 

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
32
33
34
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
 
void printF(int score[], int standard, int count);
 
int main(void) {
    int count;
    int score[20], standard;
    int i;
 
    scanf("%d"&count);
 
    for (i = 0; i < count; i++)
        scanf("%d"&score[i]);
 
    scanf("%d"&standard);
 
    printF(score, standard, count);
 
    return 0;
}
 
 
void printF(int score[], int standard, int count) {
    for (int i = 0; i < count; i++) {
        if (score[i] < standard)
            printf("%d ", score[i]);
    }
    printf("\n");
    for (int i = 0; i < count; i++) {
        if (score[i] >= standard)
            printf("%d ", score[i]);
    }
}
cs

 

기준이 되는 숫자를 기준으로 출력하기이다

if문을 사용했다

+23.09.18

이것은 배열 2개를 사용해서 기준보다 낮은건 low 배열에 높은건 high 배열에 저장한뒤에 출력하는 코드이다

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
32
33
34
35
36
37
38
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
 
 
int main(void) {
    int count;
    int score[20], standard;
    int i, j = 0, k = 0;
    int low[20], high[20];
 
    scanf("%d"&count);
 
    for (i = 0; i < count; i++)
        scanf("%d"&score[i]);
 
    scanf("%d"&standard);
 
    for (i = 0; i < count; i++)
        if (score[i] < standard)
        {
            low[j] = score[i];
            j++;
        }
        else
        {
            high[k] = score[i];
            k++;
        }
 
    for (i = 0; i < j; i++)
        printf("%d ", low[i]);
    printf("\n");
    for (i = 0; i < k; i++)
        printf("%d ", high[i]);
 
 
    return 0;
}
cs