Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions BubbleSort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// C++ program for implementation of Bubble sort
#include <bits/stdc++.h>
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
38 changes: 38 additions & 0 deletions Lucky_numbers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// C++ program for Lucky Numbers
#include <bits/stdc++.h>
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