20_10

Write a C program to insert an element / item in the sorted array.

 Source code:

/*Write a C program to insert an element / item in the sorted array.  */


#include<stdio.h>

int main( )

{

  int a[20],n=10,item,i;

    printf("Enter the sorted array: ");

    for(i=0; i<n; i++)

    {

        scanf("%d", &a[i]);

    }

    printf("Enter the item which to be inserted in the array: ");

    scanf("%d", &item);

i = n-1;

    while(item<a[i] && i>=0)

    {

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

           i--;

    }

    a[i+1] = item;

    n++;

printf("ITEM to be inserted:%d\n",item);

printf("After insertion array is:\n");

    for(i=0; i<n; i++)

    {

        printf("%d\n",a[i]);

    }

    return 0;

}

Output:
C program to insert an element or item in the sorted array


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...