Home Basic Loop Array string Function Pointer Contact STUDY

# AHF    C    PROGRAM    SOLVING

### Array_insertion

```
// AHF C PROGRAM SOLVING

//solving here 2_D   ARRAY 	programming problem

#include<stdio.h>
#include<math.h>
#define pf printf

int main()
{
int i,n,pos,num,arr[100];

pf("Enter the number of the element int the array: ");
scanf("%d",&n);

//taking array element
pf("\nEnter the element of the array: \n");
for(i=0;i < n;i++)
{
pf("\nArray [%d] = ", i);
scanf("%d",&arr[i]);
}

//taking insertion number or value
pf("\nEnter the insertion number: ");
scanf("%d",&num);

//taking insertion position
pf("\nEnter the position at which the number has to be added: ");
scanf("%d",&pos);

//the given number is inserting
for(i=n;i>=pos;i--)
arr[i+1]=arr[i];

//increment new array size
n++;

//inserting number or value is assigning in the array
arr[pos]=num;

//printing new inserted array
pf("\The array after insertion %d is: ",num);

for(i=0;i < n;i++)
pf("\nArray[%d] = %d",i,arr[i]);

return 0;
}

```
OUTPUT: