0% found this document useful (0 votes)
19 views5 pages

Dsu 1

DSA program for searching

Uploaded by

atharvwagh81
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Dsu 1

DSA program for searching

Uploaded by

atharvwagh81
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Name: Atharva wagh EnrollmentNo: 23111590391 Subject:

DSU

AIM: Write a ‘C’ program to perform following Operations on Array: Create,


Insert, Delete, Display.
Program:
#include <stdio.h>
#include <stdlib.h>

int a[20], n;

void create() {
int i;
printf("Enter the size of an array: ");
scanf("%d", &n);
printf("Enter the elements: ");
for(i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
return;
}

void insert() {
int i, ele, pos;
printf("Enter the element to be inserted: ");
scanf("%d", &ele);
printf("Enter the position at which you want to insert the element: ");
scanf("%d", &pos);
for(i = n-1; i >= pos-1; i--) {
a[i+1] = a[i];
}
a[pos-1] = ele;
n++;
}

void delet() {
int pos, i;
printf("Enter the position from which you want to delete: ");
scanf("%d", &pos);
for(i = pos-1; i < n-1; i++) {
a[i] = a[i+1];
}
n--;
}

void display() {
int i;
printf("Entered elements are: ");
for(i = 0; i < n; i++) {
printf("\t%d", a[i]);
}
printf("\n");
return;
}

int main() {
int choice;
while(1) {
printf("\n-----------------------MENU-----------------------");
printf("\n1. Create \n2. Insert \n3. Delete \n4. Display \n5. Exit");
printf("\n----------------------------------------------------");
printf("\n\n Enter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1:
create();
break;
case 2:
insert();
break;
case 3:
delet();
break;
case 4:
display();
break;
case 5:
exit(0);
default:
printf("Invalid Choice!!\n");

break;

}
}
return 0;
}
Output:

You might also like