废话不多说,直接上代码
// ConsoleApplication1.cpp: 定义控制台应用程序的入口点。
// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将
// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
//#include <SDKDDKVer.h>
#include "stdafx.h"
#include <stdlib.h>
#include "stdafx.h"
struct Student {
char name[20];
float score;
};
int main() {
{
do
{
int a, b, c;
printf("请输入A:");
scanf_s("%d", &a);
printf("请输入B:");
scanf_s("%d", &b);
printf("请输入C:");
scanf_s("%d", &c);
int i, j;
struct Student xp[3] = { { "A",a },{ "B",b },{ "C",c } };
struct Student temp;
for (i = 0; i<3; i++)
{
for (j = 0; j <= i; j++)
{
if (xp[j].score>xp[i].score)
{
temp = xp[i];
xp[i] = xp[j];
xp[j] = temp;
}
}
}
for (i = 0; i<3; i++)
printf("%s-->", xp[i].name);
printf("\n\n");
} while (true);
return 0;
}
}
和普通的排序不一样,这里是输入三个数字, 然后输出名字.所以我们用到了结构体,通过结构体数组来进行排序,最后输出数值对应的名字.