728x90
#include<stdio.h>
void JR(struct student st[]);
struct student
{
int no;
char name[50];
int kor,eng,mat,sum;
float ave;
char hak;
};
void main()
{
struct student st[5]={{1,"김경민",89,75,70},{2,"노순희",67,56,80},{3,"민은희",90,100,89},{4,"이은하",75,86,96},{5,"황은영",90,89,79}};
for(int i=0;i<5;i++)
{
/*printf("입력 : ");
scanf("%d %s %d %d %d",&st[i].no,st[i].name,&st[i].kor,&st[i].eng,&st[i].mat);*/
st[i].sum=st[i].eng+st[i].kor+st[i].mat;
st[i].ave=st[i].sum/3;
if(st[i].ave>=90)
st[i].hak='A';
else if(st[i].ave>=80)
st[i].hak='B';
else if(st[i].ave>=70)
st[i].hak='C';
else if(st[i].ave>=60)
st[i].hak='D';
else
st[i].hak='F';
}
JR(st);
printf("번호 이름 국어 영어 수학 총점 평균 학점\n");
for(i=0;i<5;i++)
printf("%d\t%s\t%d\t%d\t%d\t%d\t%.1f\t%c\n",st[i].no,st[i].name,st[i].kor,st[i].eng,st[i].mat,st[i].sum,st[i].ave,st[i].hak);
}
void JR(struct student st[])
{
struct student temp;
for(int i=0;i<5;i++)
{
for(int j=0;j<i;j++)
{
if(st[i].sum>st[j].sum)
{
temp=st[i];
st[i]=st[j];
st[j]=temp;
}
}
}
}'it > programming' 카테고리의 다른 글
| [c++] 포인터 검색 (0) | 2012.11.05 |
|---|---|
| [c++] 구조체 예제 (0) | 2012.10.22 |
| [C++] string.h 헤더파일의 strcat함수 구현하기 (0) | 2012.09.26 |