current position:Home>I hope to output the maximum, minimum and sub maximum values through sorting, but I don't know why I can't output them

I hope to output the maximum, minimum and sub maximum values through sorting, but I don't know why I can't output them

2022-02-03 01:59:44 CSDN Q & A

#include <stdio.h>
int main()
{
void sort(int x[],int n);
int i,*p,a[10];
p=a;
printf("enter 10 numbers:\n");
for(i=0; i<10; i++);
scanf("%d",p++);
p=a;
sort(p,10);
for(p=a,i=0; i<10; i++,p++)
{
printf("%d ",*p);
}
printf("the maximum is %d\nthe minimum is %d\nthe second maximum is %d\n",*(p+0),*(p+1),*(p+9));
return 0;
}
void sort(int x[],int n)
{
int i,j,k,t;
for(i=0; i<n-1; i++)
{
k=i;
for(j=i+1; j<n; j++)
if(x[j]>x[k])k=j;
if(k!=i)
{
t=x[i];
x[i]=x[k];
x[k]=t;
}
}
}




Refer to the answer 1:
#include <stdio.h>int main(){    void sort(int x[], int n);    int i, * p, a[10];    p = a;    printf("enter 10 numbers:\n");    for (i = 0; i < 10; i++)        scanf("%d", p++);    p = a;    sort(a, 10);    for (i = 0; i < 10; i++)    {        printf("%d ", p[i]);    }    printf("the maximum is %d\nthe minimum is %d\nthe second maximum is %d\n", *(p + 0), *(p + 1), *(p + 9));    return 0;}void sort(int x[], int n){    int i, j, k, t;    for (i = 0; i < n - 1; i++)    {        k = i;        for (j = i + 1; j < n; j++)            if (x[j] > x[k])k = j;        if (k != i)        {            t = x[i];            x[i] = x[k];            x[k] = t;        }    }}



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030159430597.html

Random recommended