Ticker

6/recent/ticker-posts

C Language (Insertion in array)

INSERTION IN ARRAY





C PROGRAM TO INSERT NEW ELEMENT IN ARRAY

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[60];
int size, n, i;
printf("Enter array size:");
scanf("%d",&size);

printf("Enter values in array:\n");
for(i=0; i<size; i++)
{
scanf("%d", a[i]);
}

printf("Enter new value for array:");
scanf("%d",&n);

// Insert new value in array
size ++;
a[size]=n;

// Print array's values along with new value
printf("\nArray's values after insertion\n")
for(i=0; i<size; i++)
{
printf("%d\n", a[i]);
}

getch();
}

----------------------------
         OUTPUT 
----------------------------

Enter array size: 5

Enter values in array:
6
7
3
4
8

Enter new value for array: 12
Array's values after insertion
6
7
3
4
8
12

















HOME

Post a Comment

0 Comments