current position:Home>C language choice sorting primary questions, the number after the first sorting exchange position becomes 0

C language choice sorting primary questions, the number after the first sorting exchange position becomes 0

2022-02-02 20:24:19 CSDN Q & A

img

img

img

int main(int argc, char *argv[]) {    int a[5],i,m,x,j;    for(i=0;i<5;i++){        scanf("%d",&a[i]);    }    for(j=1;j<5;j++){        m=0;        for(i=0;i<6-j;i++){            if(a[0]<a[i]){
   
   
   
   m=i;}        }          if(m!=i){
   
   
   
   x=a[m];a[m]=a[i];a[i]=x;}    }    for(i=0;i<5;i++){printf("%d ",a[i]);}    return 0;}



Refer to the answer 1:

img

 #include <stdio.h>  void Sort(int *p,int n){    int min,i,j,t;    for(i=0;i<n-1;i++)    {        min=i;        for(j=i+1;j<n;j++)            if(p[min]>p[j])                min=j;        t=p[i];p[i]=p[min];p[min]=t;    }}int main() {    int a[5],j,m,x;    for(j=0;j<5;j++){        scanf("%d",&a[j]);    }       Sort(a,5);     for(j=0;j<5;j++){
   
   
   
   printf("%d ",a[j]);}    return 0;}



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/202202022024182290.html

Random recommended