Pointers to remain in line

Papers described
using the pointer method, is inserted into an integer number of columns arranged in small to large, so that after insertion remains ascending order.
Input
Input consists of two lines:
the first line is an integer of 10 ascending sorted, separated by a space between two adjacent numbers.
The second line is the need to insert a new integer m.
Output
outputs a digital insertion, sorted in ascending integers 11, between adjacent two numbers separated by a space.
Input Example
579,112,528,303,132 33 is
. 7
example output
5,779,112,528,303,132 33 is
the range of data
input and output ranges are integers int

#include <stdio.h>

int main() 
{ 
   int s1[12],s2[12],i,j,m,loc,*p; 
   for(i=0;i<10;i++)
   scanf("%d",&s1[i]);
   p=&m;
   scanf("%d",&*p);
   for(i=0;i<10;i++)
   {
   	if(*p>=s1[i]&&*p<=s1[i+1])
   	loc=i+1;
   	else if(*p>s1[9]) 
   	loc=10;
   	else if(*p<s1[0])
   	loc=0;
   }
   for(i=0;i<loc;i++)
   {
   	s2[i]=s1[i];
   }
   s2[loc]=*p;
   for(i=loc+1,j=loc;i<11;i++,j++)
   {
   	s2[i]=s1[j];
   }
   for(i=0;i<11;i++)
   printf("%d ",s2[i]);
   return 0;
} 

Guess you like

Origin blog.csdn.net/Lhw_666/article/details/91415365