Write a program in C to insert New value in the array (sorted list)

 

#include<stdio.h>

int main()

{

int n, p, i, len=9;

int arr[15]={12, 23, 45, 66, 69, 87, 95, 10, 106};

printf(“n  The array::”);

for(i=0; i<len; i++){

printf(”  %d  “,arr[i]);

}

printf(“nEnter the number you want to insert in array: “);

scanf(“%d”,&n);

printf(“Enter the position in which you wanna insert the number: “);

scanf(“%d”, &p);

–p;

for(i=len; i>=p; i–){

arr[i+1]=arr[i];

}

arr[p]=n;

++len;

printf(“nThe array after inserting the number:n”);

for(i=0; i<len; i++){

printf(”  %d  “,arr[i]);

}

return 0;

}

Leave a Reply

You cannot copy content of this page