C_C++

(C언어) 성적처리: 구조체 배열 사용

고니자니 2022. 11. 8. 17:03
반응형

[문제] 구조체 배열을 사용해서 이름, 국어, 영어, 수학 점수를 저장하고

평균, 전체 평균을 구하여 출력하는 프로그램을 작성하시오,

 

//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

struct  student {
	char name[10];
	int kor, eng, mat;
};

int main()
{
	struct student st[5] = {
		{ "홍길동", 100, 100, 100},
		{ "이기자", 90, 95, 85},
		{ "오만원", 80, 85, 80},
		{ "홍길남", 92, 93, 94},
		{ "사오정", 100, 88, 78}
	};
	int i, tot, ttot = 0;

	printf("\n이름	\t국어 영어 수학    평균\n");
	printf("--------------------------------------\n");
	for (i = 0; i < 5; i++)
	{
		tot = st[i].kor + st[i].eng + st[i].mat;
		ttot += tot;
		printf("%s\t\t %3d  %3d  %3d  %6.2f\n",
			st[i].name, st[i].kor, st[i].eng, st[i].mat, (float)tot / 3);
	}
	printf("--------------------------------------\n");
	printf("전체 평균 : %.2f\n", (float)ttot / 15);
	return 0;
}

 

 

 

728x90
반응형