[分享]这是我刚做的结构体程序
#include<iostream.h>
struct stu
{
int no;
char name[8];
double result;
};
void compared(stu a[8])
{
int i;
for(i=0;i<7;i++)
{
for(int j=0;j<7-i;j++)
{
if(a[j].result>a[j+1].result)
{
stu temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"*******************成绩如下:******************"<<endl<<endl;
for(i=0;i<8;i++)
cout<<"第"<<i+1<<"名: "<<a[i].no<<" "<<a[i].name<<" "<<a[i].result<<endl;
}
void main()
{
stu infor[8]={{1,"李建华",13.6},{2,"张岩",14.8},{10,"胡晓强",12.0},
{13,"马万驰",12.9},{23,"米星雨",13.4},{30,"余秋实",14.1},
{55,"李枫",13.5},{89,"苏良川",12.6}};
compared(infor);
}
请大家指点一下!