From 69bf90cb3dd30b1bb00cd0f1a3941a2bac766e2e Mon Sep 17 00:00:00 2001 From: pavithradogiparthi <86222542+pavithradogiparthi@users.noreply.github.com> Date: Mon, 4 Oct 2021 17:38:50 +0530 Subject: [PATCH 1/3] Create binarysearch_pavithra.c binary search by pavithra dogiparthi --- binarysearch_pavithra.c | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 binarysearch_pavithra.c diff --git a/binarysearch_pavithra.c b/binarysearch_pavithra.c new file mode 100644 index 0000000..5c98a97 --- /dev/null +++ b/binarysearch_pavithra.c @@ -0,0 +1,50 @@ +write a program to binary search an elemnt in c language +#include +int main() +{ + int arr[4]; + int n; + int i; + int low; + int high; + int mid; + int x; + printf("no of elements in array\n"); + scanf("%d",&n); + printf("elements are \n"); + for (i=0;i high) + printf("Not found! %d isn't present in the list.\n", x); +} + +output +no of elements in array + 7 +elements are +1 2 4 6 8 9 11 +enter x 8 +8 found at location 5. + + + From 722d21f465c595b3d976dad8083855996b795fbf Mon Sep 17 00:00:00 2001 From: pavithradogiparthi <86222542+pavithradogiparthi@users.noreply.github.com> Date: Mon, 25 Oct 2021 20:08:28 +0530 Subject: [PATCH 2/3] Create selectionsort.c --- selectionsort.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 selectionsort.c diff --git a/selectionsort.c b/selectionsort.c new file mode 100644 index 0000000..5700acd --- /dev/null +++ b/selectionsort.c @@ -0,0 +1,50 @@ +//wap to do selection sort in linkedlist + +#include + +int findMinIdx(int arr[], int start, int end); +void display(int arr[]); +void selectionsort(int arr[], int start, int end); + +int findMinIdx(int arr[], int start, int end) +{ + int min_idx=start; + int i; + for(i=start+1;i<=end;i++) + { + if(arr[min_idx]>arr[i]) + min_idx=i; + } + return min_idx; +} +void display(int arr[]) +{ + int i; + for(i=0;i<=5;i++) + { + printf("%d ",arr[i]); + } +} +void swap(int* a, int* b) +{ + int temp= *b; + *b=*a; + *a=temp; +} + +void selectionsort(int arr[], int start, int end) +{ + int i; int min_idx; int x; + for(i=start; i<=end;i++) + { + min_idx=i; + x=findMinIdx(arr,i,end); + swap(&arr[min_idx],&arr[x]); + } +} +void main() +{ + int arr[6]={1,6,2,5,8,9}; + selectionsort(arr,0,5); + display(arr); +} From 029e2108af0b34b43f29542902855a16f9e88d88 Mon Sep 17 00:00:00 2001 From: pavithradogiparthi <86222542+pavithradogiparthi@users.noreply.github.com> Date: Mon, 25 Oct 2021 20:39:56 +0530 Subject: [PATCH 3/3] Create diagnoal_traversal.c --- diagnoal_traversal.c | 76 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 diagnoal_traversal.c diff --git a/diagnoal_traversal.c b/diagnoal_traversal.c new file mode 100644 index 0000000..1b37105 --- /dev/null +++ b/diagnoal_traversal.c @@ -0,0 +1,76 @@ +WAP to print the lements of an array in diagonal traversal + +#include +void main() +{ + int arr[8][8]; + int put=1; + int i,j; + int m=7; + arr[0][0]=put; + for(i=0;i<=m;i++) + { + for(j=0;j<=m;j++) + { + printf("%2d ",put); + + arr[i][j]=put++; + }printf("\n"); + } + + printf("elements in diagonal traversal \n"); + int k; + for(k =m;k>=0;k--) + { + i=k; + j=0; + while(i<=m) + { + printf("%d ",arr[i][j]); + i++; + j++; + } + printf("\n"); + } + + for(k=1;k<=m;k++) + { + i=0; + j=k; + while(j<=m) + { + printf("%d ",arr[i][j]); + i++; + j++;} + printf("\n"); + + } + +} + +output: + 1 2 3 4 5 6 7 8 + 9 10 11 12 13 14 15 16 +17 18 19 20 21 22 23 24 +25 26 27 28 29 30 31 32 +33 34 35 36 37 38 39 40 +41 42 43 44 45 46 47 48 +49 50 51 52 53 54 55 56 +57 58 59 60 61 62 63 64 +elements in diagonal traversal +57 +49 58 +41 50 59 +33 42 51 60 +25 34 43 52 61 +17 26 35 44 53 62 +9 18 27 36 45 54 63 +1 10 19 28 37 46 55 64 +2 11 20 29 38 47 56 +3 12 21 30 39 48 +4 13 22 31 40 +5 14 23 32 +6 15 24 +7 16 +8 +