C语言的一道改错题,望大神指点!晚上就要考试啦
程序D1063.c的功能是:输入数组的长度n(n<=20)以及每个数组元素,排序后输出#include<stdio.h>voidchange(int*p1,int*p2)...
程序D1063.c的功能是:输入数组的长度n(n<=20)以及每个数组元素,排序后输出
#include <stdio.h>
void change(int *p1, int *p2);
/*********Found************/
______sort(int *pArr, int n);
int main( )
{
int arr[20], *pa, i, n;
printf("Please input the number n = ");
scanf("%d", &n);
printf("Please input the array elements : ");
for (i=0, pa=arr; i<n; i++)
{
scanf("%d", pa++);
}
/*********Found************/
___________________________;
printf("\n output : \n");
for (i=0; i<n; i++)
{
printf("%d ", *(pa + i));
}
printf("\n");
return 0;
}
void change(int *p1, int *p2)
{
int tmp;
tmp = *p1;
*p1 = *p2;
*p2 = tmp;
}
/*********Found************/
______sort(int *pArr, int n)
{
int i, *pa;
for (i=n-1; i>0; i--)
{
for (pa=pArr; pa<pArr+i; pa++)
{
if (*pa > *(pa+1))
{
change(pa, pa+1);
}
}
}
/*********Found************/
___________________________;
} 展开
#include <stdio.h>
void change(int *p1, int *p2);
/*********Found************/
______sort(int *pArr, int n);
int main( )
{
int arr[20], *pa, i, n;
printf("Please input the number n = ");
scanf("%d", &n);
printf("Please input the array elements : ");
for (i=0, pa=arr; i<n; i++)
{
scanf("%d", pa++);
}
/*********Found************/
___________________________;
printf("\n output : \n");
for (i=0; i<n; i++)
{
printf("%d ", *(pa + i));
}
printf("\n");
return 0;
}
void change(int *p1, int *p2)
{
int tmp;
tmp = *p1;
*p1 = *p2;
*p2 = tmp;
}
/*********Found************/
______sort(int *pArr, int n)
{
int i, *pa;
for (i=n-1; i>0; i--)
{
for (pa=pArr; pa<pArr+i; pa++)
{
if (*pa > *(pa+1))
{
change(pa, pa+1);
}
}
}
/*********Found************/
___________________________;
} 展开
1个回答
展开全部
上机运行一下吧
#include <stdio.h>
void change(int *p1, int *p2);
/*********Found************/
//______sort(int *pArr, int n);
int *sort(int *pArr, int n);
int main( )
{
int arr[20], *pa, i, n;
printf("Please input the number n = ");
scanf("%d", &n);
printf("Please input the array elements : ");
for (i=0, pa=arr; i<n; i++)
{
scanf("%d", pa++);
}
/*********Found************/
//___________________________;
pa=sort(arr,n);
printf("\n output : \n");
for (i=0; i<n; i++)
{
printf("%d ", *(pa + i));
}
printf("\n");
return 0;
}
void change(int *p1, int *p2)
{
int tmp;
tmp = *p1;
*p1 = *p2;
*p2 = tmp;
}
/*********Found************/
//______sort(int *pArr, int n)
int *sort(int *pArr, int n)
{
int i, *pa;
for (i=n-1; i>0; i--)
{
for (pa=pArr; pa<pArr+i; pa++)
{
if (*pa > *(pa+1))
{
change(pa, pa+1);
}
}
}
/*********Found************/
//___________________________;
return pArr;
}
更多追问追答
追答
地址重发一下,电脑上看不到
追问
可以看我的提问吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询