반응형
구조체 'student'로 3명의 총점 및 평균을 계산하는 성적 처리 프로그램 구현하기
#include<stdio.h>
struct student{
int kor, eng, math, tot;
double avg;
};
int main(){
// 선언문
struct student stu[3]; // 구조체 student의 변수 stu[] 선언
// 입력문, 처리문
for(int i = 0; i < 3; ++i){
printf("[ student %d ] 입력\n", i + 1);
printf("국어 : ");
scanf("%d", &stu[i].kor);
printf("영어 : ");
scanf("%d", &stu[i].eng);
printf("수학 : ");
scanf("%d", &stu[i].math);
stu[i].tot = stu[i].kor + stu[i].eng + stu[i].math;
stu[i].avg = stu[i].tot / 3.;
}
printf("\n");
// 출력문
for(int i = 0; i < 3; ++i){
printf("student[%d] 총점 : %d\n", i + 1, stu[i].tot);
printf("student[%d] 평균 : %.2lf\n\n", i + 1, stu[i].avg);
}
return 0;
}
반응형
'C' 카테고리의 다른 글
[C언어] 실습: 입력받은 숫자가 배열에 저장되어 있는지 확인하기 (0) | 2021.05.23 |
---|---|
[C언어] 실습: 이름을 검색하여 해당하는 연락처 출력하기 (구조체) (0) | 2021.05.22 |
[C언어] 구조체 객체 복사 (0) | 2021.05.20 |
[C언어] 실습: 구조체 'car'로 자동차, 속도, 연료 상태 출력하기 (0) | 2021.05.19 |
[C언어] 실습: 구조체 'book'으로 책이름, 저자, 가격 출력하기 (0) | 2021.05.17 |