Programs List For Internal and External Exam
Programs List For Internal and External Exam
#include <stdio.h>
// Function prototypes
int main() {
int array[MAX];
while (1) {
printf("\nChoose an operation:\n");
printf("4. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
break;
scanf("%d", &position);
break;
case 2:
if (size == 0) {
break;
scanf("%d", &position);
break;
case 3:
displayArray(array, size);
break;
case 4:
printf("Exiting program.\n");
return 0;
default:
return;
arr[position] = element;
(*size)++;
return;
(*size)--;
if (size == 0) {
printf("Array is empty.\n");
return;
}
printf("\n");
2. Write a program to search a particular data from the given array of strings using linear search
method.
#include <stdio.h>
#include <string.h>
#define MAX 100
int main() {
char arr[MAX][50], key[50];
int n, i;
int main() {
int arr[100], n, key, i;
printf("Enter number of elements: ");
scanf("%d", &n);
printf("Enter sorted elements:\n");
for (i = 0; i < n; i++) scanf("%d", &arr[i]);
#include <stdio.h>
arr[j + 1] = temp;
int main() {
int arr[100], n, i;
scanf("%d", &n);
printf("Enter elements:\n");
bubbleSort(arr, n);
return 0;
#include <stdio.h>
int min_idx = i;
arr[min_idx] = arr[i];
arr[i] = temp;
int main() {
int arr[100], n, i;
scanf("%d", &n);
printf("Enter elements:\n");
return 0;
#include <stdio.h>
arr[j + 1] = arr[j];
j--;
arr[j + 1] = key;
int main() {
int arr[100], n, i;
scanf("%d", &n);
printf("Enter elements:\n");
insertionSort(arr, n);
return 0;
}
7. Write a c program to implement singly linked list with operations 1)insert at beginning
2)Search 3)Display.
#include <stdio.h>
#include <stdlib.h>
int data;
} Node;
newNode->data = value;
newNode->next = head;
return newNode;
int pos = 1;
if (head->data == key) {
return;
head = head->next;
pos++;
printf("Not found.\n");
}
void display(Node* head) {
printf("List: ");
head = head->next;
printf("NULL\n");
int main() {
while (1) {
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &value);
break;
case 2:
scanf("%d", &value);
search(head, value);
break;
case 3:
display(head);
break;
case 4:
return 0;
default:
printf("Invalid choice.\n");
#include <stdio.h>
#include <stdlib.h>
} Node;
newNode->coeff = coeff;
newNode->power = power;
newNode->next = NULL;
return newNode;
if (*head == NULL) {
*head = newNode;
return;
temp->next = newNode;
poly1 = poly1->next;
poly2 = poly2->next;
} else {
poly1 = poly1->next;
poly2 = poly2->next;
while (poly1) {
poly1 = poly1->next;
while (poly2) {
poly2 = poly2->next;
return result;
head = head->next;
printf("\n");
int main() {
return 0;
9. Write a program Perform push and pop operations on stack using array
#include <stdio.h>
if (top == MAX - 1) {
printf("Stack overflow.\n");
return;
}
stack[++top] = value;
void pop() {
if (top == -1) {
printf("Stack underflow.\n");
return;
void display() {
if (top == -1) {
printf("Stack is empty.\n");
return;
printf("Stack: ");
printf("\n");
int main() {
while (1) {
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &value);
push(value);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
return 0;
default:
printf("Invalid choice.\n");
10. Write a program Perform push and pop operations on stack using linked list.
#include <stdio.h>
#include <stdlib.h>
int data;
} Node;
if (!newNode) {
printf("Stack overflow.\n");
return;
}
newNode->data = value;
newNode->next = top;
top = newNode;
void pop() {
if (top == NULL) {
printf("Stack underflow.\n");
return;
top = top->next;
free(temp);
void display() {
if (top == NULL) {
printf("Stack is empty.\n");
return;
printf("Stack: ");
while (temp) {
temp = temp->next;
printf("\n");
}
int main() {
while (1) {
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &value);
push(value);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
return 0;
default:
printf("Invalid choice.\n");
#include <stdio.h>
if (b == 0) return 0;
if (b > 0) return a + multiply(a, b - 1);
int main() {
int a, b;
return 0;
12. Write a program Perform insert and delete operations on linear queue using array.
#include <stdio.h>
if (rear == MAX - 1) {
printf("Queue overflow.\n");
return;
queue[++rear] = value;
void dequeue() {
printf("Queue underflow.\n");
return;
}
printf("Dequeued: %d\n", queue[front++]);
void display() {
printf("Queue is empty.\n");
return;
printf("Queue: ");
printf("\n");
int main() {
while (1) {
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &value);
enqueue(value);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
return 0;
default:
printf("Invalid choice.\n");
13. Write a program Perform insert and delete operations on linear queue using linked list.
#include <stdio.h>
#include <stdlib.h>
int data;
} Node;
if (!newNode) {
printf("Queue overflow.\n");
return;
newNode->data = value;
newNode->next = NULL;
if (rear == NULL) {
return;
}
rear->next = newNode;
rear = newNode;
void dequeue() {
if (front == NULL) {
printf("Queue underflow.\n");
return;
front = front->next;
free(temp);
void display() {
if (front == NULL) {
printf("Queue is empty.\n");
return;
printf("Queue: ");
while (temp) {
temp = temp->next;
printf("\n");
int main() {
int choice, value;
while (1) {
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &value);
enqueue(value);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
return 0;
default:
printf("Invalid choice.\n");
14. Write a c program to perform insert and delete operations on circular queue using an
array.
#include <stdio.h>
printf("Queue overflow.\n");
return;
queue[rear] = value;
void dequeue() {
if (front == -1) {
printf("Queue underflow.\n");
return;
void display() {
if (front == -1) {
printf("Queue is empty.\n");
return;
printf("Queue: ");
printf("%d\n", queue[rear]);
}
int main() {
while (1) {
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &value);
enqueue(value);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
return 0;
default:
printf("Invalid choice.\n");