Programs
Programs
Programs
#include <stdio.h>
#include <stdlib.h>
if (size == 0) {
printf("Array is empty.\n");
return;
printf("\n");
printf("Invalid position.\n");
return -1;
if (*arr == NULL) {
return -1;
}
(*arr)[position] = element;
(*size)++;
return 0;
printf("Invalid position.\n");
return -1;
return -1;
(*size)--;
return 0;
int main() {
int size = 0;
while (1) {
printf("\nMenu:\n");
printf("1. Create\n");
printf("2. Insert\n");
printf("3. Delete\n");
printf("4. Display\n");
printf("5. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &size);
if (arr == NULL) {
return -1;
scanf("%d", &arr[i]);
break;
case 2:
scanf("%d", &element);
scanf("%d", &position);
break;
case 3:
scanf("%d", &position);
break;
case 4:
display(arr, size);
break;
case 5:
free(arr);
return 0;
default:
printf("Invalid choice.\n");
return 0;
PRACTICAL NO.2
AIM- Write a ‘C’ Program to search a particular data from the given array of numbers using :
Linear Search Method
#include <stdio.h>
if (arr[i] == target) {
return i;
return -1;
}
int main() {
scanf("%d", &size);
int arr[size];
scanf("%d", &arr[i]);
scanf("%d", &target);
if (result != -1) {
} else {
return 0;
PRACTICAL 3
AIM- Write C Program to search a particular data from the given array of strings using Linear
Search Method
#include <stdio.h>
#include <string.h>
if (strcmp(arr[i], target) == 0) {
return i;
return -1;
int main() {
int size;
scanf("%d", &size);
getchar();
if (result != -1) {
} else {
}
return 0;
PRACTICAL NO.4
AIM- Write a ‘C” program to search a particular data from the given array of numbers using
Binary Search method
#include <stdio.h>
int left = 0;
if (arr[mid] == target) {
return mid;
left = mid + 1;
else {
right = mid - 1;
return -1;
int main() {
int target;
scanf("%d", &target);
int result = binarySearch(arr, size, target);
if (result != -1) {
} else {
return 0;
PRACTICAL NUMBER 5
AIM- Write a ‘C” program to search a particular data from the given array of strings using
Binary Search Method
#include <stdio.h>
#include <string.h>
int left = 0;
if (comparison == 0) {
return mid;
left = mid + 1;
} else {
right = mid - 1;
return -1;
}
int main() {
char target[20];
scanf("%s", target);
if (result != -1) {
} else {
return 0;
PRACTICAL NO 6
AIM- Write a ‘C” Program to sort an array of numbers using Bubble Sort Method
#include <stdio.h>
int swapped = 0;
arr[j + 1] = temp;
swapped = 1;
}
}
if (swapped == 0) {
break;
printf("\n");
int main() {
printArray(arr, size);
bubbleSort(arr, size);
printArray(arr, size);
return 0;
PRACTICAL NO 7
AIM- Write a ‘C’ Program to Sort an Array of Strings using Bubble Sort Method
#include <stdio.h>
#include <string.h>
arr[j + 1] = temp;
swapped = 1;
if (swapped == 0) {
break;
printf("\n");
int main() {
printArray(arr, size);
bubbleSort(arr, size);
return 0;
PRACTICAL 8
AIM- Write a ‘C’Program to sort an Array of numbers using Selection Sort Method
#include <stdio.h>
int minIndex = i;
if (minIndex != i) {
arr[i] = arr[minIndex];
arr[minIndex] = temp;
printf("\n");
}
int main() {
printArray(arr, size);
selectionSort(arr, size);
printArray(arr, size);
return 0;
PRACTICAL9
AIM- Write a ‘C’ Program to sort an Array of Strings using Selection Sort Method
#include <stdio.h>
#include <string.h>
int minIndex = i;
if (minIndex != i) {
arr[i] = arr[minIndex];
arr[minIndex] = temp;
}
}
printf("\n");
int main() {
printArray(arr, size);
selectionSort(arr, size);
printArray(arr, size);
return 0;
PRACTICAL NO 10
AIM- Write a ‘C’Program to sort an Array of numbers using Insertion Sort Method
#include <stdio.h>
int j = i - 1;
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
printf("\n");
int main() {
printArray(arr, size);
insertionSort(arr, size);
printArray(arr, size);
return 0;
PRACTICAL 11
AIM- Write a ‘C’ Program to Sort an Array of Strings using Insertion Sort Method
#include <stdio.h>
#include <string.h>
int j = i - 1;
j = j - 1;
arr[j + 1] = key;
printf("\n");
int main() {
printArray(arr, size);
insertionSort(arr, size);
printArray(arr, size);
return 0;