C Program to Insert an Element into Array
Previously we learned to insert elements into empty arrays in the order. But how can we insert a particular element into a desired position of an array? For that we need to initialize a variable 'key' which we may use to indicate the position of PC in program. Let's have a look into the program. //Program #include <stdio.h> void main() { int array[10]; int i, j, n, m, temp, key, pos; printf( "Enter how many elements \n "); scanf( "%d" , &n); printf( "Enter the elements \n "); for (i = 0; i < n; i++) { scanf( "%d" , &array[i]); } printf( "Input array elements are \n "); for (i = 0; i < n; i++) { printf( "%d\n ", array[i]); } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (array[i] > array[j]) { temp = array[i]; array[i] = array[j]; array[j] = temp; } } } printf( "Sorted list is \n "); for (i = 0; i &