Data structure Lab 1 program
Data structure Lab 1 program
Program
#include <stdio.h>
int main() {
int arr[] = {12, 45, 3, 67, 22, 90, 5};
int size = sizeof(arr) / sizeof(arr[0]);
int min = arr[0], max = arr[0];
return 0;
}
2. Write a menu-based program to perform array operations: deletion of an element from the
specified position, inserting an element at the specified position, printing the array
elements.
Programs
#include <stdio.h>
int main() {
int arr[100] = {10, 20, 30, 40, 50};
int size = 5, choice, pos, value;
do {
printf("\nMenu:\n");
printf("1. Print Array\n");
printf("2. Insert Element\n");
printf("3. Delete Element\n");
printf("4. Exit\n");
printf("Enter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printArray(arr, size);
break;
case 2:
printf("Enter position to insert (0-based index): ");
scanf("%d", &pos);
printf("Enter value to insert: ");
scanf("%d", &value);
size = insertElement(arr, size, pos, value);
break;
case 3:
printf("Enter position to delete (0-based index): ");
scanf("%d", &pos);
size = deleteElement(arr, size, pos);
break;
case 4:
printf("Exiting...\n");
break;
default:
printf("Invalid choice, try again.\n");
}
} while (choice != 4);
return 0;
}