我正在尝试为数组创建排序函数。我按升序使用选择排序,但我不知道我的"output“函数有什么问题,我知道在堆栈溢出时也有人问过类似的问题,但答案对我帮助不大。Dev token上的错误显示为"Error a function-definition is not allowed here like '{‘C++“.
#include<stdio.h>
#include<stdlib.h>
void sort(int arr[], int n)
{
int minindex;
int t,i,j;
for(i=0;i<n-1;i++)
{
minindex=i;
for(j=i+1; j<n; j++)
{
if(arr[minindex]>arr[j])
minindex=j;
}
if(minindex>1)
{
int t=arr[minindex];
arr[minindex]=arr[i];
arr[i]=t;
}
}
void output(int arr[], int n)
{
for(int i=0; i<n; i++)
{
printf("%5d", arr[i]);
}
}
int main()
{
int arr[]={1,3,5,7,9,2,4,6,8,0};
int*a=(int*)calloc(10,sizeof(int));
sort(a,10);
ouput(a,10);
getchar(); getchar();
return 0;
}发布于 2018-10-23 01:07:47

我很想给你代码,但我相信你可以自己编辑。-输出
0 1 2 3 4 5 6 7 8 9
Process returned 0 (0x0) execution time : -0.000 s
Press any key to continue.https://stackoverflow.com/questions/52932851
复制相似问题