C언어 콘서트 11장 프로그래밍(Programming) 풀이
본문 바로가기

프로그래밍/c언어 콘서트

C언어 콘서트 11장 프로그래밍(Programming) 풀이

 

4.

 

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
39
40
41
42
43
#include <stdio.h>
 
 
typedef struct student {
 
    union number {
        int nationNum;
        int schoolNum;
    };    
 
    char name[10];
    char phone[20];
}STUDENT;
 
int main(void) {
 
    STUDENT s1;
    int choice;
 
    printf("주민등록번호, 학번 중 무엇을 사용하시겠습니까?(주민등록번호: 1, 학번: 2)");
    scanf("%d"&choice);
 
    switch (choice)
    {
    
    case 1:
        printf("주민등록번호 앞자리, 이름, 전화번호를 입력하세요: ");
        scanf("%d %s %s"&s1.nationNum, s1.name, s1.phone);
 
        printf("%d\n%s\n%s", s1.nationNum, s1.name, s1.phone);
        break;
 
    case 2:
        printf("학번, 이름, 전화번호를 입력하세요: ");
        scanf("%d %s %s"&s1.schoolNum, s1.name, s1.phone);
 
        printf("%d\n%s\n%s", s1.schoolNum, s1.name, s1.phone);
        break;
    }
 
    return 0;
    
}
cs

 

5.

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
#include <stdio.h>
 
typedef struct number {
    double integer;
    double sosu;
}NUM;
 
int main(void) {
 
    NUM n1, n2;
 
    printf("첫번째 복소수를 입력하시오(a, b):" );
    scanf("%lf %lf"&n1.integer, &n1.sosu);
    printf("두번째 복소수를 입력하시오(a, b):");
    scanf("%lf %lf"&n2.integer, &n2.sosu);
 
    double i_result, s_result;
 
    i_result = n1.integer + n2.integer;
    s_result = n1.sosu + n2.sosu;
 
    printf("%.1lf + %.1lfi", i_result, s_result);
 
    return 0;
}
cs

 

 

6.

 

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
39
40
41
#include <stdio.h>
 
enum user {s, r, p};
 
int main(void) {
 
    enum user u, c;
 
    printf("가위(0) 바위(1) 보(2)를 입력하세요: ");
    scanf("%d"&u);
 
    c = rand() % 3;
 
    switch (u) {
    case s:
        if (u == c)
            printf("비겼습니다.");
        else if (c == r)
            printf("졌습니다.");
        else
            printf("이겼습니다.");
        break;
    case r:
        if (u == c)
            printf("비겼습니다.");
        else if (c == p)
            printf("졌습니다.");
        else
            printf("이겼습니다.");
        break;
    case p:
        if (u == c)
            printf("비겼습니다.");
        else if (c == s)
            printf("졌습니다.");
        else
            printf("이겼습니다.");
        break;
    }
    return 0;
}
cs