1. 구조체 이름이 student 이고 멤버가 아래와 같은 구조체를 선언하시오.
구조체명
student
멤버명
name[10],kor,eng,math,tot,avg
형식
char,int,int,int,int,double
2. 1번에서 선언된 구조체를 이용하여 main( ) 함수에서 구조체 배열 stu[5]를 선언하고 아래 박스의 데이터로 초기화 하시오.
Kim 95 95 90 280 93.4
Park 90 85 90 265 88.4
Lee 95 95 95 285 95.0
Hong 85 85 90 260 86.7
Oh 85 85 85 255 85.0
3. 학생의 이름, 국어, 영어, 수학, 총점, 평균을 출력하는 함수를 작성하시오.
(for 반복문을 사용, 포인터 st와 오프셋 사용)
void Print_Out(struct student* st)
이과제에서
#include < stdio.h >
#define student_stu 5
#include < string.h >
void Print_Out(struct student*st);
struct student
{
char name[10];
int kor,eng,math,tot;
double avg;
};
void Print_Out(struct student*st);
int main(void)
{
struct student stu[5];
strcpy(stu[0].name, "Kim");
stu[0].kor=95;
stu[0].eng=95;
stu[0].math=90;
stu[0].tot=0;
stu[0].avg=0.0;
strcpy(stu[1].name, "Park");
stu[1].kor = 90;
stu[1].eng = 85;
stu[1].math = 90;
stu[1].tot = 0;
stu[1].avg = 0.0;
strcpy(stu[2].name, "Lee");
stu[2].kor = 95;
stu[2].eng = 95;
stu[2].math = 95;
stu[2].tot = 0;
stu[2].avg = 0.0;
strcpy(stu[3].name, "Hong");
stu[3].kor = 85;
stu[3].eng = 85;
stu[3].math = 90;
stu[3].tot = 0;
stu[3].avg = 0.0;
strcpy(stu[4].name, "Oh");
stu[4].kor = 85;
stu[4].eng = 85;
stu[4].math = 85;
stu[4].tot = 0;
stu[4].avg = 0.0;
return 0;
}
void Print_Out(struct student*st)
{
int i;
for(i=0;i<5;i++)
{
st[i].tot=st[i].kor+st[i].eng+st[i].math;
st[i].avg=st[i].tot/3;
printf("%s %d %d %d %d %f\n",st[i].name,st[i].kor,st[i].eng,st[i].math,st[i].tot,st[i].avg);
}
}
여기까지했는데 글씨한톨 출력이 안되네요. 왜그런거죠..??ㅠㅠ
함수같은걸호출하나?
main 밑에 Print_Out을 넣으세요 ㅋㅋ
main(void)아래에 void Print_Out(struct student *st를 넣으라는말씀이신가용??
ㄴㄴ main 맨 밑에줄에 Print_Out(stu);염 ㅋ