#include
#include
void fun(int a[], int n);
void main(void)
{
int a[5], i;
for (i=0; i<5; i++)
{
scanf("%d",&a[i]);
}
fun(a, 5);
}
void fun(int a[], int n)
{
int i, j, t;
for (i=0; i
for (j=0; j
if (a[j] > a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
for (i=0; i
printf("%d ", a[i]);
}
printf("\n");
}
int main(int argc, char* argv[])
{
int grade[5];
int i = 0;
//输入成绩
for(i=0;i<5;i++)
cin>>grade[i];
//冒泡排序
int temp;
for (i=1;i<5;i++)
{
for (int j=0;j<5-i;j++)
{
if(grade[j]>grade[j+1])
{
temp=grade[j+1];
grade[j+1]=grade[j];
grade[j]=temp;
}
}
}
//输出成绩
for(i=0;i<5;i++)
cout<
cout<
}
先定义一个int型数组,然后给数组赋值,在接下来用冒泡排序法就OK啦。