3203: 数组做函数参数----排序函数--C语言版
时间限制: 1 Sec 内存限制: 128 MB提交: 253 解决: 151
[提交][状态][讨论版][命题人:smallgyy]
题目描述
定义一个函数来完成对参数数组中元素的排序工作,函数声明如下:
void sort(int array[ ]);//该函数完成对array数组的排序工作
在以下程序的基础上,完成对sort函数的定义,提交时,只提交sort函数的定义即可。
#include <stdio.h>
void sort(int array[ ]);//该函数完成对array数组的排序工作
int main()
{
int a[10];
int i;
for(i=0;i<10;i++) //为数组元素赋值
scanf("%d",&a[i]);
sort(a); //对a数组进行排序
for(i=0;i<10;i++) //输出数组元素
printf("%d ",a[i]);
return 0;
}
void sort(int array[ ]);//该函数完成对array数组的排序工作
在以下程序的基础上,完成对sort函数的定义,提交时,只提交sort函数的定义即可。
#include <stdio.h>
void sort(int array[ ]);//该函数完成对array数组的排序工作
int main()
{
int a[10];
int i;
for(i=0;i<10;i++) //为数组元素赋值
scanf("%d",&a[i]);
sort(a); //对a数组进行排序
for(i=0;i<10;i++) //输出数组元素
printf("%d ",a[i]);
return 0;
}
输入
输入十个为未排序的整数
输出
输出已经排好序的十个整数
样例输入
1 3 5 7 9 0 2 4 6 8
样例输出
0 1 2 3 4 5 6 7 8 9
提示
可以使用任何排序方法
#include <stdio.h>
void sort(int array[ ]);//该函数完成对array数组的排序工作
int main()
{
int a[10];
int i;
for(i=0; i<10; i++) //为数组元素赋值
scanf("%d",&a[i]);
sort(a); //对a数组进行排序
for(i=0; i<10; i++) //输出数组元素
printf("%d ",a[i]);
return 0;
}
void sort(int a[])
{
int i, j, temp;
for(i = 0; i < 9; ++i)
{
for(j = i + 1; j < 10; ++j)
{
if(a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
本题主要练习一下选择排序