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

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

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

 

 

 

1.

 

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
#include <stdio.h>
 
int main(void) {
    
    char name[30];
    int age;
    int money;
 
    FILE *fp = NULL;
 
    fp = fopen("emplyee.txt""w");
 
    if (fp == NULL) {
        printf("파일을 열 수 없습니다.");
        exit(1);
    }
 
    printf("직원 이름: ");
    scanf("%s", name);
    fprintf(fp, "직원 이름: %s\n", name);
 
    printf("나이: ");
    scanf("%d"&age);
    fprintf(fp, "나이: %d\n", age);
 
    printf("월급: ");
    scanf("%d"&money);
    fprintf(fp, "월급: %d\n", money);
 
    fclose(fp);
 
    return 0;
}
cs

 

2.

 

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
#include <stdio.h>
 
int main(void) {
 
    int i, num, sum = 0, count = 0;
    double average;
    char c;
 
    FILE* fp = NULL;
 
    fp = fopen("read.txt""r");
 
    if (fp == NULL) {
        printf("파일을 열 수 없습니다.");
        exit(1);
    }
 
    while (fscanf(fp, "%d"&num) != EOF) {
        sum += num;
        count++;
    }
 
    average = (double)sum / count;
 
    printf("정수들의 개수: %d\n", count);
    printf("정수들의 합계: %d\n", sum);
    printf("정수들의 평균: %.2lf\n", average);
 
    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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
 
int main(void) {
    
    char file1[100], file2[100];
    
    printf("첫번째 파일 이름: ");
    scanf("%s", file1);
    printf("두번째 파일 이름: ");
    scanf("%s", file2);
    
    FILE* fp1, * fp2;
 
    fp1 = fopen(file1, "r");
 
    if (fp1 == NULL) {
        printf("파일 %s를 열 수 없습니다.", file1);
        exit(1);
    }
 
    fp2 = fopen(file2, "r");
 
    if (fp2 == NULL) {
        printf("파일 %s를 열 수 없습니다.", file2);
        exit(1);
    }
 
    int c1, c2;
 
    while (1) {
 
        c1 = fgetc(fp1);
        c2 = fgetc(fp2);
        
        if (c1 != c2) {
            printf("두 파일은 서로 다릅니다.");
            
            fclose(fp1);
            fclose(fp2);
 
            return 0;
        }
 
        if (c1 == EOF && c2 == EOF)
            break;
    }
 
    
    printf("두 파일은 서로 같습니다.");
 
    fclose(fp1);
    fclose(fp2);
 
    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
#include <stdio.h>
 
int main(void) {
 
    char file[100];
    char line[1000];
    int count = 1;
 
    printf("파일 이름을 입력하시오: ");
    scanf("%s", file);
 
    FILE* fp = NULL;
 
    fp = fopen(file, "r");
 
    while (1) {
        char* p = fgets(line, 1000, fp);
        if (p == NULL)
            break;
        printf("%d %s", count, p);
        count++;
    }
 
    fclose(fp);
 
    return 0;
}
cs

 

9.

 

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
#include <stdio.h>
 
int main(void) {
 
    char file[100];
    char line[1000];
    int count = 1;
 
    printf("첫번째 파일 이름: ");
    scanf("%s", file);
 
    FILE* fp = NULL;
 
    if ((fp = fopen(file, "r")) == NULL) {
        printf("파일 %s를 열 수 없습니다.", file);
        exit(1);
    }
 
    while (1) {
        char* p = fgets(line, 1000, fp);
        if (p == NULL)
            break;
        if (count % 20 == 0)
            getch();
        printf("%d: %s", count, p);
        count++;
    }
 
    fclose(fp);
 
    return 0;
}
cs

 

제가만든 게임입니다! 도움이 되셨다면 평가 한번 부탁드립니다~

https://play.google.com/store/apps/details?id=com.attitudeproblem&hl=en_CA&gl=

 

교관님 몰래 춤추기 – Apps on Google Play

Avoid the instructor's eyes and dance! Please have fun while watching the instructor's fakes. Raise your stats and items to challenge the higher score!

play.google.com