Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

EXPERIMENT 1

AIM: TO PERFROM INSERTION, SEARCHING & DELETION


IN 1D ARRAY.

CODE:

#include<stdio.h>
int A[50],size,ele,pos;

void create (int A[],int size);


void insert(int A[],int ele,int pos);
void del(int A[],int ele,int pos);
void search(int A[], int ele);

void main(){
int c,r;
do{
printf("1. ARRAY CREATION \n");
printf("2. INSERTION \n");
printf("3. SEARCHING \n");
printf("4. DELETION \n");
printf("Enter Sno as response : ");

scanf("%d",&c);
switch(c){
case 1:printf("\nEnter size of array : ");
scanf("%d",&size);

create(A,size);
break;

case 2:printf("\nEnter element to be inserted : ");


scanf("%d",&ele);
printf("Enter position : ");
scanf("%d",&pos);
ABHISHEK SHUKLA 1609110005
insert(A,ele,pos);
break;

case 3:printf("\nEnter element to be searched : ");


scanf("%d",&ele);

search(A,ele);
break;

case 4:printf("\nEnter element to be deleted : ");


scanf("%d",&ele);
printf("Enter position : ");
scanf("%d",&pos);

del(A,ele,pos);
break;

default:printf("\nENTER CORRRECT RESPONSE ! ");}

printf("\n \nPress '1' to continue and '0' to exit:");


scanf("%d",&r);}
while(r!=0);
getch();
}
//----------------------------------------------------

void create(int A[],int size){


int i;

printf("Enter array elements : ");


for (i=0;i<size;i++)
scanf("%d",&A[i]);
}
//----------------------------------------------------

void insert(int A[],int ele,int pos){


ABHISHEK SHUKLA 1609110005
int i;

for (i=size;i>pos-1;i--)
A[i]=A[i-1];

A[i]=ele;
size++;
for (i=0;i<size;i++)
printf("%d ",A[i]);
}
//----------------------------------------------------

void search(int A[], int ele){


int i,flag;
flag=0;

for (i=0;i<size;i++){
if (ele==A[i]){
flag=1;
break;} }

if (flag==1)
printf("\nElement found at %d location",i+1);
else
printf("\nElement not found");
}
//----------------------------------------------------

void del(int A[],int ele,int pos){


int i;

for(i=pos-1;i<size-1;i++)
A[i]=A[i+1];

size--;
for (i=0;i<size;i++)
printf("%d ",A[i]);
ABHISHEK SHUKLA 1609110005
OUTPUTS:

ABHISHEK SHUKLA 1609110005

You might also like