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 +#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/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; +} 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/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; +} 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/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 +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; +} 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; +} 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 "< +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; +} 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< +#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; +} 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; +} 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 +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<