一道C语言编程题,求大神给个答案!!!!!!
1、请编写函数完成整个程序,要求满足以下main函数的调用。intmain(){inta[]={123,145,210,815,44,240,919,310,44,88,...
1、请编写函数完成整个程序,要求满足以下main函数的调用。
int main(){
int a[] = {123,145,210,815,44,240,919,310,44,88,123};
int length = sizeof(a)/sizeof(a[0]);
printf("排序前:\n");
print(a,length);
sort(a,length);
printf("排序后:\n");
print(a,length);
return 0;
} 展开
int main(){
int a[] = {123,145,210,815,44,240,919,310,44,88,123};
int length = sizeof(a)/sizeof(a[0]);
printf("排序前:\n");
print(a,length);
sort(a,length);
printf("排序后:\n");
print(a,length);
return 0;
} 展开
展开全部
#include<stdio.h>
void sort(int a[],int n)
{
int i,j;
int t;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]<a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
}
void print(int a[],int n)
{
int i;
for(i=0;i<n-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[n-1]);
}
int main()
{
int a[] = {123,145,210,815,44,240,919,310,44,88,123};
int length = sizeof(a)/sizeof(a[0]);
printf("排序前:\n");
print(a,length);
sort(a,length);
printf("排序后:\n");
print(a,length);
return 0;
}
void sort(int a[],int n)
{
int i,j;
int t;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]<a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
}
void print(int a[],int n)
{
int i;
for(i=0;i<n-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[n-1]);
}
int main()
{
int a[] = {123,145,210,815,44,240,919,310,44,88,123};
int length = sizeof(a)/sizeof(a[0]);
printf("排序前:\n");
print(a,length);
sort(a,length);
printf("排序后:\n");
print(a,length);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询