Back - C Language Notes By Vivek Sir email: vivekdubey22@gmail.com (w) 9826424484

C Language Video

WAP to insert an element in array lit.

#include <stdio.h>

void main() {

   int LA[] = {21,13,35,57,48};

   int item = 99, k = 3, n = 5;

   int i = 0, j = n;

  

   printf("The original array elements are :\n");

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

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

 

   n = n + 1;

   while( j >= k) {

      LA[j+1] = LA[j];

      j = j - 1;

   }

 

   LA[k] = item;

   printf("The array elements after insertion :\n");

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

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

   }

}

Output

The original array elements are :                                                                                                     

LA[0] = 21                                                                                                                             

LA[1] = 13                                                                                                                            

LA[2] = 35                                                                                                                             

LA[3] = 57                                                                                                                            

LA[4] = 48                                                                                                                            

The array elements after insertion :                                                                                                   

LA[0] = 21                                                                                                                            

LA[1] = 13                                                                                                                             

LA[2] = 35                                                                                                                            

LA[3] = 99                                                                                                                             

LA[4] = 57                                                                                                                            

LA[5] = 48

Back - C Language Notes By Vivek Sir email: vivekdubey22@gmail.com (w) 9826424484

C Language Video