C Programming
Computer Programming

Program in C to insert a number in an array that is already stored in ascending order



Write a Program in c to insert a number in an array that is already stored in ascending order

\* C Program to to insert a number in an array that is already stored in ascending order *\

# include < stdio.h >
int   main( )
{

int   a[20], i, n, ele, pos  ;
printf(" Enter the Numbers of elements: ") ;
scanf("%d ", & n) ;
printf("\n Enter the element of araay in Assending Order : \n") ;
for (  i = 1 ; i < = n ; i++ )
scanf("%d ", & a[i]) ;
printf("\n Array enter by user are :\n") ;
for (  i = 1 ; i < = n ; i++ )
printf("%d \t", a[i]) ;

printf("\n Enter the element you want to insert :") ;
scanf("%d ", & ele) ;

for (  i = n ; i > 0 ; i-- )
{

if (  a[i] >= ele  )
{

a[i+1] = a[i] ;
pos = i ;

}

}
a[pos] = ele ;
printf("\n Array After Inserting element :\n") ;
for (  i = 1 ; i < = n+1 ; i++ )
pcanf("%d \t", a[i]) ;
return ( 0 ) ;

}

Output of Program :

Output of Program in C to insert a number in an array that is already stored in ascending order