DSU ANSWER 1.LINEAR SEARCH OUTPUT CODE #include<stdio.h> int main() { int a[20],i,x,n; printf("How many elements?"); scanf("%d",&n); printf("Enter array elements:n"); for(i=0;i<n;++i) scanf("%d",&a[i]); printf("nEnter element to search:"); scanf("%d",&x); for(i=0;i<n;++i) if(a[i]==x) break; if(i<n) printf("Element found at index %d",i); else printf("Element not found"); return 0; } 2.SELECTION SORT OUTPUT CODE #include <stdio.h> int main() { int a[100], n, i, j, position, swap; printf("Enter number of elements"); scanf("%d", &n); printf("Enter %d Numbers", n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for(i = 0; i < n - 1; i++) { position=i; for(j = i + 1; j < n; j++) { if(a[position] > a[j]) position=j; } if(position != i) { swap=a[i]; a[i]=a[position]; a[position=swap]; } } printf("Sorted Array"); for(i = 0; i < n; i++) printf("%d", a[i]); return 0; } 3. DELETE ELEMENT FROM ARRAY OUTPUT CODE #include <stdio.h> #include <conio.h> int main () { // declaration of the int type variable int arr[50]; int pos, i, num; // declare int type variable printf (" \ n Enter the number of elements in an array: \ n "); scanf (" %d", &num); printf (" \ n Enter %d elements in array: \ n ", num); // use for loop to insert elements one by one in array for (i = 0; i < num; i++ ) { printf (" arr [%d] = ", i); scanf (" %d", &arr[i]); } // enter the position of the element to be deleted printf( " Define the position of the array element where you want to delete: \ n "); scanf (" %d", &pos); // che ck whether the deletion is possible or not if (pos >= num+1) { printf (" \ n Deletion is not possible in the array."); } else { // use for loop to delete the element and update the index for (i = p os - 1; i < num - 1; i++) { arr[i] = arr[i+1]; // assign arr[i+1] to arr[i] } printf (" \ n The resultant array is: \ n"); // display the final array for (i = 0; i< num - 1; i++) { printf (" arr[%d] = ", i); printf (" %d \ n", arr[i]); } } return 0; } 4. STACK OUTPUT #include <stdio.h> #include <stdlib.h> #define SIZE 4 int top = - 1, inp_array [SIZE]; void push(); void pop(); void show(); int main() { int choice; while (1) { printf(" \ nPerform operations on the stack:"); printf(" \ n1.Push the element \ n2.Pop the element \ n3.Show \ n4.End"); printf(" \ n \ nEnter the choice: "); scanf("%d", &choice); switch (choice) { case 1: push(); break; case 2: pop(); break; case 3: show(); break; ca se 4: exit(0); default: printf(" \ nInvalid choice!!"); } } } void push() { int x; if (top == SIZE - 1) { printf(" \ nOverflow!!"); } else { printf(" \ nEnter the element to be added onto the stack: "); scanf("%d", &x); top = top + 1; inp_array[top] = x; } } void pop() { if (top == - 1) { printf(" \ nUnderflow!!"); } else { printf(" \ nPopped element: %d", inp_array[top]); top = top - 1; } } void show() { if (top == - 1) { printf(" \ nUnderflow!!"); } else { printf(" \ nElements present in the stack: \ n"); for (int i = top; i >= 0; -- i) printf("%d \ n", inp_array[i]); } }