minseo-jung / study-c

0 stars 0 forks source link

성적 관리 프로그램 만들기 #30

Open minseo-jung opened 5 years ago

minseo-jung commented 5 years ago
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void p16_1_2()
{
    int sub_total=0;
    int total=0;
    int i, j;
    int score[5][5];
    score[4][4] = 0;
    for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 4; j++)
        {
            printf("P%d 학생의 S%d 과목의 점수\n", i + 1, j + 1);
            scanf("%d", &score[i][j]);
            total += score[i][j];
        }
        score[i][4] = total;
        total = 0;
    }
    for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 4; j++)
        {
            sub_total += score[j][i];
        }
        score[4][i] = sub_total;
        sub_total = 0;
    }
    for (i = 0; i < 5; i++)
    {
        for (j = 0; j < 5; j++)
        {
            printf("%d\t",score[i][j] );

        }
        printf("\n");
    }

    return;
}
minseo-jung commented 5 years ago

성적프로그램에 학생의 이름이나 과목도 입력받아서 배열을 넣을 수 있을까요? 제가 알기로는 문자열을 입력받을 때는 문자열에 있는 문자의 개수만큼 그 칸을 잡기 때문에 사람의 이름 철자 수가 3글자 2글자 4글자 이런식으로 다르다면 문제가 생길것 같은데 이런걸 해결할 방법이 있을까요?

wonny25 commented 5 years ago

좋은 방법은 아닌데 software적으로 직접 싱크맞춰주는 방식도 있어 아래처럼 학생이름, 과목 3개, 점수 3개 형태로 해서 index간 잘 맞춰서 입력받고, 출력해주면 될거야. char name[5]; char class[5][3]; int score[5][3];