0% found this document useful (0 votes)
12 views2 pages

Array

The document provides C code examples for inserting and deleting elements in an array. It outlines the steps for inserting a new element at a specified position and for deleting an element from a given index. The code includes user input for the number of elements and the specific elements to be modified.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Array

The document provides C code examples for inserting and deleting elements in an array. It outlines the steps for inserting a new element at a specified position and for deleting an element from a given index. The code includes user input for the number of elements and the specific elements to be modified.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Ques.

Array: Insertion and Deletion


1. Insertion
#include<stdio.h>
void main()
{
int a[20],m,i,j,k,new_ele;
printf("enter the number of elements:");
scanf("%d",&m);
printf("enter %d elements:",m);
for(k=1;k<=m;k++)
scanf("%d",&a[k]);

printf("enter the element to be inserted:");


scanf("%d",&new_ele);
printf("where %d is to be inserted:",new_ele);
scanf("%d",&j);

i=m;
while(i>=j)
{
a[i+1]=a[i];
i--;
}
a[j]=new_ele;
m=m+1;

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


for(k=1;k<=m;k++)
printf("%d\n",a[k]);
}
a. First
b. Last

2. Deletion:
#include<stdio.h>
void main()
{
int a[20],m,i,j,k,del;
printf("enter the number of elements:");
scanf("%d",&m);
printf("enter %d elements:",m);
for(k=1;k<=m;k++)
scanf("%d",&a[k]);

printf("enter the element to be inserted:");


scanf("%d",&j);

i=j;
while(i<=m-1)
{
a[i]=a[i+1];
i++;
}
m=m-1;

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


for(k=1;k<=m;k++)
printf("%d\n",a[k]);
}

You might also like