From a6b4c9f56af599c26cc29affd2408da5ec216a42 Mon Sep 17 00:00:00 2001 From: HIMANSHU SHARMA Date: Mon, 6 Jan 2020 15:42:20 +0530 Subject: [PATCH 01/17] Check_Palindrome.c I have created a C program to check whether a number is palindrome or not using BITWISE. --- Check_Palindrome.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Check_Palindrome.c diff --git a/Check_Palindrome.c b/Check_Palindrome.c new file mode 100644 index 0000000..f33cbf5 --- /dev/null +++ b/Check_Palindrome.c @@ -0,0 +1,28 @@ +#include +#define SIZE 8 + +int main() +{ + unsigned int n; + printf("Enter number ( max range 255)\n"); + scanf("%d",&n); + int c[SIZE]={0}; + int i=SIZE-1; + printf("Binary representation is: "); + while(n!=0){ + c[i--]=n&1; + n=n>>1; + } + for(int j=0;j Date: Mon, 6 Jan 2020 15:48:58 +0530 Subject: [PATCH 02/17] Create Jump_Search.cpp I have created Jump_Search.cpp --- Jump_Search.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Jump_Search.cpp diff --git a/Jump_Search.cpp b/Jump_Search.cpp new file mode 100644 index 0000000..83df681 --- /dev/null +++ b/Jump_Search.cpp @@ -0,0 +1,40 @@ +#include +#include + +using namespace std; +int jumpSearch(int array[], int size, int key) { + int start = 0; + int end = sqrt(size); + + while(array[end] <= key && end < size) { + start = end; + end += sqrt(size); + if(end > size - 1) + end = size; + } + + for(int i = start; i> n; + int arr[n]; + cout << "Enter items: " << endl; + + for(int i = 0; i< n; i++) { + cin >> arr[i]; + } + + cout << "Enter search key to search in the list: "; + cin >> searchKey; + if((loc = jumpSearch(arr, n, searchKey)) >= 0) + cout << "Item found at location: " << loc << endl; + else + cout << "Item is not found in the list." << endl; +} From c26d0d2d6e17275a7d925c0f4c237dfecf333243 Mon Sep 17 00:00:00 2001 From: HIMANSHU SHARMA Date: Tue, 7 Jan 2020 13:20:20 +0530 Subject: [PATCH 03/17] Create Swap_Bits.c --- Swap_Bits.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Swap_Bits.c diff --git a/Swap_Bits.c b/Swap_Bits.c new file mode 100644 index 0000000..3c021a9 --- /dev/null +++ b/Swap_Bits.c @@ -0,0 +1,14 @@ +#include +int main() +{ + int num,m,n; + scanf("%d"&num); + scanf("%d%d",&m,&n); + int x,y; + x=(num>>m)&1; + y=(num>>n)&1; + int p=x^y; + p=(p< Date: Thu, 9 Jan 2020 19:27:27 +0530 Subject: [PATCH 04/17] Created DivisibleBy9.c --- DivisibleBy9.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 DivisibleBy9.c diff --git a/DivisibleBy9.c b/DivisibleBy9.c new file mode 100644 index 0000000..fbc8e9e --- /dev/null +++ b/DivisibleBy9.c @@ -0,0 +1,21 @@ +#include +int divisibleby9(int n) +{ + if(n==9 || n==0) + return 1; + if(n<9) + return 0; + int x=n>>3; + int y=n&7; + n=x-y; + return divisibleby9(n); +} +int main() +{ + int n; + scanf("%d",&n); + if(divisibleby9(n)) + printf("Yes"); + else + printf("No"); +} From dc8dfc40fd593413d03354b390e1a89c57530db5 Mon Sep 17 00:00:00 2001 From: HIMANSHU SHARMA Date: Sat, 18 Jan 2020 00:28:32 +0530 Subject: [PATCH 05/17] Create Queue.c --- Queue.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Queue.c diff --git a/Queue.c b/Queue.c new file mode 100644 index 0000000..228764a --- /dev/null +++ b/Queue.c @@ -0,0 +1,51 @@ +#include +#include +#define SIZE 5 + +void insert(int); + +int find_min(); +int q[SIZE]; +int front=-1,rear=-1; +void insert(int n) +{ + if(rear==SIZE-1) + { + printf("Queue overflow"); + exit(1); + } + else + { + if(front==-1) + front=0; + rear++; + q[rear]=n; + } +} +int find_min() +{ + front=0; + int min=q[front]; + for(int i=front;i<=rear;i++) + { + if(min>q[i]) + min=q[i]; + } + return min; +} +int main() +{ + int val; + scanf("%d",&n); + for(int i=0;i Date: Mon, 20 Jan 2020 23:25:11 +0530 Subject: [PATCH 06/17] Create FibonacciSeries.cpp --- FibonacciSeries.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 FibonacciSeries.cpp diff --git a/FibonacciSeries.cpp b/FibonacciSeries.cpp new file mode 100644 index 0000000..7ba9a4d --- /dev/null +++ b/FibonacciSeries.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +void printFibonacci(int n){ + static int n1=0, n2=1, n3; + if(n>0){ + n3 = n1 + n2; + n1 = n2; + n2 = n3; + cout<>n; + cout<<"Fibonacci Series: "; + cout<<"0 "<<"1 "; + printFibonacci(n-2); + return 0; +} From a6615b4f2de94809b41f379668d163ff5f89487b Mon Sep 17 00:00:00 2001 From: HIMANSHU SHARMA Date: Sat, 25 Jan 2020 13:28:19 +0530 Subject: [PATCH 07/17] Create Counting_Substring.c --- Counting_Substring.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Counting_Substring.c diff --git a/Counting_Substring.c b/Counting_Substring.c new file mode 100644 index 0000000..a3885a8 --- /dev/null +++ b/Counting_Substring.c @@ -0,0 +1,28 @@ +#include +#include +void count(char *str); +int main() +{ + char str(100) + scanf("%[^\n]",str); + count(str); +} +void count(char *str) +{ + char tmp[]="the"; + int i,j,c=0,cnt=0; + for(i-0;i Date: Sun, 26 Jan 2020 10:53:41 +0530 Subject: [PATCH 08/17] Add files via upload --- Himanshu Sharma/Check_Palindrome.c | 28 +++++++++++++++ Himanshu Sharma/Counting_Substring.c | 28 +++++++++++++++ Himanshu Sharma/DivisibleBy9.c | 21 ++++++++++++ Himanshu Sharma/FibonacciSeries.cpp | 21 ++++++++++++ Himanshu Sharma/Jump_Search.cpp | 40 ++++++++++++++++++++++ Himanshu Sharma/Queue.c | 51 ++++++++++++++++++++++++++++ Himanshu Sharma/README.md | 27 +++++++++++++++ Himanshu Sharma/Swap_Bits.c | 14 ++++++++ 8 files changed, 230 insertions(+) create mode 100644 Himanshu Sharma/Check_Palindrome.c create mode 100644 Himanshu Sharma/Counting_Substring.c create mode 100644 Himanshu Sharma/DivisibleBy9.c create mode 100644 Himanshu Sharma/FibonacciSeries.cpp create mode 100644 Himanshu Sharma/Jump_Search.cpp create mode 100644 Himanshu Sharma/Queue.c create mode 100644 Himanshu Sharma/README.md create mode 100644 Himanshu Sharma/Swap_Bits.c diff --git a/Himanshu Sharma/Check_Palindrome.c b/Himanshu Sharma/Check_Palindrome.c new file mode 100644 index 0000000..f33cbf5 --- /dev/null +++ b/Himanshu Sharma/Check_Palindrome.c @@ -0,0 +1,28 @@ +#include +#define SIZE 8 + +int main() +{ + unsigned int n; + printf("Enter number ( max range 255)\n"); + scanf("%d",&n); + int c[SIZE]={0}; + int i=SIZE-1; + printf("Binary representation is: "); + while(n!=0){ + c[i--]=n&1; + n=n>>1; + } + for(int j=0;j +#include +void count(char *str); +int main() +{ + char str(100) + scanf("%[^\n]",str); + count(str); +} +void count(char *str) +{ + char tmp[]="the"; + int i,j,c=0,cnt=0; + for(i-0;i +int divisibleby9(int n) +{ + if(n==9 || n==0) + return 1; + if(n<9) + return 0; + int x=n>>3; + int y=n&7; + n=x-y; + return divisibleby9(n); +} +int main() +{ + int n; + scanf("%d",&n); + if(divisibleby9(n)) + printf("Yes"); + else + printf("No"); +} diff --git a/Himanshu Sharma/FibonacciSeries.cpp b/Himanshu Sharma/FibonacciSeries.cpp new file mode 100644 index 0000000..7ba9a4d --- /dev/null +++ b/Himanshu Sharma/FibonacciSeries.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +void printFibonacci(int n){ + static int n1=0, n2=1, n3; + if(n>0){ + n3 = n1 + n2; + n1 = n2; + n2 = n3; + cout<>n; + cout<<"Fibonacci Series: "; + cout<<"0 "<<"1 "; + printFibonacci(n-2); + return 0; +} diff --git a/Himanshu Sharma/Jump_Search.cpp b/Himanshu Sharma/Jump_Search.cpp new file mode 100644 index 0000000..83df681 --- /dev/null +++ b/Himanshu Sharma/Jump_Search.cpp @@ -0,0 +1,40 @@ +#include +#include + +using namespace std; +int jumpSearch(int array[], int size, int key) { + int start = 0; + int end = sqrt(size); + + while(array[end] <= key && end < size) { + start = end; + end += sqrt(size); + if(end > size - 1) + end = size; + } + + for(int i = start; i> n; + int arr[n]; + cout << "Enter items: " << endl; + + for(int i = 0; i< n; i++) { + cin >> arr[i]; + } + + cout << "Enter search key to search in the list: "; + cin >> searchKey; + if((loc = jumpSearch(arr, n, searchKey)) >= 0) + cout << "Item found at location: " << loc << endl; + else + cout << "Item is not found in the list." << endl; +} diff --git a/Himanshu Sharma/Queue.c b/Himanshu Sharma/Queue.c new file mode 100644 index 0000000..228764a --- /dev/null +++ b/Himanshu Sharma/Queue.c @@ -0,0 +1,51 @@ +#include +#include +#define SIZE 5 + +void insert(int); + +int find_min(); +int q[SIZE]; +int front=-1,rear=-1; +void insert(int n) +{ + if(rear==SIZE-1) + { + printf("Queue overflow"); + exit(1); + } + else + { + if(front==-1) + front=0; + rear++; + q[rear]=n; + } +} +int find_min() +{ + front=0; + int min=q[front]; + for(int i=front;i<=rear;i++) + { + if(min>q[i]) + min=q[i]; + } + return min; +} +int main() +{ + int val; + scanf("%d",&n); + for(int i=0;i
+ Steps to run the program +
    +
  1. Fork the project you want to work +
  2. Open the program of respective language in editors like +
      For C, C++ +
    • DEv C++ +
    • Turbo C +
    +
    +
      Python +
    • Sublime Text +
    • Python Idle +
    +
    + +
    +
  3. Make the required changes +
  4. Commit the changes +
  5. Make a pull request (PR) +
  6. Check Leader Board +
+ diff --git a/Himanshu Sharma/Swap_Bits.c b/Himanshu Sharma/Swap_Bits.c new file mode 100644 index 0000000..3c021a9 --- /dev/null +++ b/Himanshu Sharma/Swap_Bits.c @@ -0,0 +1,14 @@ +#include +int main() +{ + int num,m,n; + scanf("%d"&num); + scanf("%d%d",&m,&n); + int x,y; + x=(num>>m)&1; + y=(num>>n)&1; + int p=x^y; + p=(p< Date: Mon, 27 Jan 2020 21:31:05 +0530 Subject: [PATCH 09/17] Create Minimum adjacent swaps.cpp --- Himanshu Sharma/Minimum adjacent swaps.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Himanshu Sharma/Minimum adjacent swaps.cpp diff --git a/Himanshu Sharma/Minimum adjacent swaps.cpp b/Himanshu Sharma/Minimum adjacent swaps.cpp new file mode 100644 index 0000000..4a91acd --- /dev/null +++ b/Himanshu Sharma/Minimum adjacent swaps.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; +void solve(int a[], int n) +{ + int maxx = -1, minn = a[0], l = 0, r = 0; + for (int i = 0; i < n; i++) { + if (a[i] > maxx) { + maxx = a[i]; + l = i; + } + if (a[i] <= minn) { + minn = a[i]; + r = i; + } + } + if (r < l) + cout << l + (n - r - 2); + else + cout << l + (n - r - 1); +} +int main() +{ + int n; + cin>>n; + int arr[n]; + for(int i=0;i>arr[i]; + } + solve(arr, n); + return 0; +} From f4a68d90f58fbdb34454861a8b9ff9f7a99b397d Mon Sep 17 00:00:00 2001 From: HIMANSHU SHARMA Date: Mon, 27 Jan 2020 23:36:57 +0530 Subject: [PATCH 10/17] Create LeftShift.c --- Himanshu Sharma/LeftShift.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Himanshu Sharma/LeftShift.c diff --git a/Himanshu Sharma/LeftShift.c b/Himanshu Sharma/LeftShift.c new file mode 100644 index 0000000..3f279b7 --- /dev/null +++ b/Himanshu Sharma/LeftShift.c @@ -0,0 +1,29 @@ +#include + +int main() +{ + int n; + scanf("%d",&n); + int a[n]; + for(int i=0;i=n){ + a[i]=tmp[j]; + j++; + } + else + a[i]=a[i+m]; + } + for(int i=0;i Date: Wed, 29 Jan 2020 12:16:28 +0530 Subject: [PATCH 11/17] Create permutation.c --- Himanshu Sharma/permutation.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Himanshu Sharma/permutation.c diff --git a/Himanshu Sharma/permutation.c b/Himanshu Sharma/permutation.c new file mode 100644 index 0000000..4dbc9e0 --- /dev/null +++ b/Himanshu Sharma/permutation.c @@ -0,0 +1,31 @@ +#include +#include +void swap(char *x, char *y) +{ + char temp; + temp = *x; + *x = *y; + *y = temp; +} +void permute(char *a, int l, int r) +{ + int i; + if (l == r) + printf("%s\n", a); + else + { + for (i = l; i <= r; i++) + { + swap((a+l), (a+i)); + permute(a, l+1, r); + swap((a+l), (a+i)); //backtrack + } + } +} +int main() +{ + char str[] = "ABC"; + int n = strlen(str); + permute(str, 0, n-1); + return 0; +} From 9ae5a05d095e3909ef94280735f80078214f95ba Mon Sep 17 00:00:00 2001 From: HIMANSHU SHARMA Date: Wed, 29 Jan 2020 16:30:21 +0530 Subject: [PATCH 12/17] Create Magic Square.cpp --- Himanshu Sharma/Magic Square.cpp | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Himanshu Sharma/Magic Square.cpp diff --git a/Himanshu Sharma/Magic Square.cpp b/Himanshu Sharma/Magic Square.cpp new file mode 100644 index 0000000..82646fb --- /dev/null +++ b/Himanshu Sharma/Magic Square.cpp @@ -0,0 +1,50 @@ +#include +using namespace std; +void generateSquare(int n) +{ + int magicSquare[n][n]; + memset(magicSquare, 0, sizeof(magicSquare)); + + int i = n/2; + int j = n-1; + for (int num = 1; num <= n*n; ) + { + if (i == -1 && j == n) + { + j = n-2; + i = 0; + } + else + { + if (j == n) + j = 0; + if (i < 0) + i = n - 1; + } + if (magicSquare[i][j]) + { + j -= 2; + i++; + continue; + } + else + magicSquare[i][j] = num++; + + j++; i--; + } + cout<<"The Magic Square for n="<>n;// Works only when n is odd + generateSquare (n); + return 0; +} From 108314136d5e0beef2438aed55116be1c28f47e0 Mon Sep 17 00:00:00 2001 From: HIMANSHU SHARMA Date: Fri, 31 Jan 2020 22:33:48 +0530 Subject: [PATCH 13/17] Create Position_Of_SetBit.c --- Himanshu Sharma/Position_Of_SetBit.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Himanshu Sharma/Position_Of_SetBit.c diff --git a/Himanshu Sharma/Position_Of_SetBit.c b/Himanshu Sharma/Position_Of_SetBit.c new file mode 100644 index 0000000..e02d4e2 --- /dev/null +++ b/Himanshu Sharma/Position_Of_SetBit.c @@ -0,0 +1,24 @@ +#include +int isPowerOfTwo(unsigned n) +{ + return n && (!(n & (n - 1))); +} +int findPosition(unsigned n) +{ + if (!isPowerOfTwo(n)) + return -1; + unsigned i = 1, pos = 1; + while (!(i & n)) { + i = i << 1; + ++pos; + } + return pos; +} +int main(void) +{ + int n; + scanf("%d",&n); + int pos = findPosition(n); + (pos == -1) ? printf("n = %d, Invalid number\n", n) : printf("n = %d, Position %d \n", n, pos); + return 0; +} From fa375b42d24ba565d2e98883d44d08b0651632a1 Mon Sep 17 00:00:00 2001 From: HIMANSHU SHARMA Date: Fri, 31 Jan 2020 23:18:20 +0530 Subject: [PATCH 14/17] Create Parity.cpp --- Parity.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Parity.cpp diff --git a/Parity.cpp b/Parity.cpp new file mode 100644 index 0000000..f791754 --- /dev/null +++ b/Parity.cpp @@ -0,0 +1,21 @@ +# include +# define bool int +using namespace std; +bool getParity(unsigned int n) +{ + bool parity=0; + while (n) + { + parity=!parity; + n=n&(n-1); + } + return parity; +} +int main() +{ + unsigned int n; + cin>>n; + cout<<"Parity of no "< Date: Fri, 31 Jan 2020 23:19:21 +0530 Subject: [PATCH 15/17] Create Parity.cpp --- Himanshu Sharma/Parity.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Himanshu Sharma/Parity.cpp diff --git a/Himanshu Sharma/Parity.cpp b/Himanshu Sharma/Parity.cpp new file mode 100644 index 0000000..f791754 --- /dev/null +++ b/Himanshu Sharma/Parity.cpp @@ -0,0 +1,21 @@ +# include +# define bool int +using namespace std; +bool getParity(unsigned int n) +{ + bool parity=0; + while (n) + { + parity=!parity; + n=n&(n-1); + } + return parity; +} +int main() +{ + unsigned int n; + cin>>n; + cout<<"Parity of no "< Date: Fri, 31 Jan 2020 23:19:58 +0530 Subject: [PATCH 16/17] Delete Parity.cpp --- Parity.cpp | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 Parity.cpp diff --git a/Parity.cpp b/Parity.cpp deleted file mode 100644 index f791754..0000000 --- a/Parity.cpp +++ /dev/null @@ -1,21 +0,0 @@ -# include -# define bool int -using namespace std; -bool getParity(unsigned int n) -{ - bool parity=0; - while (n) - { - parity=!parity; - n=n&(n-1); - } - return parity; -} -int main() -{ - unsigned int n; - cin>>n; - cout<<"Parity of no "< Date: Sat, 1 Feb 2020 14:46:09 +0530 Subject: [PATCH 17/17] Create Issue76.c --- Himanshu Sharma/Issue76.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Himanshu Sharma/Issue76.c diff --git a/Himanshu Sharma/Issue76.c b/Himanshu Sharma/Issue76.c new file mode 100644 index 0000000..a074be1 --- /dev/null +++ b/Himanshu Sharma/Issue76.c @@ -0,0 +1,35 @@ +#include +void findSmallest(int n) +{ + int i, j=0; + int res[100]; + + if (n < 10) + { + printf("%d", n+10); + return; + } + for (i=9; i>1; i--) + { + while (n%i == 0) + { + n = n/i; + res[j] = i; + j++; + } + } + if (n > 10) + { + printf("Not possible"); + return; + } + for (i=j-1; i>=0; i--) + printf("%d", res[i]); +} +int main() +{ + int n; + scanf("%d",&n); + findSmallest(n); + return 0; +}