Arrays are still in order. Insert a number in an ordered array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.