From 7dfe90c551d8e6377d645bafefcdefab871ea606 Mon Sep 17 00:00:00 2001 From: anjanisinghal21 <91344343+anjanisinghal21@users.noreply.github.com> Date: Fri, 29 Oct 2021 20:10:02 +0530 Subject: [PATCH 1/2] bubble_sort.c --- BubbleSort.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 BubbleSort.c diff --git a/BubbleSort.c b/BubbleSort.c new file mode 100644 index 0000000..45d5435 --- /dev/null +++ b/BubbleSort.c @@ -0,0 +1,44 @@ +// C++ program for implementation of Bubble sort +#include +using namespace std; + +void swap(int *xp, int *yp) +{ + int temp = *xp; + *xp = *yp; + *yp = temp; +} + +// A function to implement bubble sort +void bubbleSort(int arr[], int n) +{ + int i, j; + for (i = 0; i < n-1; i++) + + // Last i elements are already in place + for (j = 0; j < n-i-1; j++) + if (arr[j] > arr[j+1]) + swap(&arr[j], &arr[j+1]); +} + +/* Function to print an array */ +void printArray(int arr[], int size) +{ + int i; + for (i = 0; i < size; i++) + cout << arr[i] << " "; + cout << endl; +} + +// Driver code +int main() +{ + int arr[] = {64, 34, 25, 12, 22, 11, 90}; + int n = sizeof(arr)/sizeof(arr[0]); + bubbleSort(arr, n); + cout<<"Sorted array: \n"; + printArray(arr, n); + return 0; +} + +// This code is contributed by rathbhupendra From 67fd59569f205494da7aad2e4d0da5ca417bbe08 Mon Sep 17 00:00:00 2001 From: anjanisinghal21 <91344343+anjanisinghal21@users.noreply.github.com> Date: Fri, 29 Oct 2021 20:13:30 +0530 Subject: [PATCH 2/2] Lucky no in C is created. --- Lucky_numbers.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Lucky_numbers.c diff --git a/Lucky_numbers.c b/Lucky_numbers.c new file mode 100644 index 0000000..24b7601 --- /dev/null +++ b/Lucky_numbers.c @@ -0,0 +1,38 @@ +// C++ program for Lucky Numbers +#include +using namespace std; +#define bool int + +/* Returns 1 if n is a lucky no. +otherwise returns 0*/ +bool isLucky(int n) +{ + static int counter = 2; + + if(counter > n) + return 1; + if(n % counter == 0) + return 0; + + /*calculate next position of input no. + Variable "next_position" is just for + readability of the program we can + remove it and update in "n" only */ + int next_position = n - (n/counter); + + counter++; + return isLucky(next_position); +} + +// Driver Code +int main() +{ + int x = 5; + if( isLucky(x) ) + cout << x << " is a lucky no."; + else + cout << x << " is not a lucky no."; +} + +// This code is contributed +// by rathbhupendra