...
C언어 학생 답안 및 석차 출력
배열을 이용한 학생 답안 및 점수 출력을 간단하게나마 구현해 보았다.
#include <string.h>
#include <stdio.h>
#define N 10
#define STUDENT 10
/*
객관식 10문제가 있고 정답은 1,3,2,3,4,2,3,1,4,2 다
배열에 10명의 학생의 답안을 적고 해답을 가려내고 석차를 내시오
*/
int main(void)
{
int paper[STUDENT][N]={{1,3,2,3,4,2,3,1,4,3},{1,2,2,2,4,2,3,1,4,2},{4,3,2,3,4,2,3,1,4,2},{1,3,2,2,4,3,3,4,4,2},
{1,3,2,3,4,2,3,3,4,1},{1,1,2,4,4,3,3,2,4,3},{1,3,2,3,4,2,3,1,4,2},{1,3,2,3,3,2,3,1,4,2},
{2,3,3,3,3,2,4,1,4,2},{3,4,4,2,4,1,2,1,4,2}};
int answer[N]={1,3,2,3,4,2,3,1,4,2};//정답
int score_student[N]={0},num_student[N]={0,1,2,3,4,5,6,7,8,9},grade_student[N]={0};
int i,j,score,tmp,switch0;
puts("\n ■문항별 채점 결과■");
puts("┌──────────────────────────┐");
puts("│문항 0 1 2 3 4 5 6 7 8 9 점수 │");
puts("├──────────────────────────┤");
for(i=0;i<STUDENT;i++)
{
score = 0;
printf("│%2d번 ", i+1);
for(j=0;j<N;j++)
{
if(paper[i][j] == answer[j])
{
printf("O ");
score++;
}
else
{
printf("X ");
}
}
score_student[i]=score;
printf("%2d점 │\n", score);
}
puts("└──────────────────────────┘");
puts("\n\n ■정렬 및 석차■");
puts(" ┌─────────┐");
puts(" │번호 점수 석차 │");
puts(" ├─────────┤");
for(i=0;i<N-1;i++)
{
for(j=0;j<N-1-i;j++)
{
if(score_student[j]>score_student[j+1])
{
tmp = score_student[j];
score_student[j] = score_student[j+1];
score_student[j+1] = tmp;
tmp = num_student[j];
num_student[j] = num_student[j+1];
num_student[j+1] = tmp;
}
}
}
for(i=0;i<N;i++)
{
for(j=i;j<N;j++)
{
if(score_student[i] < score_student[j])
{
grade_student[i]++;
}
}
}
for(i=N-1;i>=0;i--)
{
printf(" │%2d번 %2d점 %2d등 │\n", num_student[i]+1,score_student[i],grade_student[i]+1);
}
puts(" └─────────┘");
//puts("├──────────────────────────┤");
}
인용한 부분에 있어 만일 누락된 출처가 있다면 반드시 알려주시면 감사하겠습니다
이 글이 좋으셨다면 구독 & 좋아요
여러분의 구독과 좋아요는
저자에게 큰 힘이 됩니다.