Several integers are placed in the array from small to large, and the user enters a number into the array, and the number in the array is still sorted from small to large. Ask the big guy to see what's wrong with this program?
#include <stdio.h>
#include <stdlib.h>
void Inserer (int *s,int x,int *n) {
int i,j=0;
while (J<*n && s[j]<x) j + +;
For (i= (*n) -1;i>=j;i--) s[i+1]=s[i];
S[i]=x;
*n= (*n) +1;
}
void output (int *s,int *n) {
int i; for (i=0;i<*n;i++) printf ("%d", s[i]);
printf ("\ n");
}
int main (void) {
int s[10]={1,6,7,10,14,18,22,29,36,47},x;
int n=10; printf ("Entrez un chiffre:");
scanf ("%d", &x);
printf ("Le tableau Precedent:");
Output (s,&n);
Inserer (S,x,&n)
printf ("Le nouveau tableau:");
Output (s,&n);
return exit_success;
}
If you enter 12, the result of the operation:
Entrez un chiffre:12
Le Tableau precedent:1 6 7 10 14 18 22 29 36 47
Le Nouveau tableau:1 6 7 12 14 14 18 22 29 36 48 12 9900928 0 4199400 0 0 0 46 0 4225568 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
--------------------------------http://huyunsong1314.blog.163.com/
Arrays are still in order. Insert a number in an ordered array