C 언어 Example - function4

문제

한 개인의 성적 별포(*)의 가로 막대그래프로 표현하는 프로그램을 작성하자. 막대 그래프의 출력을 두 개의 함수로 수행하도록 하자. 하나는 출력 제목을 출력하는 함수와 다른 하나는 막대그래프를 그리는 함수를 만들어 프로그램을 작성하자

printHeading

반환값 : 없음
인자 : 없음
기능 : '----개인별 점수 막대 그래프----' 출력하고 한줄을 비우도록 출력하는 함수

printHistogram

반환값 : 출력되는 별표(*)의 개수로 int형
인자 : 점수 int형
기능 : 인자로 받은 점수를 10으로 나눈 정수만을 이용하여 이 수만큼 *표를 출력하고, 이 수를 반환하는 함수


실행화면



코드

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
56
57
58
#include<stdio.h>
#include<Windows.h>
 
void printHeading();
int printHistogram(int score);
 
int main(void) {
 
    int person1 = 74;
    int person2 = 42;
    int person3 = 99;
 
    int temp;
    int i;
 
    printHeading();
 
    temp = printHistogram(person1);
    printf("임꺽정 (%d) : ", person1);
    for (i = 0; i < temp; i++) {
        printf("*");
    }
    printf("(%d)\n", temp);
 
    temp = printHistogram(person2);
    printf("홍길동 (%d) : ", person2);
    for (i = 0; i < temp; i++) {
        printf("*");
    }
    printf("(%d)\n", temp);
 
    temp = printHistogram(person3);
    printf("장길산 (%d) : ", person3);
    for (i = 0; i < temp; i++) {
        printf("*");
    }
    printf("(%d)\n", temp);
 
 
    system("pause");
    return 0;
}
 
void printHeading() {
    printf("----개인별 점수 막대 그래프----\n\n");
}
 
int printHistogram(int score) {
     
    /*int temp = score/10;
 
    while (temp) {
        printf("*");
        temp--;
    }*/
 
    return score/10;
}
cs

댓글