Insert Element In An Array

Introduction
  • In this blog, I am going to explain about " insert the element in an array" 
Software Requirement
  • Turbo C++ OR C.
Programming
  1. #include < stdio.h >   
  2. int main()  
  3. {  
  4.     int array[100], position, c, n, value;  
  5.     printf("Enter number of elements in array\n");  
  6.     scanf("%d", & n);  
  7.     printf("Enter %d elements\n", n);  
  8.     for (c = 0; c < n; c++) scanf("%d", & array[c]);  
  9.     printf("Enter the location where you wish to insert an element\n");  
  10.     scanf("%d", & position);  
  11.     printf("Enter the value to insert\n");  
  12.     scanf("%d", & value);  
  13.     for (c = n - 1; c >= position - 1; c--) array[c + 1] = array[c];  
  14.     array[position - 1] = value;  
  15.     printf("Resultant array is\n");  
  16.     for (c = 0; c <= n; c++) printf("%d\n", array[c]);  
  17.     return 0;  
  18. }   
Explanation 
  • By the programming, it is clearly understood  how  a user  can insert an element in an array.

    programming
Output

Output
 
Conclusion
  • Thus, the program can be printed and executed successfully.
Ebook Download
View all
Learn
View all