From 51cc29eb501ada9f4ee22c87542715e77855df78 Mon Sep 17 00:00:00 2001 From: aadit Date: Mon, 5 Aug 2024 01:08:32 +0530 Subject: [PATCH] Upload files to "DS/C/Lab/Week1" --- DS/C/Lab/Week1/binary.c | 75 ++++++++++++++++++++++++++++++++++ DS/C/Lab/Week1/bubble.c | 39 ++++++++++++++++++ DS/C/Lab/Week1/insertionsort.c | 43 +++++++++++++++++++ DS/C/Lab/Week1/linear.c | 43 +++++++++++++++++++ DS/C/Lab/Week1/selectionsort.c | 42 +++++++++++++++++++ 5 files changed, 242 insertions(+) create mode 100644 DS/C/Lab/Week1/binary.c create mode 100644 DS/C/Lab/Week1/bubble.c create mode 100644 DS/C/Lab/Week1/insertionsort.c create mode 100644 DS/C/Lab/Week1/linear.c create mode 100644 DS/C/Lab/Week1/selectionsort.c diff --git a/DS/C/Lab/Week1/binary.c b/DS/C/Lab/Week1/binary.c new file mode 100644 index 0000000..12cd4f8 --- /dev/null +++ b/DS/C/Lab/Week1/binary.c @@ -0,0 +1,75 @@ +#include + +int main() +{ + int a,c,n,i,temp; + int flag=0; + int arr[10]; + + printf("Enter the number of elements you want in the array: "); + scanf("%d",&n); + + printf("Enter the numbers you want in the array:\n"); + for(i=0;iarr[c]) + min=c; + if(aarr[min]) + max=c; + } + + if(flag){ + printf("The number has been found.\n"); + }else{ + printf("The number does not exist in this array.\n"); + } + + return 0; +} + + diff --git a/DS/C/Lab/Week1/bubble.c b/DS/C/Lab/Week1/bubble.c new file mode 100644 index 0000000..3c5d375 --- /dev/null +++ b/DS/C/Lab/Week1/bubble.c @@ -0,0 +1,39 @@ +#include + +int main() +{ + int n,i,j,temp; + int flag=0; + + printf("Enter the number of elements you want in the array: "); + scanf("%d",&n); + + int arr[n]; + + printf("Enter the numbers you want in the array:\n"); + for(i=0;iarr[j+1]){ + temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + } + } + } + + printf("The numbers in the sorted array are:\n"); + for(i=0;i + +int main() +{ + int n, i, j, temp; + int flag = 0; + + printf("Enter the number of elements you want in the array: "); + scanf("%d", &n); + + int arr[n]; + + printf("Enter the numbers you want in the array:\n"); + for (i = 0; i < n; i++) + { + scanf("%d", &arr[i]); + } + + printf("The numbers in the array are:\n"); + for (i = 0; i < n; i++) + { + printf("%d\n", arr[i]); + } + + // sorting + for (i = 0; i < n; i++) + { + int key = arr[i]; + int j = i - 1; + while (j >= 0 && arr[j] > key) + { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } + + printf("The numbers in the sorted array are:\n"); + for (i = 0; i < n; i++) + { + printf("%d \n", arr[i]); + } +} diff --git a/DS/C/Lab/Week1/linear.c b/DS/C/Lab/Week1/linear.c new file mode 100644 index 0000000..559f99e --- /dev/null +++ b/DS/C/Lab/Week1/linear.c @@ -0,0 +1,43 @@ +#include + +int main() +{ + int a,n,i; + int flag=0; + int arr[10]; + + printf("Enter the number of elements you want in the array: "); + scanf("%d",&n); + + printf("Enter the numbers you want in the array:\n"); + for(i=0;i + +int main() +{ + int n,i,j,temp; + int flag=0; + + printf("Enter the number of elements you want in the array: "); + scanf("%d",&n); + + int arr[n]; + + printf("Enter the numbers you want in the array:\n"); + for(i=0;i