23BBS0006 VL2023240506375 Ast02
23BBS0006 VL2023240506375 Ast02
Digital Assesment 2
Name: Mohammed Sami
Registration Number : 23BBS0006 Date: 08/03/24
1.
Algorithm:
Copy of the file:
Source code:
#include <stdio.h>
#include <stdlib.h>
struct Node {
int coefficient;
int exponent;
struct Node* next;
};
int main() {
Node* poly1 = NULL;
insert(&poly1, 3, 2);
insert(&poly1, 2, 1);
insert(&poly1, 5, 0);
printf("Polynomial 1: ");
display(poly1);
printf("Polynomial 2: ");
display(poly2);
1.
Input:
Output:
2.
Input:
Output:
3.Extreme input case:
Output:
2.:
Algorithm:
Source code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
do{
int n;
printf("\n *****");
printf("\n\nEnter the number of inputs(enter 0 to exit): ");
scanf("%d",&n);
if(n==0){
break;
}
if(n<0){
printf("\nInvalid ! Enter positive number of inputs!");
}
else{
int input[n];
//Taking inputs
printf("\nEnter the inputs: ");
for(int i=0;i<n;i++){
scanf("%d",&input[i]);
}
int search;
printf("Enter the element to search :");
scanf("%d",&search);
int count=0;
Source Code:
#include<stdio.h>
#include<stdlib.h>
#define max_size 5
if (min_index != i) {
int temp = arr[i];
arr[i] = arr[min_index];
arr[min_index] = temp;
}
}
int main()
{
int arr[max_size]={34,65,34,23,78};
int choice;
do{
printf("\n\nEnter your choice for the sorting algorithm:\n0.Exit\n1.Bubble
sort\n2.Insertion sort\n3.Selection sort\n");
scanf("%d",&choice);
if (choice==0){
break;
}
else
{switch(choice)
{
case 1:
bubble_sort(arr);
break;
case 2:
insertion_sort(arr);
break;
case 3:
selection_sort(arr);
break;
default:
printf("Invalid input!");
break;
}
}}while (1);
return 0;
}
Test Cases 1,2, and 3:
Test case 4: