├── C programs ├── Binarysearch.c ├── BubbleSort.c ├── ChangeTwoDigitInNumberInEnglish.c ├── Circularqueue.c ├── HelloWorld.c ├── Matrix Addition.c ├── MergeSort.c ├── Quicksort.c ├── SelectionSort.c ├── Square.c ├── bubble_sorting.c ├── cashier_problem.c ├── fabonicseries.c ├── factorial.c ├── fibonacci.c ├── infixtopostfix.c ├── leap_year.c ├── linkedlist.c ├── rockpaperandscissor.c ├── snakegame.c ├── stack.c ├── swap.c └── transpose.c ├── C++ programs ├── 1sCompliment.cpp ├── AntiClockWise_Print_of_Spiral_Printing.cpp ├── BacktrackingRatInMaze.cpp ├── C++ program to Create Spiral Matrix ├── C++ program to check Valid Shuffle ├── Create C++ Programs to check string rotation ├── HeapSort.cpp ├── InsertionSort.cpp ├── Kadane's__Algorithm.cpp ├── MaximumPathSum.cpp ├── MergeSort.cpp ├── Permutation.cpp ├── PowerOfTwoOrNot.cpp ├── ProductArrayPuzzle.cpp ├── RcursionRemovingDuplicates.cpp ├── RecursionCountMaze.cpp ├── RecursionCountPath.cpp ├── RecursionFirstAndLastOcc.cpp ├── RecursionGenerateAllSubstrings.cpp ├── RecursionGenerateSubstringsWithASCII.cpp ├── RecursionKeypad.cpp ├── RecursionKnapsackProblem.cpp ├── RecursionMoveXToEnd.cpp ├── RecursionNraisedP.cpp ├── RecursionPermuataionOfString.cpp ├── RecursionTowerOfHanoi.cpp ├── Running_sum.cpp ├── SelectionSort.cpp ├── SieveOfEratosthenes.cpp ├── SortingDnfSort.cpp ├── SortingWaveSort.cpp ├── SpiralOrderMatrixTraversal.cpp ├── TheOneWithAllTheCandy.cpp ├── Topological Sort in C++ ├── TransposeOfAMatrix.cpp ├── Trapping_Rainwater.cpp ├── UniqueNoInAnArray.cpp ├── access array elements.cpp ├── add to integers.cpp ├── add two numbers using functions.cpp ├── addition and subtraction of a 2-D matrix.cpp ├── addition of two matrices.cpp ├── age of person in years,week,days,hours.cpp ├── all prime numbers between 1 to n.cpp ├── alphabet pattern 1.cpp ├── alphabet pattern 2.cpp ├── alphabet pattern 3.cpp ├── alphabet pattern in v shape.cpp ├── alphabet pattern.cpp ├── alphabets pattern in inverted U shap.cpp ├── area of rectangle using functions.cpp ├── area of square using functions.cpp ├── armstrong number using functions.cpp ├── armstrong number.cpp ├── armstrong numbr using recursion.cpp ├── array using switch case.cpp ├── arrays using switch case.cpp ├── average of 5 numbers using pointers with no arguments, no returns.cpp ├── average of numbers using arrays.cpp ├── binary pattern.cpp ├── binary seach.cpp ├── binary_search.cpp ├── brracket_balance.cpp ├── bubblesort.cpp ├── calculate aggergate percentage of a student.cpp ├── calculate gross salary.cpp ├── calculate sum and average of first 10 integer numbers.cpp ├── calculate sum of odd and even from 1 to n using loops.cpp ├── call by reference using functions.cpp ├── character is vowel or consonant in string using pointers.cpp ├── check a given character is lower case alphabet or not.cpp ├── check a number is positive,negative,zero.cpp ├── check even or odd number.cpp ├── check odd or even using functions.cpp ├── check pime or not using functions.cpp ├── check vowel or consonant.cpp ├── check whether a input character if it is lowercase letter then convert to uppercase letter otherwise convert to lower case letter.cpp ├── check whether a triangle is valid or not.cpp ├── compute sum of all array elements.cpp ├── convert degree fahrenheit into degree celsius.cpp ├── convert distance in meters,feet,inches,centimeters.cpp ├── copy one array to another.cpp ├── cost price of an item.cpp ├── count how many times a number is present in an array.cpp ├── count number of positive,negative and zero in array.cpp ├── count positive,negative,zero elements in an aray.cpp ├── cross star pattern with value of n.cpp ├── cross star pattern.cpp ├── cube of a number using functions.cpp ├── date of birth of a person.cpp ├── delete element from an array.cpp ├── deleteMidElementOfStack.cpp ├── deletion of array elementys.cpp ├── determine a number is prime or not.cpp ├── editdistance.cpp ├── floyydwarshal.cpp ├── graph │ ├── bfs.cpp │ ├── bfsinc.cpp │ ├── bfst.cpp │ ├── bfstraversal.cpp │ ├── demo.cpp │ ├── dfs.cpp │ ├── dfsusingadjacencymatrix.cpp │ ├── implementationofbfs.cpp │ ├── implementationofdfs.cpp │ ├── implementationofgraph.cpp │ ├── implementbfs2.cpp │ ├── practicebst.cpp │ └── primsalgorithm.cpp ├── infix_to_postfix.cpp ├── insertion_in_cll.cpp ├── josephus_problem-death_circle.cpp ├── kthGrammer.cpp ├── pascal_matrix.cpp ├── prims_algo.cpp ├── print_row_from_pasacl.cpp ├── pythagorean_triplet.cpp ├── sortAnArray.cpp ├── sorting.cpp ├── stack_impemented_by_ll.cpp ├── subarrayAddingToS.cpp └── wave_print_2D.cpp ├── Java programs ├── BOOKCHEF.java ├── Binary Search.java ├── CombinationSum.java ├── LinkedList.java ├── NQueens.java ├── QuickSort.java ├── Rotate.java ├── SMPAIR.java ├── SelectionSort.java ├── TACHSTCK.java ├── TowerOfHanoi.java ├── armstrong.java ├── dog.java ├── find_path.java ├── gcd.java ├── linear.java ├── loopdetectioninLL.java ├── merge_sort.java ├── removeduplicates.java ├── stack.java ├── suduko.java ├── xoxo.java └── zerosumtriplet.java ├── LICENSE.md ├── Python ├── Calculator.py ├── Creating _cross.py ├── Python Program to check whether input is well-formatted └── Snake and Ladder │ ├── Snake_and_ladder.py │ └── snake_and_ladder.png ├── Readme.md └── Web Development ├── Calculator ├── index.html ├── script.js └── style.css ├── Digital StopWatch ├── app.js ├── index.html └── stylesheet.css ├── Password Strength Checker ├── app.js ├── index.html └── stylesheet.css ├── Rock Paper Scissors Game ├── app.js ├── download.jpg ├── g.jpg ├── index.html └── stylesheet.css ├── TIC-TAC-TOE ├── index.html ├── tic.css └── tic.js ├── Typing Speed Test ├── index.html ├── paragraphs.js ├── script.js └── style.css ├── file_handling ├── .gitignore ├── app.js ├── file_store.js ├── hello.text ├── meesage.txt ├── message.txt ├── package-lock.json └── package.json ├── loginPage ├── index.html └── style.css ├── netflix clone ├── index.html ├── script.js └── style.css ├── simpleTabs ├── index.html └── style.css ├── stylishStaticCV ├── Readme.md ├── images │ ├── Cat.webm │ ├── Productivity.png │ ├── clouds.png │ ├── favicon.ico │ └── mountain.png ├── index.html └── styles.css ├── toDoList ├── index.html ├── script.js ├── style.css └── trashbin.png └── todoslist project ├── index.html ├── script.js └── style.css /C programs/Binarysearch.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i, low, high, mid, n, key, array[100]; 5 | printf("Enter number of elements"); 6 | scanf("%d",&n); 7 | printf("Enter %d integers \n", n); 8 | for(i = 0; i < n; i++) 9 | scanf("%d",&array[i]); 10 | printf("Enter value to find \n"); 11 | scanf("%d", &key); 12 | low = 0; 13 | high = n - 1; 14 | mid = (low+high)/2; 15 | while (low <= high) { 16 | if(array[mid] < key) 17 | low = mid + 1; 18 | else if (array[mid] == key) { 19 | printf("%d found at location %d \n", key, mid+1); 20 | break; 21 | } 22 | else 23 | high = mid - 1; 24 | mid = (low + high)/2; 25 | } 26 | if(low > high) 27 | printf("Not found! %d isn't present in the list \n", key); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C programs/BubbleSort.c: -------------------------------------------------------------------------------- 1 | /* C program for Bubble sort */ 2 | #include 3 | void swap(int *x, int *y){ 4 | int temp = *x; 5 | *x = *y; 6 | *y = temp; 7 | } 8 | /*bubble sort */ 9 | void bubbleSort(int arr[], int n){ 10 | int i, j; 11 | for (i = 0; i < n-1; i++) 12 | // Last i elements are already in place 13 | for (j = 0; j < n-i-1; j++) 14 | if (arr[j] > arr[j+1]) 15 | swap(&arr[j], &arr[j+1]); 16 | } 17 | /* print an array */ 18 | void printArray(int arr[], int size){ 19 | int i; 20 | for (i=0; i < size; i++) 21 | printf("%d ", arr[i]); 22 | } 23 | int main(){ 24 | int arr[] = {64, 34, 25, 12, 22, 11, 90}; 25 | int n = sizeof(arr)/sizeof(arr[0]); 26 | bubbleSort(arr, n); 27 | printf("Sorted array: "); 28 | printArray(arr, n); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /C programs/ChangeTwoDigitInNumberInEnglish.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n, t; 5 | char n1[][11] = { "Ten","Eleven","Twelve","Thirteen","Fourteen","Sixteen","Seventeen","Eighteen","Nineteen" }; 6 | char n2[][10] = { "One","Two","Three","Four","Five","Six","Seven","Eight","Nine" }; 7 | char n3[][10] = { "Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety" }; 8 | 9 | printf("Enter a Two Digit Number\n"); 10 | scanf_s("%d", &n); 11 | if (n<10||n>99||n==0){ 12 | printf("Please Enter the valid Two Digit Number"); 13 | } 14 | else { 15 | if (n < 20) { 16 | t = n % 10; 17 | printf("%s",n1[t]); 18 | } 19 | else if (n >=20){ 20 | t = n % 10; 21 | int t1 = n / 10; 22 | if (n % 10 == 0) 23 | { 24 | printf("%s", n3[t1 - 2]); 25 | } 26 | else { 27 | printf("%s %s", n3[t1 - 2], n2[t-1]); 28 | } 29 | } 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /C programs/HelloWorld.c: -------------------------------------------------------------------------------- 1 | //Run the ``hello world'' program on your system. Experiment with leaving out parts of the program. 2 | #include 3 | 4 | int main() { 5 | 6 | /* printf("Hello world Shweta"); //first Method 7 | */ 8 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 9 | /* 10 | printf("Hello,"); 11 | printf("world"); //Second Method 12 | */ 13 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 14 | /* 15 | printf("Hello World\"Shweta\""); //Third Method 16 | */ 17 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 18 | /* 19 | for(;printf("Hello World");)break; //Fourth Method 20 | */ 21 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 22 | /* 23 | void fun(void){ 24 | printf("Hello World"); 25 | } 26 | fun(); //Fivth Method 27 | */ 28 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29 | /* 30 | #define a "Hello World" 31 | printf("%s",a); //Sixth Method 32 | */ 33 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 34 | /* 35 | if(1){ 36 | printf("Hello World"); //Seven Method 37 | } 38 | */ 39 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 40 | /* 41 | if(1<<0){ 42 | printf("Hello World"); //Eigth Method 43 | } 44 | */ 45 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 46 | /* 47 | switch(1<<0){ 48 | case 1: 49 | printf("Hello World"); //Nine Method 50 | } 51 | */ 52 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 53 | 54 | /* 55 | char a[15]={"Hello World"}; 56 | printf("%s",a); //Ten Method 57 | */ 58 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 59 | 60 | /* 61 | char a[][15]={"Hello","World"}; 62 | printf("%s %s",a,a[1]); //Eleven Method 63 | */ 64 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 65 | 66 | /* 67 | char a[][15]={'H','e','l','l','o',' ','W','o','r','l','d'}; 68 | printf("%s",a); //Twelve Method 69 | */ 70 | //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /C programs/Matrix Addition.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int a[100][100],b[100][100],d[100][100],i,j,r,c; 5 | printf("enter the no. row :"); 6 | scanf("%d",&r); 7 | printf("\nenter the no. of coloumn :"); 8 | scanf("%d",&c); 9 | for(i=0;i<=r;i++) 10 | {for(j=0;j<=c;j++) 11 | scanf("\n%d\n",&a[i][j]); 12 | } 13 | printf("\n"); 14 | 15 | for(i=0;i<=r;i++) 16 | {for(j=0;j<=c;j++) 17 | scanf("\n%d\n",&b[i][j]); 18 | } 19 | printf("\n"); 20 | 21 | for(i=0;i<=r;i++) 22 | for(j=0;j<=c;j++) 23 | d[i][j]=a[i][j]+b[i][j]; 24 | for(i=0;i<=r;i++) 25 | { 26 | printf("\n"); 27 | for(j=0;j<=c;j++) 28 | printf("the add of two matrix is %d \n",d[i][j]); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /C programs/MergeSort.c: -------------------------------------------------------------------------------- 1 | /* Program to sort the number by using Merge sort*/ 2 | #include 3 | #define max 10 4 | 5 | int a[11] = { 10, 14, 19, 26, 27, 31, 33, 35, 42, 44, 0 }; 6 | int b[10]; 7 | void merging(int low, int mid, int high) { 8 | int l1, l2, i; 9 | 10 | for(l1 = low, l2 = mid + 1, i = low; l1 <= mid && l2 <= high; i++) { 11 | if(a[l1] <= a[l2]) 12 | b[i] = a[l1++]; 13 | else 14 | b[i] = a[l2++]; 15 | } 16 | while(l1 <= mid) 17 | b[i++] = a[l1++]; 18 | 19 | while(l2 <= high) 20 | b[i++] = a[l2++]; 21 | 22 | for(i = low; i <= high; i++) 23 | a[i] = b[i]; 24 | } 25 | void sort(int low, int high) { 26 | int mid; 27 | if(low < high) { 28 | mid = (low + high) / 2; 29 | sort(low, mid); 30 | sort(mid+1, high); 31 | merging(low, mid, high); 32 | } else { 33 | return; 34 | } 35 | } 36 | 37 | int main() { 38 | int i; 39 | printf("List before sorting\n"); 40 | for(i = 0; i <= max; i++) 41 | printf("%d ", a[i]); 42 | sort(0, max); 43 | printf("\nList after sorting\n"); 44 | for(i = 0; i <= max; i++) 45 | printf("%d ", a[i]); 46 | } -------------------------------------------------------------------------------- /C programs/Quicksort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void quicksort(int nums[],int low, int high) 4 | { 5 | if(low>=high) 6 | { 7 | return; 8 | } 9 | int start=low; 10 | int end=high; 11 | int mid=(start+end)/2; 12 | int pivot=nums[mid]; 13 | while(start<=end) 14 | { 15 | while(nums[start]pivot) 20 | { 21 | end--; 22 | } 23 | if(start<=end) 24 | { 25 | int temp=nums[start]; 26 | nums[start]=nums[end]; 27 | nums[end]=temp; 28 | start++; 29 | end--; 30 | } 31 | } 32 | quicksort(nums,low,end); 33 | quicksort(nums,start,high); 34 | } 35 | 36 | int main() 37 | { 38 | int n; 39 | scanf("%d",&n); 40 | int nums[n]; 41 | int i,j; 42 | for(i=0;i 3 | void swap(int *x, int *y){ 4 | int temp = *x; 5 | *x = *y; 6 | *y = temp; 7 | } 8 | void selectionSort(int arr[], int n){ 9 | int i, j, min_idx; 10 | for (i = 0; i < n-1; i++){ 11 | min_idx = i; 12 | for (j = i+1; j < n; j++) 13 | if (arr[j] < arr[min_idx]) 14 | min_idx = j; 15 | swap(&arr[min_idx], &arr[i]); 16 | } 17 | } 18 | /* Print the array*/ 19 | void printArray(int arr[], int size){ 20 | int i; 21 | for (i=0; i < size; i++) 22 | printf("%d ", arr[i]); 23 | printf("\n"); 24 | } 25 | int main(){ 26 | int arr[] = {64, 25, 12, 22, 11}; 27 | int n = sizeof(arr)/sizeof(arr[0]); 28 | selectionSort(arr, n); 29 | printf("Sorted array: \n"); 30 | printArray(arr, n); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /C programs/Square.c: -------------------------------------------------------------------------------- 1 | #include 2 | //create the function f, fderivative, CalculateSquare function 3 | double f(double x, double c) { 4 | return (x*x) - c; 5 | } 6 | double fderivative(double x) { 7 | return 2 * x; 8 | } 9 | double CalculateSquare(double x, int iter, double(*f)(double, double), double(*fd)(double)) {//call the value 10 | double xc = x;//assign value 11 | //created a loop for iteration 12 | for (int i = 0; i < iter; i++) { 13 | //call the function f,fderivative and divides both(f/fd) after substract with root(x) value 14 | x -= (f(x, xc) / fd(x)); 15 | } 16 | return x; 17 | } 18 | 19 | int main() 20 | { 21 | double root; 22 | do { 23 | printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< \n"); 24 | printf("Enter a number you want to calculate the root of: \n"); 25 | if (scanf("%lf", &root)) { 26 | double rootPrint = root; 27 | root = CalculateSquare(root, 6, f, fderivative); 28 | printf("The root of %.4lf is: %.4lf\n", rootPrint, root); 29 | } 30 | } while (1); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /C programs/bubble_sorting.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int a[100],n,intial=0,final=n-1,i,temp,j; 5 | printf("enter the value size :"); 6 | scanf("%d",&n); 7 | printf("\n enter the elements of arrays:\n"); 8 | for(i=0;i0;i--) 16 | { 17 | for(j=0;j<=i;j++) 18 | { 19 | if(a[j]>a[j+1]) 20 | {temp=a[j]; 21 | a[j]=a[j+1]; 22 | a[j+1]=temp; 23 | } 24 | } 25 | } 26 | printf("sorted array in asscending order:\n"); 27 | for(i=0;i0;i--) 34 | { 35 | printf("\n"); 36 | printf("a[%d]=%d",i,a[i]); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /C programs/cashier_problem.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int a,b,c,d,e,f,x; 5 | printf("enter the value of x:"); 6 | scanf("%d",&x); 7 | 8 | if(x<10000) 9 | { 10 | a=x/1000; 11 | printf("Number of 1000 notes are:%d\n",a); 12 | b=x%1000; 13 | c=b/100; 14 | printf("Number of 100 notes are:%d\n",c); 15 | d=b%100; 16 | e=d/10; 17 | printf("Number of 10 notes are:%d\n",e); 18 | f=d%10; 19 | printf("Number of 1 rs coins are:%d\n",f); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /C programs/fabonicseries.c: -------------------------------------------------------------------------------- 1 | #include 2 | main() 3 | { 4 | int a=0,b=1,sum,n,i; 5 | printf("enter the value for which you wants fabonic series:"); 6 | scanf("%d",&n); 7 | printf("the fabonic series of %d are:\n",n); 8 | for(i=0;i 2 | int main() { 3 | int n, i; 4 | unsigned long long fact = 1; 5 | printf("Enter an integer: "); 6 | scanf("%d", &n); 7 | 8 | // shows error if the user enters a negative integer 9 | if (n < 0) 10 | printf("Error! Factorial of a negative number doesn't exist."); 11 | else { 12 | for (i = 1; i <= n; ++i) { 13 | fact *= i; 14 | } 15 | printf("Factorial of %d = %llu", n, fact); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C programs/fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int i, n; 6 | 7 | // initialize first and second terms 8 | int t1 = 0, t2 = 1; 9 | 10 | // initialize the next term (3rd term) 11 | int nextTerm = t1 + t2; 12 | 13 | // get no. of terms from user 14 | printf("Enter the number of terms: "); 15 | scanf("%d", &n); 16 | 17 | // print the first two terms t1 and t2 18 | printf("Fibonacci Series: %d, %d, ", t1, t2); 19 | 20 | // print 3rd to nth terms 21 | for (i = 3; i <= n; ++i) { 22 | printf("%d, ", nextTerm); 23 | t1 = t2; 24 | t2 = nextTerm; 25 | nextTerm = t1 + t2; 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /C programs/infixtopostfix.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define MAX 100 5 | 6 | char stack[MAX]; 7 | int top = -1; 8 | 9 | void push(char ch) 10 | { 11 | stack[++top] = ch; 12 | } 13 | 14 | char pop() 15 | { 16 | return stack[top--]; 17 | } 18 | 19 | int priority(char ch) 20 | { 21 | if (ch == '(') 22 | return 0; 23 | if (ch == '+' || ch == '-') 24 | return 1; 25 | if (ch == '*' || ch == '/' || ch == '%') 26 | return 2; 27 | if (ch == '^') 28 | return 3; 29 | } 30 | 31 | int main() 32 | { 33 | char infix[MAX], postfix[MAX], ch; 34 | int i = 0, j = 0; 35 | printf("Enter the infix expression:"); 36 | gets(infix); 37 | while ((ch = infix[i++]) != '\0') 38 | { 39 | if (ch == '(') 40 | push(ch); 41 | else if (isalnum(ch)) 42 | postfix[j++] = ch; 43 | else if (ch == ')') 44 | { 45 | while (stack[top] != '(') 46 | postfix[j++] = pop(); 47 | pop(); 48 | } 49 | else 50 | { 51 | while (priority(stack[top]) >= priority(ch)) 52 | postfix[j++] = pop(); 53 | push(ch); 54 | } 55 | } 56 | while (top != -1) 57 | postfix[j++] = pop(); 58 | postfix[j] = '\0'; 59 | printf("The postfix expression is:"); 60 | puts(postfix); 61 | return 0; 62 | } 63 | 64 | // OUTPUT 65 | 66 | // Enter the infix expression:a+b*c 67 | // The postfix expression is:abc*+ 68 | 69 | // Enter the infix expression:a+b*(c^d-e)^(f+g*h)-i 70 | // The postfix expression is:abcd^e-fgh*+^*+i- 71 | 72 | // Enter the infix expression:(a+b)*c-(d-e)*(f+g) 73 | // The postfix expression is:ab+c*de-fg+*- 74 | 75 | // Enter the infix expression:a+b*c-d/e 76 | // The postfix expression is:abc*+de/ -------------------------------------------------------------------------------- /C programs/leap_year.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int a; 5 | printf("enter the year:"); 6 | scanf("%d",&a); 7 | 8 | if((a%4==0)&&(a%100!=0)||(a/400==0)) 9 | { 10 | printf("it is an leap year\n"); 11 | } 12 | else 13 | 14 | printf("it is not an leap year"); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /C programs/rockpaperandscissor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int rockpaperscissor(char you,char comp){ 6 | if (you==comp){ 7 | return 0; 8 | } 9 | if (you=='r' && comp=='p'){ 10 | return -1; 11 | } 12 | else if (you=='r' && comp=='s'){ 13 | return 1; 14 | } 15 | if (you=='p' && comp=='s'){ 16 | return -1; 17 | } 18 | else if (you=='p' && comp=='r'){ 19 | return 1; 20 | } 21 | if (you=='s' && comp=='r'){ 22 | return -1; 23 | } 24 | else if (you=='s' && comp=='p'){ 25 | return 1; 26 | } 27 | } 28 | int main (){ 29 | char you,comp; 30 | srand(time(0)); 31 | int number = rand()%100 + 1; 32 | if(number<33){ 33 | comp='r'; 34 | } 35 | else if(number>33 && number<66){ 36 | comp='p'; 37 | } 38 | else{ 39 | comp='s'; 40 | } 41 | printf("Choose Between r,p And s\n"); 42 | scanf("%c", &you); 43 | int result= rockpaperscissor(you,comp); 44 | printf("You chose %c and computer chose %c\n",you,comp); 45 | if(result==1){ 46 | printf("You won this Game\n"); 47 | } 48 | else if(result==-1){ 49 | printf("You loss this Game\n"); 50 | } 51 | else{ 52 | printf("Game draws\n"); 53 | } 54 | return 0; 55 | } -------------------------------------------------------------------------------- /C programs/snakegame.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int i, j, height = 20, width = 20; 8 | int gameover, score; 9 | int x, y, fruitx, fruity, flag; 10 | 11 | void setup() 12 | { 13 | gameover = 0; 14 | 15 | x = height / 2; 16 | y = width / 2; 17 | label1: 18 | fruitx = rand() % 20; 19 | if (fruitx == 0) 20 | goto label1; 21 | label2: 22 | fruity = rand() % 20; 23 | if (fruity == 0) 24 | goto label2; 25 | score = 0; 26 | } 27 | 28 | 29 | void draw() 30 | { 31 | system("cls"); 32 | for (i = 0; i < height; i++) { 33 | for (j = 0; j < width; j++) { 34 | if (i == 0 || i == width - 1 35 | || j == 0 36 | || j == height - 1) { 37 | printf("#"); 38 | } 39 | else { 40 | if (i == x && j == y) 41 | printf("0"); 42 | else if (i == fruitx 43 | && j == fruity) 44 | printf("*"); 45 | else 46 | printf(" "); 47 | } 48 | } 49 | printf("\n"); 50 | } 51 | 52 | 53 | printf("score = %d", score); 54 | printf("\n"); 55 | printf("press X to quit the game"); 56 | } 57 | 58 | 59 | void input() 60 | { 61 | if (kbhit()) { 62 | switch (getch()) { 63 | case 'a': 64 | flag = 1; 65 | break; 66 | case 's': 67 | flag = 2; 68 | break; 69 | case 'd': 70 | flag = 3; 71 | break; 72 | case 'w': 73 | flag = 4; 74 | break; 75 | case 'x': 76 | gameover = 1; 77 | break; 78 | } 79 | } 80 | } 81 | 82 | void logic() 83 | { 84 | sleep(0.01); 85 | switch (flag) { 86 | case 1: 87 | y--; 88 | break; 89 | case 2: 90 | x++; 91 | break; 92 | case 3: 93 | y++; 94 | break; 95 | case 4: 96 | x--; 97 | break; 98 | default: 99 | break; 100 | } 101 | 102 | if (x < 0 || x > height 103 | || y < 0 || y > width) 104 | gameover = 1; 105 | 106 | if (x == fruitx && y == fruity) { 107 | label3: 108 | fruitx = rand() % 20; 109 | if (fruitx == 0) 110 | goto label3; 111 | 112 | label4: 113 | fruity = rand() % 20; 114 | if (fruity == 0) 115 | goto label4; 116 | score += 10; 117 | } 118 | } 119 | 120 | 121 | void main() 122 | { 123 | int m, n; 124 | 125 | 126 | setup(); 127 | 128 | while (!gameover) { 129 | 130 | draw(); 131 | input(); 132 | logic(); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /C programs/stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define max 10 3 | int st[max],top=-1; 4 | 5 | void push(int st[],int val); 6 | int pop(int st[]); 7 | int peek(int st[]); 8 | void display(int st[]); 9 | 10 | int main (){ 11 | int val,option; 12 | do{ 13 | printf("\n*****MAIN MENU*****"); 14 | printf("\n 1. PUSH"); 15 | printf("\n 2. POP"); 16 | printf("\n 3. PEEK"); 17 | printf("\n 4. Size"); 18 | printf("\n 5. Display"); 19 | printf("\n 6. Exit"); 20 | printf("\n Enter your option : "); 21 | scanf("%d",&option); 22 | switch (option){ 23 | case 1: 24 | printf("\n Enter the value to be pushed : "); 25 | scanf("%d",&val); 26 | push(st,val); 27 | break; 28 | case 2: 29 | val=pop(st); 30 | if(val!=-1){ 31 | printf("\n The value deleted from the stack is %d",val); 32 | } 33 | break; 34 | case 3: 35 | val=peek(st); 36 | if(val!=-1){ 37 | printf("\n The value at the top of stack is %d",val); 38 | } 39 | break; 40 | case 4: 41 | printf("Size of stack: %d",top+1); 42 | break; 43 | case 5: 44 | display(st); 45 | break; 46 | case 6: 47 | break; 48 | default: 49 | printf("Invalid Choice"); 50 | break; 51 | } 52 | } while(option !=5); 53 | return 0; 54 | } 55 | 56 | void push(int st[],int val){ 57 | if(top==max-1){ 58 | printf("\n STACK OVERFLOW"); 59 | } 60 | else{ 61 | top++; 62 | st[top]=val; 63 | } 64 | } 65 | 66 | int pop(int st[]){ 67 | int val; 68 | if(top==-1){ 69 | printf("\n STACK UNDERFLOW"); 70 | return -1; 71 | } 72 | else{ 73 | val=st[top]; 74 | top--; 75 | return val; 76 | } 77 | } 78 | 79 | int peek(int st[]){ 80 | if(top==-1){ 81 | printf("\n STACK EMPTY"); 82 | return -1; 83 | } 84 | else{ 85 | return st[top]; 86 | } 87 | } 88 | 89 | void display(int st[]){ 90 | if(top==-1){ 91 | printf("\n STACK EMPTY"); 92 | } 93 | else{ 94 | for(int i=top;i>=0;i--){ 95 | printf("%d ",st[i]); 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /C programs/swap.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void swap(int *x,int *y) 4 | { 5 | *x=*x+*y; 6 | *y=*x-*y; 7 | *x=*x-*y; 8 | } 9 | void main() 10 | { 11 | int a=0,b=0; 12 | printf("Enter the two numbers to be swapped:\n"); 13 | scanf("%d",&a); 14 | scanf("%d",&b); 15 | swap(&a,&b); 16 | printf("The numbers after swapped are:\n"); 17 | printf("a=%d\tb=%d",a,b); 18 | } 19 | -------------------------------------------------------------------------------- /C programs/transpose.c: -------------------------------------------------------------------------------- 1 | /*c program to find transpose of a matrix */ 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int p, q, c, d, mat[10][10], tra[10][10]; 8 | 9 | printf("Enter the number of rows and columns of a matrix\n"); 10 | scanf("%d%d", &p, &q); 11 | printf("Enter elements of the matrix\n"); 12 | 13 | for (c = 0; c < p; c++) 14 | for (d = 0; d < q; d++) 15 | scanf("%d", &mat[c][d]); 16 | 17 | for (c = 0; c < p; c++) 18 | for (d = 0; d < q; d++) 19 | tra[d][c] = mat[c][d]; 20 | 21 | printf("Transpose of the matrix:\n"); 22 | 23 | for (c = 0; c < q; c++) { 24 | 25 | for (d = 0; d < p; d++) 26 | 27 | printf("%d\t", tra[c][d]); 28 | 29 | printf("\n"); 30 | } 31 | 32 | return 0; 33 | } 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /C++ programs/1sCompliment.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Given an N bit binary number, find the 1's complement of the number. 3 | The ones' complement of a binary number is defined as the value obtained by inverting all the bits in the binary representation of the number 4 | (swapping 0s for 1s and vice versa). 5 | 6 | 7 | Example: 8 | 9 | Input: 10 | N = 3 11 | S = 101 12 | 13 | Output: 14 | 010 15 | Explanation: 16 | We get the output by converting 1's in S 17 | to 0 and 0s to 1 18 | 19 | */ 20 | 21 | #include 22 | using namespace std; 23 | 24 | class Solution{ 25 | public: 26 | string onesComplement(string S,int N){ 27 | 28 | for(int i=0;i>t; 39 | while(t--) 40 | { 41 | int n; 42 | cin>>n; 43 | string s; 44 | cin>>s; 45 | Solution ob; 46 | cout< 2 | using namespace std; 3 | 4 | void AntiSpiral(int A[][100],int r,int c) 5 | { 6 | int startRow=0; 7 | int endRow=r-1; 8 | int startCol=0; 9 | int endCol=c-1; 10 | 11 | while(startRow<=endRow && startCol<=endCol) 12 | { 13 | for(int i=startRow;i<=endRow;i++) 14 | { 15 | cout<=startRow;i--) 26 | { 27 | cout<=startCol;i--) 32 | { 33 | cout<>row>>col; 44 | 45 | int A[100][100]={0}; 46 | 47 | for(int i=0;i>A[i][j]; 52 | } 53 | } 54 | 55 | AntiSpiral(A,row,col); 56 | } -------------------------------------------------------------------------------- /C++ programs/BacktrackingRatInMaze.cpp: -------------------------------------------------------------------------------- 1 | /* We are given an 2d array of 0 and 1, and we have to find the path which the cat should follow to reach the destination..*/ 2 | 3 | #include 4 | using namespace std; 5 | 6 | bool isSafe(int** arr, int x, int y, int n) 7 | { 8 | if(x>n; 46 | 47 | int** arr= new int*[n]; 48 | for(int i=0;i>arr[i][j]; 58 | } 59 | } 60 | 61 | int** solArr=new int*[n]; 62 | for(int i=0;i 5 | using namespace std; 6 | int main() 7 | { 8 | int r,c; 9 | cin>>r>>c; 10 | int mat[r][c]; 11 | for(int i=0; i>mat[i][j]; 14 | } 15 | } 16 | 17 | int rowstart = 0, rowend= r-1, columnstart=0, columnend=c-1; 18 | while(rowstart<=rowend && columnstart<=columnend){ 19 | 20 | for(int j=columnstart ; j<=columnend; j++){ 21 | cout<=columnstart; j--){ 33 | cout<=rowstart; i--){ 39 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string s1, s2, res; 7 | cin >> s1; 8 | cin >> s2; 9 | cin >> res; 10 | int n1 = s1.size(); 11 | int n2 = s2.size(); 12 | int nr = res.size(); 13 | int f1 = 0, f2=0; 14 | if (nr != n1 + n2) 15 | { 16 | cout << "No" << endl; 17 | } 18 | else 19 | { 20 | int i = 0, j = 0, k = 0; 21 | while (k < nr) 22 | { 23 | 24 | if (i < n1 && res[k] == s1[i]) 25 | { 26 | i++; 27 | k++; 28 | } 29 | else if (j < n2 && res[k] == s2[j]) 30 | { 31 | j++; 32 | k++; 33 | } 34 | else 35 | { 36 | f1 = 1; 37 | break; 38 | } 39 | } 40 | } 41 | 42 | if (f1 == 1) 43 | { 44 | int i = 0, j = 0, k = 0; 45 | while (k < nr){ 46 | 47 | if (i < n2 && res[k] == s2[i]) 48 | { 49 | i++; 50 | k++; 51 | } 52 | else if (j < n1 && res[k] == s1[j]) 53 | { 54 | j++; 55 | k++; 56 | } 57 | else 58 | { 59 | f2 = 1; 60 | break; 61 | } 62 | } 63 | } 64 | 65 | if (f1==0 || f2==0) 66 | { 67 | cout << "Yes" << endl; 68 | } 69 | else 70 | { 71 | cout << "No" << endl; 72 | } 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /C++ programs/Create C++ Programs to check string rotation: -------------------------------------------------------------------------------- 1 | //check if s1 s2 are rotations of each other or not 2 | 3 | #include 4 | using namespace std; 5 | 6 | //will not work if string contains dupliacte characters like ABACD 7 | bool checkRotation(string s1, string s2){ 8 | 9 | int n1= s1.size(); 10 | int n2= s2.size(); 11 | 12 | if(n1!=n2){ 13 | return false; 14 | 15 | } 16 | 17 | int rotateby=-1; 18 | 19 | //get the index of the 1st char of s1 in s2 20 | for(int i=0; i>s1; 67 | cout<<"Enter string s2: "; 68 | cin>>s2; 69 | 70 | // cout< 3 | using namespace std; 4 | 5 | // Code By Manan 6 | void heapify(int arr[], int n, int i) 7 | { 8 | int largest = i; 9 | int l = 2 * i + 1; 10 | int r = 2 * i + 2; 11 | 12 | if (l < n && arr[l] > arr[largest]) 13 | largest = l; 14 | 15 | if (r < n && arr[r] > arr[largest]) 16 | largest = r; 17 | 18 | if (largest != i) { 19 | swap(arr[i], arr[largest]); 20 | 21 | heapify(arr, n, largest); 22 | } 23 | } 24 | 25 | // Code By Manan 26 | void heapSort(int arr[], int n) 27 | { 28 | 29 | for (int i = n / 2 - 1; i >= 0; i--) 30 | heapify(arr, n, i); 31 | 32 | for (int i = n - 1; i >= 0; i--) { 33 | swap(arr[0], arr[i]); 34 | 35 | heapify(arr, i, 0); 36 | } 37 | } 38 | 39 | // Code By Manan 40 | void printArray(int arr[], int n) 41 | { 42 | for (int i = 0; i < n; ++i) 43 | cout << arr[i] << " "; 44 | cout << "\n"; 45 | } 46 | 47 | 48 | // Code By Manan 49 | int main() 50 | { 51 | int arr[] = { 12, 11, 13, 5, 6, 7 }; 52 | int n = sizeof(arr) / sizeof(arr[0]); 53 | 54 | heapSort(arr, n); 55 | 56 | cout << "Sorted array is \n"; 57 | printArray(arr, n); 58 | } 59 | -------------------------------------------------------------------------------- /C++ programs/InsertionSort.cpp: -------------------------------------------------------------------------------- 1 | /*C++ Programme for the insertion sort*/ 2 | #include 3 | using namespace std; 4 | 5 | void InsertionSort(int arr[], int n) 6 | { 7 | for(int i=1;i0 && arr[j]>key) 12 | { 13 | arr[j+1]=arr[j]; 14 | j--; 15 | } 16 | arr[j+1]=key; 17 | } 18 | } 19 | 20 | int main() 21 | { 22 | int n; 23 | cin>>n; 24 | int arr[n]; 25 | for(int i=0;i>arr[i]; 28 | } 29 | 30 | InsertionSort(arr, n); 31 | 32 | for(int i=0;i 7 | using namespace std; 8 | 9 | int maxSubArraySum(int a[], int size) 10 | { 11 | int max_so_far = INT_MIN, max_ending_here = 0; 12 | 13 | for (int i = 0; i < size; i++) { 14 | max_ending_here = max_ending_here + a[i]; 15 | if (max_so_far < max_ending_here) 16 | max_so_far = max_ending_here; 17 | 18 | if (max_ending_here < 0) 19 | max_ending_here = 0; 20 | } 21 | return max_so_far; 22 | } 23 | 24 | // Driver Code 25 | int main() 26 | { 27 | int a[] = { -2, -3, 4, -1, -2, 1, 5, -3 }; 28 | int n = sizeof(a) / sizeof(a[0]); 29 | 30 | // Function Call 31 | int max_sum = maxSubArraySum(a, n); 32 | cout << "Maximum contiguous sum is " << max_sum; 33 | return 0; 34 | } 35 | 36 | 37 | //Time Complexity: O(N) 38 | // Auxiliary Space: O(1) -------------------------------------------------------------------------------- /C++ programs/MaximumPathSum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxi = INT_MIN; 4 | int solve(TreeNode* root) { 5 | if(!root)return 0; 6 | int lsubtreesum = max(0, solve(root->left)); 7 | int rightsubtreesum = max(0, solve(root->right)); 8 | maxi = max(maxi, lsubtreesum + rightsubtreesum + root->val); 9 | return max(lsubtreesum, rightsubtreesum) + root->val; 10 | } 11 | 12 | int maxPathSum(TreeNode* root) { 13 | if(!root)return 0; 14 | solve(root); 15 | return maxi; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /C++ programs/MergeSort.cpp: -------------------------------------------------------------------------------- 1 | /*C++ Programme for the merge sort*/ 2 | #include 3 | using namespace std; 4 | 5 | void Merge(int a[], int low, int mid, int high) 6 | { 7 | int n1=mid-low+1, n2=high-mid; 8 | int left[n1], right[n2]; 9 | for(int i=0;il) 48 | { 49 | int m= l + (r-l)/2; 50 | MergeSort(arr, l ,m); 51 | MergeSort(arr, m+1, r); 52 | Merge(arr,l,m,r); 53 | 54 | } 55 | } 56 | 57 | int main() 58 | { 59 | int n; 60 | cin>>n; 61 | int arr[n]; 62 | for(int i=0;i>arr[i]; 65 | } 66 | 67 | MergeSort(arr, 0, n); 68 | 69 | for(int i=0;i& nums, vector>&ans, 4 | vector&freq, vector&ds){ 5 | if(ds.size() == nums.size()){ 6 | ans.push_back(ds); 7 | return; 8 | } 9 | 10 | for(int i = 0 ; i < nums.size() ; i++){ 11 | if(!freq[i]){ 12 | freq[i] = 1; 13 | ds.push_back(nums[i]); 14 | permute(nums, ans, freq, ds); 15 | freq[i] = 0; 16 | ds.pop_back(); 17 | } 18 | } 19 | } 20 | public: 21 | vector> permute(vector& nums) { 22 | vector>ans; 23 | vectords, freq(10,0); 24 | permute(nums, ans, freq, ds); 25 | return ans; 26 | } 27 | }; -------------------------------------------------------------------------------- /C++ programs/PowerOfTwoOrNot.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool ispowerof2 (int n) 5 | { 6 | return (n && !(n & n-1)); 7 | } 8 | 9 | int main() 10 | { 11 | int n; 12 | cin>>n; 13 | cout< 5 | using namespace std; 6 | 7 | 8 | 9 | // } Driver Code Ends 10 | //User function template for C++ 11 | 12 | class Solution{ 13 | public: 14 | // nums: given vector 15 | // return the Product vector P that hold product except self at each index 16 | vector productExceptSelf(vector& nums, int n) { 17 | 18 | //code here 19 | long long int pr=1; 20 | long long int count=0; 21 | for(long long int i=0;i p(n); 35 | for(long long int i=0;i1) 46 | { 47 | p[i]= 0; 48 | } 49 | else 50 | { 51 | p[i]= pr/nums[i]; 52 | } 53 | } 54 | 55 | return p; 56 | } 57 | }; 58 | 59 | 60 | // { Driver Code Starts. 61 | int main() 62 | { 63 | int t; // number of test cases 64 | cin>>t; 65 | while(t--) 66 | { 67 | int n; // size of the array 68 | cin>>n; 69 | vector arr(n),vec(n); 70 | 71 | for(int i=0;i>arr[i]; 74 | } 75 | Solution obj; 76 | vec = obj.productExceptSelf(arr,n); // function call 77 | 78 | for(int i=0;i 2 | #include 3 | 4 | using namespace std; 5 | 6 | string removeDup(string s) 7 | { 8 | if(s.length()==0) 9 | { 10 | return ""; 11 | } 12 | 13 | char ch=s[0]; 14 | string ans = removeDup(s.substr(1)); 15 | 16 | if(ch==ans[0]) 17 | { 18 | return ans; 19 | } 20 | else 21 | return ch+ans; 22 | } 23 | 24 | int main() 25 | { 26 | cout< 2 | using namespace std; 3 | 4 | int countPathMaze(int n, int i, int j) 5 | { 6 | if(i==n-1 && j==n-1) 7 | { 8 | return 1; 9 | } 10 | if(i>=n || j>=n) 11 | { 12 | return 0; 13 | } 14 | 15 | return countPathMaze(n, i+1, j) + countPathMaze(n, i, j+1); 16 | } 17 | 18 | int main() 19 | { 20 | cout< 2 | using namespace std; 3 | 4 | int countPath(int s, int e) 5 | { 6 | if(s==e) 7 | { 8 | return 1; 9 | } 10 | else if(s>e) 11 | { 12 | return 0; 13 | } 14 | else 15 | { 16 | int count=0; 17 | for(int i=1;i<=6;i++) 18 | { 19 | count+= countPath(s+i, e); 20 | } 21 | return count; 22 | } 23 | } 24 | int main() 25 | { 26 | cout< 3 | using namespace std; 4 | 5 | int firstOcc(int arr[], int n, int i, int key) 6 | { 7 | if(i==n) 8 | { 9 | return -1; 10 | } 11 | if(arr[i]==key) 12 | { 13 | return i; 14 | } 15 | return firstOcc(arr, n, i+1, key); 16 | } 17 | 18 | int lastOcc(int arr[], int n, int i, int key) 19 | { 20 | if(i==n) 21 | { 22 | return -1; 23 | } 24 | 25 | int restArray = lastOcc(arr, n, i+1, key); 26 | if(restArray!=-1) 27 | { 28 | return restArray; 29 | } 30 | if(arr[i]==key) 31 | { 32 | return i; 33 | } 34 | return -1; 35 | 36 | } 37 | int main() 38 | { 39 | int arr[] = {4,2,1,2,5,2,7}; 40 | cout< 2 | #include 3 | 4 | using namespace std; 5 | 6 | void subseq(string s, string ans) 7 | { 8 | if(s.length()==0) 9 | { 10 | cout< 2 | #include 3 | 4 | using namespace std; 5 | 6 | void subseq(string s, string ans) 7 | { 8 | if(s.length()==0) 9 | { 10 | cout< 2 | #include 3 | using namespace std; 4 | 5 | string keypadArr[] = {"", "./", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; 6 | 7 | void keypad(string s, string ans) 8 | { 9 | if(s.length()==0) 10 | { 11 | cout< 2 | using namespace std; 3 | 4 | int knapsack(int value[], int wt[], int n, int W) 5 | { 6 | if(n==0 || W==0) 7 | { 8 | return 0; 9 | } 10 | 11 | if(wt[n-1]>W) 12 | { 13 | return knapsack(value, wt, n-1, W); 14 | } 15 | 16 | return max(knapsack(value, wt, n-1, W-wt[n-1])+value[n-1], knapsack(value, wt, n-1, W)); 17 | } 18 | 19 | int main() 20 | { 21 | int wt[]= {10, 20, 30}; 22 | int value[]= {100, 50, 150}; 23 | int W=50; 24 | 25 | cout< 2 | #include 3 | using namespace std; 4 | 5 | string MoveallX(string s) 6 | { 7 | if(s.length()==0) 8 | { 9 | return ""; 10 | } 11 | 12 | char ch=s[0]; 13 | string ans = MoveallX(s.substr(1)); 14 | 15 | if(ch=='x') 16 | { 17 | return ans+ch; 18 | } 19 | else 20 | return ch+ans; 21 | } 22 | 23 | int main() 24 | { 25 | cout< 2 | using namespace std; 3 | 4 | int power(int n, int p) 5 | { 6 | if(p==0) 7 | { 8 | return 1; 9 | } 10 | int prevpower = power(n, p-1); 11 | return n*prevpower; 12 | } 13 | 14 | int main() 15 | { 16 | int n, p; 17 | cin>>n>>p; 18 | 19 | cout< 2 | #include 3 | 4 | using namespace std; 5 | 6 | void permutation(string s , string ans) 7 | { 8 | if(s.length()==0) 9 | { 10 | cout< 2 | using namespace std; 3 | 4 | void towerofHanoi(int n, char src, char dest, char helper) 5 | { 6 | if(n==0) 7 | { 8 | return; 9 | } 10 | towerofHanoi(n-1, src, helper, dest); 11 | cout<<"Move from "< 2 | #include 3 | using namespace std; 4 | class Solution 5 | { 6 | public: 7 | vector runningSum(vector &nums) 8 | { 9 | vector temp; 10 | int n = nums.size(); 11 | for (int i = 0; i < n; i++) 12 | { 13 | int sum = 0; 14 | for (int j = 0; j <= i; j++) 15 | { 16 | sum += nums[j]; 17 | } 18 | temp.push_back(sum); 19 | } 20 | return temp; 21 | } 22 | }; 23 | 24 | int main() 25 | { 26 | 27 | Solution s; 28 | vector vect{10, 20, 30}; 29 | vector ans; 30 | ans = s.runningSum(vect); 31 | for (auto it = ans.begin(); it != ans.end(); it++) 32 | cout << *it << " "; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /C++ programs/SelectionSort.cpp: -------------------------------------------------------------------------------- 1 | /*C++ Programme for the selection sort*/ 2 | #include 3 | using namespace std; 4 | 5 | void SelectSort(int arr[], int n) 6 | { 7 | for(int i=0;i>n; 23 | int arr[n]; 24 | for(int i=0;i>arr[i]; 27 | } 28 | 29 | SelectSort(arr, n); 30 | 31 | for(int i=0;i 3 | using namespace std; 4 | 5 | void primeSieve(int n) 6 | { 7 | int prime[n] = {0}; 8 | 9 | for(int i=2;i<=n;i++) 10 | { 11 | if(prime[i]==0) 12 | { 13 | for(int j=i*i;j<=n;j+=i) 14 | { 15 | prime[j]=1; 16 | } 17 | } 18 | } 19 | 20 | for(int i=2;i<=n;i++) 21 | { 22 | if(prime[i]==0) 23 | { 24 | cout<>n; 34 | primeSieve(n); 35 | } -------------------------------------------------------------------------------- /C++ programs/SortingDnfSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void swap(int arr[], int i, int j) 5 | { 6 | int temp = arr[i]; 7 | arr[i]=arr[j]; 8 | arr[j]=temp; 9 | } 10 | 11 | void dnfSort(int arr[], int n) 12 | { 13 | int low=0; 14 | int mid=0; 15 | int high=n-1; 16 | 17 | while(mid<=high) 18 | { 19 | if(arr[mid]==0) 20 | { 21 | swap(arr, low, mid); 22 | low++; mid++; 23 | } 24 | else if(arr[mid]==1) 25 | { 26 | mid++; 27 | } 28 | 29 | else 30 | { 31 | swap(arr, mid, high); 32 | high--; 33 | } 34 | } 35 | } 36 | 37 | int main() 38 | { 39 | int arr[]= {1,0,2,1,0,1,2,1,2}; 40 | 41 | dnfSort(arr, 9); 42 | 43 | for(int i=0;i<9;i++) 44 | { 45 | cout< 2 | 3 | using namespace std; 4 | 5 | void swap(int arr[], int i, int j) 6 | { 7 | int temp=arr[i]; 8 | arr[i]=arr[j]; 9 | arr[j]=temp; 10 | } 11 | 12 | void waveSort(int arr[], int n) 13 | { 14 | for(int i=1;iarr[i-1]) 17 | { 18 | swap(arr, i, i-1); 19 | } 20 | if(arr[i]>arr[i+1] && i<=n-2) 21 | { 22 | swap(arr, i, i+1); 23 | } 24 | } 25 | } 26 | 27 | int main() 28 | { 29 | int arr[]={1,3,4,7,5,6,2}; 30 | 31 | waveSort(arr, 7); 32 | 33 | for(int i=0;i<7;i++) 34 | { 35 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int n,m; 7 | cin>>n>>m; 8 | 9 | int a[n][m]; 10 | 11 | for(int i=0;i>a[i][j]; 16 | } 17 | } 18 | 19 | //spiral order print 20 | 21 | int row_start=0 ,row_end=n-1, col_start=0, col_end=m-1; 22 | 23 | while(row_start<=row_end && col_start<=col_end) 24 | { 25 | //for row start 26 | for(int col=col_start;col<=col_end;col++) 27 | { 28 | cout<=col_start;col--) 41 | { 42 | cout<=row_start;row--) 48 | { 49 | cout< 2 | using namespace std; 3 | 4 | void solve(){ 5 | 6 | int n; 7 | cin>>n; 8 | 9 | vector a(n); 10 | 11 | for(int i=0;i>a[i]; 13 | } 14 | 15 | int mini = *min_element(a.begin(),a.end()); 16 | 17 | int ans = mini*n; 18 | 19 | for(int i=0;imini) 21 | ans++; 22 | } 23 | 24 | cout<>t; 31 | 32 | while(t--){ 33 | 34 | solve(); 35 | } 36 | } -------------------------------------------------------------------------------- /C++ programs/Topological Sort in C++: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cout<<"Enter no of vertices in graph: "; 8 | cin>>n; 9 | 10 | int adj[n][n]; 11 | int indegree[n]; 12 | stack st; 13 | for(int i=0 ; i>adj[i][j]; 20 | if (adj[i][j]==1){ 21 | indegree[j]+=1; 22 | } 23 | } 24 | } 25 | 26 | for(int i=0; i 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int n,m; 7 | cin>>n>>m; 8 | 9 | int a[n][m]; 10 | 11 | for(int i=0;i>a[i][j]; 16 | } 17 | } 18 | //this can be used if matrix is given and we have not to take the input 19 | /* for(int i=0;i 3 | using namespace std; 4 | class Solution{ 5 | // Function to find the trapped water between the blocks. 6 | public: 7 | long long trappingWater(int arr[], int n){ 8 | // code here 9 | long i,sum=0; 10 | int *left = new int[n]; 11 | int *right= new int[n]; 12 | left[0] = arr[0]; 13 | for(i=1;i=0;i--) 20 | { right[i] = std::max(right[i+1],arr[i]); } 21 | for(i=0;i> t; 31 | 32 | while(t--){ 33 | int n; 34 | 35 | //size of array 36 | cin >> n; 37 | 38 | int a[n]; 39 | 40 | //adding elements to the array 41 | for(int i =0;i> a[i]; 43 | } 44 | Solution obj; 45 | //calling trappingWater() function 46 | cout << obj.trappingWater(a, n) << endl; 47 | } 48 | return 0; 49 | } -------------------------------------------------------------------------------- /C++ programs/UniqueNoInAnArray.cpp: -------------------------------------------------------------------------------- 1 | //write a program to find a unique number in an array where all numbers except one is present twice. 2 | 3 | #include 4 | using namespace std; 5 | 6 | 7 | int unique(int arr[], int n) 8 | { 9 | int xorsum =0; 10 | for(int i=0; i 2 | int main() 3 | { 4 | int a[5],i; 5 | for(i=0;i<5;i++) 6 | { 7 | printf("\n Enter the element="); 8 | scanf("%d",&a[i]); 9 | 10 | } 11 | printf("Array elements are \n"); 12 | for(i=0;i<5;i++) 13 | { 14 | printf("%d\n",a[i]); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /C++ programs/add to integers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a,b,sum; 5 | printf("Enter two numbers"); 6 | scanf("%d%d",&a,&b); 7 | sum=a+b; 8 | printf("sum of two numbers is %d",sum); 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /C++ programs/add two numbers using functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | //program to demonstrate the use of functions in c 3 | void add(int x,int y); //function prototype 4 | int main() 5 | { 6 | int x,y; 7 | printf("Enter ywo numbers"); 8 | scanf("%d%d",&x,&y); 9 | add(x,y); //function call 10 | } 11 | void add(int a,int b) 12 | { 13 | int c; 14 | c=a+b; //function definition 15 | printf("sum is %d",c); 16 | return c; 17 | } 18 | -------------------------------------------------------------------------------- /C++ programs/addition and subtraction of a 2-D matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int m,n,a[10][10],b[10][10],c[10][10],d[10][10],i,j; 5 | printf("Enter number of rows m = "); 6 | scanf("%d",&m); 7 | printf("Enter number of columns n "); 8 | scanf("%d",&n); 9 | printf("Marix elements:"); 10 | for(i=0;i 2 | int main() 3 | { 4 | int m1[10][10],m2[10][10],m3[10][10],m,n,i,j,addition; 5 | printf("Enter number of rows = "); 6 | scanf("%d",&m); 7 | printf("Enter number of columns = "); 8 | scanf("%d",&n); 9 | printf("Enter elements of first matrix= \n"); 10 | for(i=0;i 2 | int main() 3 | { 4 | /* CALCULATE AGE OF A PERSON */ 5 | int cy,by,week,age,hrs; 6 | printf("Enter the birth year = "); 7 | scanf("%d",&by); 8 | printf("Enter the current year = "); 9 | scanf("%d",&cy); 10 | age=cy-by; 11 | printf("Age of person is %d",age); 12 | week=(age*365)/7; 13 | printf("\n Age in week is = %d \n",week); 14 | hrs=week*7*24; 15 | printf(" \nAge in hours is = %d \n",hrs); 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /C++ programs/all prime numbers between 1 to n.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num,i,dividend,n; 5 | printf("enter maximum range"); 6 | scanf("%d",&n); 7 | for(num=1;num<=n;num++) 8 | { 9 | dividend=0; 10 | for(i=2;i>=num/2;i++) 11 | { 12 | if(num%i==0) 13 | { 14 | dividend++; 15 | break; 16 | } 17 | } 18 | if (dividend==0 && num!=1) 19 | printf("%d\t",num); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /C++ programs/alphabet pattern 1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j; 5 | char ch='A'; 6 | for(i=1;i<=5;i++) 7 | { 8 | for(j=1;j<=i;j++) 9 | { 10 | printf("\n%c",ch); 11 | ch++; 12 | } 13 | ch='A'; 14 | 15 | printf("\n"); 16 | } 17 | -------------------------------------------------------------------------------- /C++ programs/alphabet pattern 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j; 5 | char ch='A'; 6 | for(i=1;i<=5;i++) 7 | { 8 | for(j=1;j<=i;j++) 9 | { 10 | 11 | printf("%c",ch); 12 | } 13 | ch++; 14 | printf("\n"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /C++ programs/alphabet pattern 3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j; 5 | char ch='A'; 6 | for(i=1;i<=5;i++) 7 | { 8 | for(j=1;j<=i;j++) 9 | { 10 | printf("%c",ch); 11 | ch++; 12 | } 13 | printf("\n"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /C++ programs/alphabet pattern in v shape.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j; 5 | for(i=1;i<=5;i++) 6 | { 7 | for(j=1;j<=9;j++) 8 | { 9 | if(j<=i || j>=10-i) 10 | { 11 | printf("%c",96+i); 12 | } 13 | else 14 | { 15 | printf(" "); 16 | } 17 | 18 | } 19 | printf("\n"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /C++ programs/alphabet pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j; 5 | char k; 6 | for(i=1;i<=3;i++) 7 | { 8 | k='A'; 9 | for(j=1;j<=3;j++) 10 | { 11 | 12 | if(j<=i) 13 | printf("%c",k); 14 | k++; 15 | } 16 | else 17 | printf(" "); 18 | 19 | 20 | } 21 | printf("\n"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /C++ programs/alphabets pattern in inverted U shap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j; 5 | char ch; 6 | for(i=1;i<=4;i++) 7 | { 8 | ch='A'; 9 | for(j=1;j<=7;j++) 10 | { 11 | if(j<=5-i||j>=3+i) 12 | { 13 | printf("%c",ch); 14 | j<4?ch++:ch--; 15 | } 16 | else 17 | { 18 | printf(" "); 19 | if(j==4) 20 | ch--; 21 | } 22 | } 23 | printf("\n"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /C++ programs/area of rectangle using functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int area(int l,int b); 3 | int main() 4 | { 5 | int l,b; 6 | printf("Enter the length\n"); 7 | scanf("%d",&l); 8 | printf("Enter the breadth\n"); 9 | scanf("%d",&b); 10 | rectangle=area(l,b); 11 | printf("Area of rectangle = %d",rectangle); 12 | 13 | } 14 | int area(int l,int b) 15 | { 16 | int area; 17 | area=l*b; 18 | return(area); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /C++ programs/area of square using functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | square area (); 3 | int main() 4 | { 5 | int a,square; 6 | printf("Enter side of square="); 7 | scanf("%d",&a); 8 | square=area(a*a); 9 | print("\nArea of square =%d",square); 10 | } 11 | area() 12 | { 13 | int a; 14 | area=a*a; 15 | return(); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /C++ programs/armstrong number using functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | void armstrong () 3 | 4 | { 5 | int num,sum=0,r,original_number; 6 | printf("Enter a number"); 7 | scanf("%d",&num); 8 | original_number=num; 9 | while(num!=0) 10 | { 11 | r=num%10; 12 | sum=sum+r*r*r; 13 | num=num/10; 14 | } 15 | printf("new number is %d",num); 16 | if(sum=num) 17 | { 18 | printf("number is armstrong\n"); 19 | } 20 | else 21 | { 22 | printf("number is not armstrong\n"); 23 | } 24 | void armstrong(); 25 | void main() 26 | { 27 | 28 | armstrong(); //function call 29 | } 30 | 31 | -------------------------------------------------------------------------------- /C++ programs/armstrong number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num,orig,newnum=0,r=0; 5 | printf("Enter a number"); 6 | scanf("%d",&num); 7 | orig=num; 8 | while(num!=0) 9 | { 10 | r= num%10; 11 | newnum=newnum+r*r*r; 12 | num=num/10; 13 | } 14 | printf("new number is%d",newnum); 15 | if(newnum==orig) 16 | { 17 | printf("number is armstrong"); 18 | } 19 | else 20 | { 21 | printf("number is not armstrong"); 22 | } 23 | 24 | 25 | 26 | 27 | 28 | 29 | } 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /C++ programs/armstrong numbr using recursion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int armstrong(int); 3 | int main() 4 | { 5 | int n,ans; 6 | printf("Enter a three digit number n = "); 7 | scanf("%d",&n); 8 | ans=armstrong(n); 9 | if(ans==n) 10 | { 11 | printf("%d is an armstrong number ",n); 12 | } 13 | else 14 | { 15 | printf("%d is not an armstrong number ",n); 16 | } 17 | 18 | } 19 | int armstrong(int n) 20 | { 21 | 22 | if(n%10!=0) 23 | return (n%10)*(n%10)*(n%10)+armstrong(n/10); 24 | else 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /C++ programs/array using switch case.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | /*ARRAYS USING SWITCH CASE*/ 4 | { 5 | int a[10],c1=0,c2=0,ch,i; 6 | printf("\nEnter 10 elements\n"); 7 | for(i=0;i<10;i++) 8 | { 9 | scanf("%d",&a[i]); 10 | } 11 | printf("\n 1. SUM OF ARRAY = "); 12 | printf("\n 2. COUNT EVEN AND ODD ELEMENTS FROM ARRAY"); 13 | printf("\n 3. SUM OF POSITIVE AND NEGATIVE ELEMENTS IN AN ARRAY"); 14 | printf("\nEnter your choice = "); 15 | scanf("%d",&ch); 16 | 17 | switch(ch) 18 | { 19 | case 1: 20 | printf("sum of array is"); 21 | for(i=0;i<10;i++) 22 | c1=c1+a[i]; 23 | printf("sum of array elements is %d",c1); 24 | break; 25 | case 2: 26 | printf("even and odd elements from array "); 27 | for(i=0;i<10;i++) 28 | { 29 | if(a[i]%2==0) 30 | c1++; 31 | else 32 | c2++; 33 | } 34 | printf("\n even=%d \n odd=%d",c1,c2); 35 | break; 36 | case 3: 37 | printf("count positive and negative elements in array"); 38 | for(i=0;i<10;i++) 39 | { 40 | if(a[i]>0) 41 | c1=c1+a[i]; 42 | else if(a[i]<0) 43 | c2=c2+a[i]; 44 | 45 | } 46 | 47 | printf("\n positive=%d \n negative=%d",c1,c2); 48 | break; 49 | default: 50 | printf("invalid choice"); 51 | break; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /C++ programs/arrays using switch case.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | /* ARRAYS USING SWITCH-CASE*/ 5 | int a[10],i,ch,s=0,c1=0,c2=0; 6 | printf("Enter 10 numbers="); 7 | for(i=0;i<10;i++) 8 | { 9 | scanf("\n %d",&a[i]); 10 | } 11 | printf("\n 1.SUM OF ARRAY"); 12 | printf("\n 2.COUNT EVEN AND ODD ELEMENTS FROM ARRAY"); 13 | printf("\n 3.SUM OF POSITIVE AND NEGATIVE VALUES IN ARRAY"); 14 | printf("\n Enter your choice"); 15 | scanf("%d",ch); 16 | switch(ch) 17 | { 18 | case 1: 19 | for(i=0;i<10;i++) 20 | s=s+a[i]; 21 | printf("\n sum of array = %d",s); 22 | break; 23 | case 2: 24 | for(i=0;i<10;i++) 25 | { 26 | if(i%2==0) 27 | c1++; 28 | else 29 | c2++; 30 | } 31 | printf("\n Even = %d\n Odd = %d",c1,c2); 32 | break; 33 | 34 | case 3: 35 | for(i=0;i<10;i++) 36 | { 37 | if(a[i]>0) 38 | c1=c1+a[i]; 39 | else if(a[i]<0) 40 | c2=c2+a[i]; 41 | 42 | } 43 | printf("\n Positive = %d\n Negative = %d",c1,c2); 44 | break; 45 | default: 46 | printf("invalid choice"); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /C++ programs/average of 5 numbers using pointers with no arguments, no returns.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | void average(void); 3 | void main() 4 | { 5 | int a,b,c,d,e,sum; 6 | float average; 7 | printf("Enter 5 numbers"); 8 | scanf("%d%d%d%d%d",&a,&b,&c,&d,&e); 9 | 10 | printf("Average is %f",average); 11 | 12 | } 13 | void average(void) 14 | { 15 | int a,b,c,d,e; 16 | float sum,avg; 17 | sum=a+b+c+d+e; 18 | avg=(a+b+c+d+e)/5; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /C++ programs/average of numbers using arrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a[5],i,sum=0; 5 | float average; 6 | printf("Enter five numbers"); 7 | scanf("%d",&a[i]); 8 | for(i=0;i<=4;i++) 9 | sum=sum+a[i]; 10 | average=sum/5.0; 11 | printf("average is%f",average); 12 | 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /C++ programs/binary pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j,k; 5 | for(i=1;i<=6;i++) 6 | { 7 | k=1; 8 | for(j=1;j<=6;j++) 9 | { 10 | 11 | if(j<=i) 12 | printf("%d",k); 13 | k=1-k; 14 | } 15 | else 16 | printf(" "); 17 | } 18 | printf("\n"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /C++ programs/binary seach.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int search(vector& nums, int target) { 4 | 5 | int start=0; 6 | int end=nums.size()-1; 7 | int mid; 8 | while(start<=end) 9 | { 10 | mid=start-(start-end)/2; 11 | if(nums[mid]==target) 12 | { 13 | return mid; 14 | } 15 | else if(nums[mid]>target) 16 | { 17 | end=mid-1; 18 | } 19 | else 20 | { 21 | start=mid+1; 22 | } 23 | } 24 | return -1; 25 | 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /C++ programs/binary_search.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | // Initial template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | 8 | // } Driver Code Ends 9 | // User function template for C++ 10 | 11 | class Solution { 12 | public: 13 | int binarysearch(int arr[], int n, int k) { 14 | // code here 15 | int start=0,end=n-1; 16 | while(start<=end) 17 | { 18 | int mid=start+(end-start)/2; 19 | if(arr[mid]==k) 20 | { 21 | return mid; 22 | 23 | } 24 | else if(arr[mid]>k) 25 | { 26 | end=mid-1; 27 | } 28 | else 29 | { 30 | start=mid+1; 31 | } 32 | } 33 | return -1; 34 | } 35 | }; 36 | 37 | //{ Driver Code Starts. 38 | int main() { 39 | int t; 40 | cin >> t; 41 | 42 | while (t--) { 43 | int N; 44 | cin >> N; 45 | int arr[N]; 46 | for (int i = 0; i < N; i++) cin >> arr[i]; 47 | int key; 48 | cin >> key; 49 | Solution ob; 50 | int found = ob.binarysearch(arr, N, key); 51 | cout << found << endl; 52 | } 53 | } 54 | 55 | // } Driver Code Ends 56 | -------------------------------------------------------------------------------- /C++ programs/brracket_balance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class stack 6 | { 7 | public: 8 | int top; 9 | int size; 10 | char *Arr; 11 | }; 12 | 13 | void push(stack *ptr,char data) 14 | { 15 | if(ptr->top==ptr->size-1) 16 | { 17 | cout<<"Stack Overflow"<top++; 22 | ptr->Arr[ptr->top]=data; 23 | } 24 | } 25 | 26 | char pop(stack *ptr) 27 | { 28 | char x; 29 | if(ptr->top==-1) 30 | { 31 | cout<<"Stack Underflow"<Arr[ptr->top]; 36 | ptr->top--; 37 | } 38 | return x; 39 | } 40 | 41 | int isEmpty(stack ptr) 42 | { 43 | if(ptr.top==-1) 44 | { 45 | return 1; 46 | } 47 | return 0; 48 | } 49 | 50 | int isBalanced(stack st,string str) 51 | { 52 | for(int i=0;i>str; 78 | 79 | stack st; 80 | st.size=str.length(); 81 | st.Arr=new char[st.size]; 82 | st.top=-1; 83 | 84 | cout<<"Lets Check "< 4 | using namespace std; 5 | 6 | // A function to implement bubble sort 7 | void bubbleSort(int arr[], int n) 8 | { 9 | int i, j; 10 | for (i = 0; i < n - 1; i++) 11 | 12 | // Last i elements are already 13 | // in place 14 | for (j = 0; j < n - i - 1; j++) 15 | if (arr[j] > arr[j + 1]) 16 | swap(arr[j], arr[j + 1]); 17 | } 18 | 19 | // Function to print an array 20 | void printArray(int arr[], int size) 21 | { 22 | int i; 23 | for (i = 0; i < size; i++) 24 | cout << arr[i] << " "; 25 | cout << endl; 26 | } 27 | 28 | // Driver code 29 | int main() 30 | { 31 | int arr[] = { 5, 1, 4, 2, 8}; 32 | int N = sizeof(arr) / sizeof(arr[0]); 33 | bubbleSort(arr, N); 34 | cout << "Sorted array: \n"; 35 | printArray(arr, N); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /C++ programs/calculate aggergate percentage of a student.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int physics,chemistry,maths,english,computer; 5 | float total,per; 6 | printf("Enter the marks of physics = \n"); 7 | scanf("%d",&physics); 8 | printf("Enter the marks of chemistry = \n"); 9 | scanf("%d",&chemistry); 10 | printf("Enter the marks of maths = \n"); 11 | scanf("%d",&maths); 12 | printf("Enter the marks of english = \n"); 13 | scanf("%d",&english); 14 | printf("Enter the marks of computer = \n"); 15 | scanf("%d",&computer); 16 | total=physics+chemistry+maths+english+computer; 17 | per=total/5.0; 18 | printf("Aggregate percentage is %f",per); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /C++ programs/calculate gross salary.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | float basic_salary,dearness_allowance,houserent_allowance,gross_salary; 5 | printf("Enter basic salary of person\n"); 6 | scanf("%f",&basic_salary); 7 | dearness_allowance=(40*basic_salary)/100; 8 | houserent_allowance=(20*basic_salary)/100; 9 | gross_salary=(basic_salary+dearness_allowance+houserent_allowance); 10 | 11 | printf("gross_salary of person is %f\n",gross_salary); 12 | } 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /C++ programs/calculate sum and average of first 10 integer numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,sum=0; 5 | float avg; 6 | for(i=1;i<=10;i++) 7 | { 8 | sum=sum+i; 9 | } 10 | for(i=1;i<=10;i++) 11 | avg=sum/10; 12 | 13 | printf("sum =%d\n",sum); 14 | printf("avg =%d\n",avg); 15 | } 16 | -------------------------------------------------------------------------------- /C++ programs/calculate sum of odd and even from 1 to n using loops.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n,i,j,sumo,sume; 5 | printf("enter the value of n="); 6 | scanf("%d",&n); 7 | printf("odd numbers are \n"); 8 | for(i=1;i<=n;i=i+2) 9 | { 10 | printf("%d \t",i); 11 | sumo=sumo+i; 12 | } 13 | printf("\n %d",sumo); 14 | printf("even numbers are \n"); 15 | for(j=2;j<=n;j=j+2) 16 | { 17 | printf("%d \t",j); 18 | sume=sume+j; 19 | } 20 | printf("\n %d",sumo); 21 | } 22 | -------------------------------------------------------------------------------- /C++ programs/call by reference using functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | //demonstrate the use of call by reference using functions 3 | void swap(int*,int*); 4 | int main() 5 | { 6 | int a,b; 7 | printf("Enter two values"); 8 | scanf("%d%d",&a,&b); 9 | printf("\nBefore swapping a=%d,b=%d",a,b); 10 | swap(&a,&b); 11 | printf("\nAfter swapping a=%d,b=%d ,a,b"); 12 | 13 | } 14 | void swap(int*p,int*q) 15 | { 16 | int *p,*q,r; 17 | r=*p; 18 | *p=*q; 19 | *q=r; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /C++ programs/character is vowel or consonant in string using pointers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int c1=0,c2=0; 5 | char str[10],*p; 6 | printf("Enter string="); 7 | gets(str); 8 | *p==(str); 9 | while(*p!='\0') 10 | { 11 | if(*p=='A',||*p=='E'||*p=='I'||*p=='o'||*p=='U'||*p=='a'||*p=='e'||*p=='i'||*p=='o'||*p=='u') 12 | c1++; 13 | else 14 | c2++; 15 | } 16 | printf("vowel =%d\n consonant=%d",c1,c2); 17 | } 18 | -------------------------------------------------------------------------------- /C++ programs/check a given character is lower case alphabet or not.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char c; 5 | int a; 6 | printf("enter a character"); 7 | scanf("%c",&c); 8 | c=a; 9 | if(c>=97 && c>=122) 10 | printf("lower case alphabet"); 11 | else 12 | printf("not a lower case alphabet"); 13 | } 14 | -------------------------------------------------------------------------------- /C++ programs/check a number is positive,negative,zero.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a; 5 | printf("Enter a number"); 6 | scanf("%d",&a); 7 | if(a>0) 8 | printf("a is positive"); 9 | else if(a<0) 10 | printf("a is negative"); 11 | else 12 | printf("a is zero"); 13 | } 14 | -------------------------------------------------------------------------------- /C++ programs/check even or odd number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a; 5 | printf("Enter the value of a="); 6 | scanf("%d",&a); 7 | if(a%2==0) 8 | 9 | printf("number is even %d",a); 10 | else 11 | printf(" number is odd %d",a); 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /C++ programs/check odd or even using functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | /*takes nothing returns nothing function type odd and even number function*/ 3 | void oddeven(void); 4 | int main() 5 | { 6 | oddeven(); 7 | } 8 | void oddeven(void) 9 | { 10 | int a; 11 | printf("Enter a number"); 12 | scanf("%d",&a); 13 | if(a%2==0) 14 | printf("even number",a); 15 | else 16 | printf("odd number",a); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /C++ programs/check pime or not using functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | void checkprime(int n); 3 | { 4 | int num; 5 | printf("Enter a number"); 6 | scanf("%d",&num); 7 | for(i=2;i 2 | int main() 3 | { 4 | char c; 5 | int uppercase_vowel,lowercase_vowel; 6 | printf("Enter a character"); 7 | scanf("%c",c); 8 | uppercase_vowel=(c=='a'||c=='e'||c ='i'||c=='o'||c=='u'); 9 | lowercase_vowel=(c=='A'||c=='E'||c=='I'||c='O'C=='U'); 10 | if(uppercase_vowel||lowercase_vowel) 11 | printf("vowel"); 12 | else 13 | printf("consonant"); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /C++ programs/check whether a input character if it is lowercase letter then convert to uppercase letter otherwise convert to lower case letter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char c; 5 | printf("enter a character"); 6 | scanf("%c",&c); 7 | if(c>='A' && c<='Z') 8 | printf("it is uppercase letter \n lowercase letter %c",c+32); 9 | else if(c>='a' && c<='z') 10 | printf("it is lowercase letter \n uppercase letter %c",c-32); 11 | else 12 | printf("invalid choice"); 13 | } 14 | -------------------------------------------------------------------------------- /C++ programs/check whether a triangle is valid or not.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a,b,c; 5 | printf("enter sides of triangle"); 6 | scanf("%d%d%d",&a,&b,&c); 7 | if((a+b<=c)&&(a+c<=b)&&(b+c<=a)) 8 | printf("triangle is valid"); 9 | else 10 | printf("triangle is invalid"); 11 | } 12 | -------------------------------------------------------------------------------- /C++ programs/compute sum of all array elements.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a[10]={11,22,36,15,2}; 5 | int sum=0,*p; 6 | p=&a; 7 | for(p=&a[0];p<=&a[4];p++) 8 | sum=sum+*p; 9 | printf("sum is %d",sum); 10 | } 11 | -------------------------------------------------------------------------------- /C++ programs/convert degree fahrenheit into degree celsius.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | float cel,fr; 5 | printf("Enter the temperature in fahrenhite ="); 6 | scanf("%f",&fr); 7 | cel=5.0/9*(fr-32); 8 | printf("\n the temperature in celsius = %f\n",cel); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /C++ programs/convert distance in meters,feet,inches,centimeters.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int d; 5 | printf("enter the distance in kms"); 6 | scanf("%d",&d); 7 | printf("the distance in meters = %d\n",d*1000); 8 | printf("the distance in feet = %d\n",d*3281); 9 | printf("the distance in inches = %d\n,d*39370"); 10 | printf("the distance in centimeter = %d\n",d*100000); 11 | } 12 | -------------------------------------------------------------------------------- /C++ programs/copy one array to another.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a[10],b[10],n,i,j; 5 | printf("Enter the number"); 6 | scanf("%d",&n); 7 | for(i=0;i 2 | int main() 3 | { 4 | float s,p,c; 5 | printf("Enter the selling price of 15 items = \n"); 6 | scanf("%f",&s); 7 | printf("Enter the profit of 15 items = \n"); 8 | scanf("%f",&p); 9 | /* CALCULATE COST PRICE OF ITEM */ 10 | 11 | c=(s-p)/15; 12 | printf("The cost price of an item is %f",c); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /C++ programs/count how many times a number is present in an array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a[10],i,c=0,n; 5 | printf("\nEnter 10 elements = \n"); 6 | for(i=0;i<10;i++) 7 | { 8 | scanf("\n%d",&a[i]); 9 | } 10 | printf("\n enter the number which you want to count"); 11 | scanf("%d",&a[i]); 12 | for(i=0;i<10;i++) 13 | { 14 | if(a[i]==n) 15 | c++; 16 | } 17 | printf("\n count = %d",c); 18 | } 19 | -------------------------------------------------------------------------------- /C++ programs/count number of positive,negative and zero in array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a[10],i,n,posi,neg,zero; 5 | printf("COUNT THE NUMBER OF POSITIVE,NEGATIVE,ZERO ELEMENT IN AN ARRAY"); 6 | printf(" \n Enter the number of elements = "); 7 | scanf("\n %d",&n); 8 | 9 | for(i=0;i0) 23 | posi=a[i]; 24 | else if(a[i]<0) 25 | neg=a[i]; 26 | else 27 | zero=a[i]; 28 | } 29 | printf("\n positive elements are = %d ",posi); 30 | printf("\n negative elements are = %d ",neg); 31 | printf("\n zero elements are = %d",zero); 32 | } 33 | -------------------------------------------------------------------------------- /C++ programs/count positive,negative,zero elements in an aray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a[10],n,i,posi=0,neg=0,zero=0; 5 | printf("Enter the number"); 6 | scanf("%d",&n); 7 | for(i=0;i0) 20 | posi++; 21 | else if(a[i]<0) 22 | neg++; 23 | else 24 | zero++; 25 | } 26 | printf("positive numbers=%d",posi); 27 | printf("negative number=%d",neg); 28 | printf("zero numbers=%d",zero); 29 | } 30 | -------------------------------------------------------------------------------- /C++ programs/cross star pattern with value of n.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j,n; 5 | printf("enter value of n : "); 6 | scanf("%d",&n); 7 | for(i=1;i<=n;i++) 8 | { 9 | for(j=1;j<=n;j++) 10 | { 11 | if(j == i || j == n+1-i) 12 | { 13 | printf("*"); 14 | } 15 | else 16 | { 17 | printf(" "); 18 | } 19 | } 20 | printf("\n"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /C++ programs/cross star pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j; 5 | for(i=1;i<=7;i++) 6 | { 7 | for(j=1;j<=7;j++) 8 | { 9 | if(i==j || j==8-i) 10 | printf("*"); 11 | else 12 | printf(" "); 13 | } 14 | printf("\n"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /C++ programs/cube of a number using functions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int cubeofnumber(int); 3 | int main() 4 | { 5 | int num,c; 6 | printf("Enter a number : "); 7 | scanf("%d",&num); 8 | c=cubeofnumber(num); 9 | printf("Cube of number = %d",c); 10 | } 11 | int cubeofnumber(int x) 12 | { 13 | 14 | return x*x*x; 15 | } 16 | -------------------------------------------------------------------------------- /C++ programs/date of birth of a person.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int year,month,date; 5 | printf("Enter date of birth of a person = "); 6 | scanf("%d",&date); 7 | printf("Enter month of birth of a person = "); 8 | scanf("%d",&month); 9 | printf("Enter year of birth of a person = "); 10 | scanf("%d",&year); 11 | printf("DATE OF BIRTH OF PERSON = %d/%d/%d ",date,month,year); 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /C++ programs/delete element from an array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int arr[100],position,c,n; 5 | printf("enter number of elements in an array"); 6 | scanf("%d",&n); 7 | for(c=0;cn+1) 15 | printf("deleting element is not possible"); 16 | else 17 | { 18 | for(c=position-1;c&st,int &mid) 4 | { 5 | if(st.size()==mid) 6 | { 7 | st.pop(); 8 | return; 9 | } 10 | int temp = st.top(); 11 | st.pop(); 12 | deleteM(st,mid); 13 | 14 | st.push(temp); 15 | } 16 | public: 17 | //Function to delete middle element of a stack. 18 | void deleteMid(stack&s, int sizeOfStack) 19 | { 20 | if(s.empty()) return; 21 | int mid = ceil((sizeOfStack+1)/2); 22 | deleteM(s,mid); 23 | return; 24 | } 25 | }; 26 | 27 | //No Need TO Find the Size Everytime lets do it. 28 | class Solution 29 | { 30 | void deleteM(stack&st,int mid) 31 | { 32 | if(mid==1) 33 | { 34 | st.pop(); 35 | return; 36 | } 37 | int temp = st.top(); 38 | st.pop(); 39 | deleteM(st,mid-1); 40 | 41 | st.push(temp); 42 | } 43 | public: 44 | //Function to delete middle element of a stack. 45 | void deleteMid(stack&s, int sizeOfStack) 46 | { 47 | if(s.empty()) return; 48 | int mid = (sizeOfStack/2)+1; 49 | deleteM(s,mid); 50 | return; 51 | } 52 | }; -------------------------------------------------------------------------------- /C++ programs/deletion of array elementys.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a[100],n,posi,i; 5 | printf("Enter number of array elements = "); 6 | scanf("%d",&n); 7 | for(i=0;i<=n;i++) 8 | { 9 | scanf("\n%d",a[i]); 10 | } 11 | printf("Array elements are = "); 12 | for(i=0;i<=n;i++) 13 | { 14 | printf("\n%d",a[i]); 15 | } 16 | printf("Enter position for deletion = "); 17 | { 18 | scanf("%d",&posi); 19 | } 20 | for(i=posi-1;i 2 | int main() 3 | { 4 | int num,i; 5 | printf("enter a number"); 6 | scanf("%d",&num); 7 | i=2; 8 | while(i<=num-1) 9 | { 10 | if(num%i==0) 11 | { 12 | printf("not a prime number"); 13 | break; 14 | } 15 | i++; 16 | } 17 | if(i==num) 18 | printf("prime number"); 19 | } 20 | -------------------------------------------------------------------------------- /C++ programs/editdistance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int minDis(string s1, string s2, int n, int m, 4 | vector >& dp) 5 | { 6 | 7 | // If any string is empty, 8 | // return the remaining characters of other string 9 | 10 | if (n == 0) 11 | return m; 12 | 13 | if (m == 0) 14 | return n; 15 | 16 | // To check if the recursive tree 17 | // for given n & m has already been executed 18 | 19 | if (dp[n][m] != -1) 20 | return dp[n][m]; 21 | 22 | // If characters are equal, execute 23 | // recursive function for n-1, m-1 24 | 25 | if (s1[n - 1] == s2[m - 1]) { 26 | return dp[n][m] = minDis(s1, s2, n - 1, m - 1, dp); 27 | } 28 | // If characters are nt equal, we need to 29 | // find the minimum cost out of all 3 operations. 30 | // 1. insert 2.delete 3.replace 31 | else { 32 | int insert, del, replace; // temp variables 33 | 34 | insert = minDis(s1, s2, n, m - 1, dp); 35 | del = minDis(s1, s2, n - 1, m, dp); 36 | replace = minDis(s1, s2, n - 1, m - 1, dp); 37 | return dp[n][m] = 1 + min(insert, min(del, replace)); 38 | } 39 | } 40 | 41 | // Driver program 42 | int main() 43 | { 44 | 45 | string str1 = "voldemort"; 46 | string str2 = "dumbledore"; 47 | 48 | int n = str1.length(), m = str2.length(); 49 | vector > dp(n + 1, vector(m + 1, -1)); 50 | 51 | cout << minDis(str1, str2, n, m, dp); 52 | return 0; 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /C++ programs/floyydwarshal.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program for Floyd Warshall Algorithm 2 | #include 3 | using namespace std; 4 | 5 | // Number of vertices in the graph 6 | #define V 4 7 | 8 | /* Define Infinite as a large enough 9 | value.This value will be used for 10 | vertices not connected to each other */ 11 | #define INF 99999 12 | 13 | // A function to print the solution matrix 14 | void printSolution(int dist[][V]); 15 | 16 | // Solves the all-pairs shortest path 17 | // problem using Floyd Warshall algorithm 18 | void floydWarshall(int graph[][V]) 19 | { 20 | /* dist[][] will be the output matrix 21 | that will finally have the shortest 22 | distances between every pair of vertices */ 23 | int dist[V][V], i, j, k; 24 | 25 | /* Initialize the solution matrix same 26 | as input graph matrix. Or we can say 27 | the initial values of shortest distances 28 | are based on shortest paths considering 29 | no intermediate vertex. */ 30 | for (i = 0; i < V; i++) 31 | for (j = 0; j < V; j++) 32 | dist[i][j] = graph[i][j]; 33 | 34 | /* Add all vertices one by one to 35 | the set of intermediate vertices. 36 | ---> Before start of an iteration, 37 | we have shortest distances between all 38 | pairs of vertices such that the 39 | shortest distances consider only the 40 | vertices in set {0, 1, 2, .. k-1} as 41 | intermediate vertices. 42 | ----> After the end of an iteration, 43 | vertex no. k is added to the set of 44 | intermediate vertices and the set becomes {0, 1, 2, .. 45 | k} */ 46 | for (k = 0; k < V; k++) { 47 | // Pick all vertices as source one by one 48 | for (i = 0; i < V; i++) { 49 | // Pick all vertices as destination for the 50 | // above picked source 51 | for (j = 0; j < V; j++) { 52 | // If vertex k is on the shortest path from 53 | // i to j, then update the value of 54 | // dist[i][j] 55 | if (dist[i][j] > (dist[i][k] + dist[k][j]) 56 | && (dist[k][j] != INF 57 | && dist[i][k] != INF)) 58 | dist[i][j] = dist[i][k] + dist[k][j]; 59 | } 60 | } 61 | } 62 | 63 | // Print the shortest distance matrix 64 | printSolution(dist); 65 | } 66 | 67 | /* A utility function to print solution */ 68 | void printSolution(int dist[][V]) 69 | { 70 | cout << "The following matrix shows the shortest " 71 | "distances" 72 | " between every pair of vertices \n"; 73 | for (int i = 0; i < V; i++) { 74 | for (int j = 0; j < V; j++) { 75 | if (dist[i][j] == INF) 76 | cout << "INF" 77 | << " "; 78 | else 79 | cout << dist[i][j] << " "; 80 | } 81 | cout << endl; 82 | } 83 | } 84 | 85 | // Driver's code 86 | int main() 87 | { 88 | /* Let us create the following weighted graph 89 | 10 90 | (0)------->(3) 91 | | /|\ 92 | 5 | | 93 | | | 1 94 | \|/ | 95 | (1)------->(2) 96 | 3 */ 97 | int graph[V][V] = { { 0, 5, INF, 10 }, 98 | { INF, 0, 3, INF }, 99 | { INF, INF, 0, 1 }, 100 | { INF, INF, INF, 0 } }; 101 | 102 | // Function call 103 | floydWarshall(graph); 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /C++ programs/graph/bfs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | void bfs(int s,vector adj[],bool vis[],int n) 6 | { 7 | queue q; 8 | q.push(s); 9 | 10 | vis[s]=true; 11 | while(!q.empty()) 12 | { 13 | int curr=q.front(); 14 | q.pop(); 15 | cout<>n,e; 36 | 37 | vector adj[n]; 38 | bool vis[n]={false}; 39 | for(int i=0;i>u>>v; 43 | adj[u].push_back(v); 44 | 45 | } 46 | 47 | bfs(0,adj,vis,n); 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /C++ programs/graph/bfsinc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | 6 | void bfs(int g[][7],int start,int n) 7 | { 8 | int i=start; 9 | struct queue q; 10 | int visited[7]={0}; 11 | 12 | print("%d",i); 13 | visited[i]=1; 14 | 15 | enqueue(i); 16 | while(!isEmpty()) 17 | { 18 | i=dequeue(); 19 | for(int j=1;j 2 | using namespace std; 3 | 4 | void printbfs(int** edges,int n,int sv) 5 | { 6 | queue q; 7 | bool *visited=new bool[n]; 8 | for(int i=0;i>n; 34 | cout<<"\n enter the number of edges \n"; 35 | cin>>e; 36 | 37 | int** edges=new int*[n]; 38 | for(int i=0;i>f; 52 | cout<<"\n enter second vertex \n"<>s; 54 | edges[f][s]=1; 55 | edges[s][f]=1; 56 | 57 | } 58 | bool *visited=new bool[n]; 59 | for(int i=0;i 2 | #include 3 | #include 4 | struct node{ 5 | int data; 6 | struct node* next; 7 | }; 8 | 9 | struct node* front=NULL; 10 | struct node* rear=NULL; 11 | 12 | void enqueue(int x){ 13 | struct node* newnode=(struct node*)malloc(sizeof(node)); 14 | newnode->data=x; 15 | newnode->next=NULL; 16 | if(front==NULL && rear==NULL) 17 | { 18 | front=newnode; 19 | rear=newnode; 20 | 21 | } 22 | else{ 23 | rear->next=newnode; 24 | rear=newnode; 25 | } 26 | 27 | 28 | } 29 | 30 | void display() 31 | { 32 | struct node* temp; 33 | if(front==NULL && rear==NULL) 34 | { 35 | printf("\n queue is empty\n"); 36 | 37 | } 38 | else{ 39 | temp=front; 40 | while(temp!=NULL) 41 | { 42 | printf("%d",temp->data); 43 | temp=temp->next; 44 | } 45 | } 46 | } 47 | 48 | void dequeue(){ 49 | struct node* temp=front; 50 | if(front==NULL && rear==NULL) 51 | { 52 | printf("\n queue underflow\n"); 53 | 54 | } 55 | else{ 56 | printf("%d",front->data); 57 | front=front->next; 58 | free(temp); 59 | } 60 | } 61 | 62 | int peek(){ 63 | if(front==NULL) 64 | { 65 | return INT_MAX; 66 | } 67 | else{ 68 | return front->data; 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /C++ programs/graph/demo.cpp: -------------------------------------------------------------------------------- 1 | #ifndef Queue_h 2 | #define Queue_h 3 | #include 4 | struct Node 5 | { 6 | int data; 7 | struct Node *next; 8 | 9 | }*front=NULL,*rear=NULL; 10 | void enqueue(int x) 11 | { 12 | struct Node *t; 13 | t=(struct Node*)malloc(sizeof(struct Node)); 14 | if(t==NULL) 15 | printf("Queue is FUll\n"); 16 | else 17 | { 18 | t->data=x; 19 | t->next=NULL; 20 | if(front==NULL) 21 | front=rear=t; 22 | else 23 | { 24 | rear->next=t; 25 | rear=t; 26 | } 27 | } 28 | 29 | } 30 | int dequeue() 31 | { 32 | int x=-1; 33 | struct Node* t; 34 | 35 | if(front==NULL) 36 | printf("Queue is Empty\n"); 37 | else 38 | { 39 | x=front->data; 40 | t=front; 41 | front=front->next; 42 | free(t); 43 | } 44 | return x; 45 | } 46 | int isEmpty() 47 | { 48 | return front==NULL; 49 | } 50 | #endif /* Queue_h */ 51 | #include 52 | //#include "Queue.h" 53 | void BFS(int G[][7],int start,int n) 54 | { 55 | int i=start,j; 56 | 57 | int visited[7]={0}; 58 | 59 | printf("%d ",i); 60 | visited[i]=1; 61 | enqueue(i); 62 | 63 | while(!isEmpty()) 64 | { 65 | i=dequeue(); 66 | for(j=1;j 2 | using namespace std; 3 | 4 | class graph{ 5 | public: 6 | map visited; 7 | map> adj; 8 | 9 | void addedge(int v,int w); 10 | void dfs(int v); 11 | 12 | }; 13 | 14 | void graph::addedge(int v,int w) 15 | { 16 | adj[v].push_back(w); 17 | } 18 | void graph::dfs(int v) 19 | { 20 | visited[v]=true; 21 | cout<::iterator i; 25 | for(i=adj[v].begin();i!=adj[v].end();i++) 26 | { 27 | if(!visited[*i]) 28 | dfs(*i); 29 | } 30 | } 31 | 32 | 33 | 34 | 35 | int main() 36 | { 37 | // Create a graph given in the above diagram 38 | graph g; 39 | g.addedge(0, 1); 40 | g.addedge(0, 2); 41 | g.addedge(1, 2); 42 | g.addedge(2, 0); 43 | g.addedge(2, 3); 44 | g.addedge(3, 3); 45 | 46 | cout << "Following is Depth First Traversal" 47 | " (starting from vertex 2) \n"; 48 | g.dfs(2); 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /C++ programs/graph/dfsusingadjacencymatrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void print(int **edges,int n,int sv,bool *visited) 5 | { 6 | cout<>n; 31 | cout<<"\n enter the number of edges \n"; 32 | cin>>e; 33 | 34 | int** edges=new int*[n]; 35 | for(int i=0;i>f; 49 | cout<<"\n enter second vertex \n"<>s; 51 | edges[f][s]=1; 52 | edges[s][f]=1; 53 | 54 | } 55 | bool *visited=new bool[n]; 56 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | template 9 | 10 | class graph{ 11 | //here we are creating a non weighted graph so we are ausing list 12 | //value in the map is key 13 | map > l; 14 | 15 | public: 16 | void addedge(int x,int y) 17 | //we want a bidirectional graph so we insert u node after that we insert v node or we push_back v node after it 18 | { 19 | l[x].push_back(y); 20 | l[y].push_back(x); 21 | 22 | } 23 | 24 | void bfs(T srcn) 25 | { 26 | map visited; 27 | queue q; 28 | 29 | q.push(srcn); 30 | visited[srcn]=true; 31 | 32 | while(!q.empty()) 33 | { 34 | T node = q.front(); 35 | q.pop(); 36 | cout< g; 56 | g.addedge(0,1); 57 | g.addedge(1,2); 58 | g.addedge(2,3); 59 | g.addedge(3,4); 60 | g.addedge(4,5); 61 | 62 | 63 | g.bfs(0); 64 | 65 | } -------------------------------------------------------------------------------- /C++ programs/graph/implementationofdfs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void dfs(int s,vector g[],bool *vis) 6 | { 7 | 8 | vis[s]=true; 9 | cout<>n>>e; 23 | 24 | vector g[n]; 25 | bool vis[n]; 26 | 27 | for(int i=0;i>e;i++) 28 | { 29 | int u,v; 30 | cin>>u>>v; 31 | g[u].push_back(v); 32 | g[v].push_back(u); 33 | } 34 | 35 | dfs(0,g,vis); 36 | 37 | cout< 2 | using namespace std; 3 | 4 | class graph{ 5 | int v; 6 | list *adj; 7 | 8 | public: 9 | graph(int v); 10 | void addedge(int v,int w); 11 | void bfs(int s); 12 | }; 13 | 14 | graph::graph(int v) 15 | { 16 | this->v=v; 17 | adj = new list[v]; 18 | } 19 | 20 | void graph::addedge(int v,int w) 21 | { 22 | adj[v].push_back(w); 23 | } 24 | 25 | void graph::bfs(int s) 26 | { 27 | bool *visited=new bool[v]; 28 | for(int i=0;i queue; 34 | visited[s]=true; 35 | queue.push_back(s); 36 | 37 | list::iterator i; 38 | 39 | while(!queue.empty()) 40 | { 41 | s=queue.front(); 42 | cout< 2 | using namespace std; 3 | #define v 5 4 | int minkey(int dis[],bool mstset[]) 5 | { 6 | int minimum=INT_MAX; 7 | int vertex; 8 | for(int v=0;v 2 | #include 3 | using namespace std; 4 | 5 | class stack 6 | { 7 | public: 8 | int top; 9 | int size; 10 | char *A; 11 | }; 12 | 13 | int isEmpty(stack temp) 14 | { 15 | if(temp.top==-1) 16 | { 17 | return 1; 18 | } 19 | return 0; 20 | } 21 | 22 | int isFull(stack temp) 23 | { 24 | if(temp.top==temp.size-1) 25 | { 26 | return 1; 27 | } 28 | return 0; 29 | } 30 | 31 | char topElement(stack st) 32 | { 33 | return st.A[st.top]; 34 | } 35 | 36 | void push(stack *temp,char d) 37 | { 38 | if(temp->top==temp->size-1) 39 | { 40 | cout<<"Stack OverFlow"<top++; 46 | temp->A[temp->top]=d; 47 | return; 48 | } 49 | } 50 | 51 | char pop(stack *temp) 52 | { 53 | if(temp->top==-1) 54 | { 55 | cout<<"Stack Underflow"<A[temp->top]; 61 | temp->top--; 62 | return x; 63 | } 64 | } 65 | 66 | int precendence(char ch) 67 | { 68 | if(ch=='+' || ch=='-') 69 | return 1; 70 | else if(ch=='*' || ch=='/') 71 | return 2; 72 | else 73 | return 0; 74 | } 75 | 76 | string postfix(stack stk,string st) 77 | { 78 | string post=""; 79 | for(int i=0;i precendence(topElement(stk))) 88 | { 89 | push(&stk,st[i]); 90 | } 91 | else 92 | { 93 | while(isEmpty(stk)==0) 94 | { 95 | post+=pop(&stk); 96 | } 97 | push(&stk,st[i]); 98 | } 99 | } 100 | } 101 | 102 | while(!isEmpty(stk)) 103 | { 104 | post+=pop(&stk); 105 | } 106 | return post; 107 | } 108 | 109 | int main() 110 | { 111 | string st; 112 | cin>>st; 113 | stack stk; 114 | stk.top=-1; 115 | stk.size=st.length(); 116 | stk.A = new char(stk.size); 117 | 118 | cout< 2 | using namespace std; 3 | 4 | class Node 5 | { 6 | public: 7 | int data; 8 | Node *next; 9 | }*head=NULL; 10 | 11 | void create_ll(int A[],int n) 12 | { 13 | head=new Node; 14 | head->data=A[0]; 15 | head->next=head; 16 | Node *current=head; 17 | 18 | for(int i=1;idata=A[i]; 22 | current->next=temp; 23 | temp->next=head; 24 | current=temp; 25 | } 26 | } 27 | 28 | void display() 29 | { 30 | Node *ptr=head; 31 | int flag=0; 32 | while(ptr!=head || flag!=1) 33 | { 34 | flag=1; 35 | cout<data<<"->"; 36 | ptr=ptr->next; 37 | } 38 | cout<next; 51 | } 52 | return length; 53 | } 54 | 55 | void insert(int pos,int data) 56 | { 57 | Node *temp=new Node; 58 | temp->data=data; 59 | if(pos>length()) 60 | { 61 | cout<<"Invalid Postion"; 62 | } 63 | else if(pos==1) 64 | { 65 | Node *ptr=head; 66 | while(ptr->next!=head) 67 | { 68 | ptr=ptr->next; 69 | } 70 | temp->next=head; 71 | head=temp; 72 | ptr->next=head; 73 | } 74 | else 75 | { 76 | Node *ptr=head; 77 | for(int i=0;inext; 80 | } 81 | temp->next=ptr->next; 82 | ptr->next=temp; 83 | } 84 | 85 | 86 | } 87 | 88 | int main() 89 | { 90 | int A[]={1,2,3,4,5,6}; 91 | create_ll(A,sizeof(A)/sizeof(A[0])); 92 | display(); 93 | insert(3,0); 94 | display(); 95 | } -------------------------------------------------------------------------------- /C++ programs/josephus_problem-death_circle.cpp: -------------------------------------------------------------------------------- 1 | // It will fail becoz of the O(n) --> Space Complexity 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | void solve(int currIndex,int k,vector v,int &ans) 8 | { 9 | if(v.size()==1) 10 | { 11 | ans=v[0]; 12 | return; 13 | } 14 | 15 | currIndex=(currIndex+k)%v.size(); 16 | v.erase(v.begin()+currIndex); 17 | 18 | solve(currIndex,k,v,ans); 19 | } 20 | 21 | int main() 22 | { 23 | int n=0,k=0; 24 | cin>>n>>k; 25 | 26 | vector v; 27 | for(int i=1;i<=n;i++) v.push_back(i); 28 | int ans=0; 29 | solve(0,k-1,v,ans); 30 | cout<> generate(int numRows) { 6 | vector> result; 7 | 8 | for(int i=0;i row; 11 | for(int j=0;j<=i;j++) 12 | { 13 | if(j==0 || j==i) row.push_back(1); 14 | else row.push_back(result[i-1][j-1]+result[i-1][j]); 15 | } 16 | result.push_back(row); 17 | } 18 | 19 | return result; 20 | } 21 | }; -------------------------------------------------------------------------------- /C++ programs/prims_algo.cpp: -------------------------------------------------------------------------------- 1 | /* code by som #2nd year cse at IIIT - Pune */ 2 | 3 | /* PRIM'S ALGORITHM */ 4 | /* used to find minimum spanning tree with v-1 edges and v nodes where v are the number of nodes in original 5 | graph */ 6 | #include 7 | using namespace std; 8 | #define ull unsigned long long 9 | #define Mod 1000000007 10 | typedef long long ll; 11 | typedef long double ld; 12 | typedef pair p32; 13 | typedef pair p64; 14 | typedef pair pdd; 15 | typedef vector v64; 16 | typedef vector v32; /* vector */ 17 | typedef vector > vv32; 18 | typedef vector > vv64; 19 | typedef vector > vvp64; 20 | typedef vector vp64; 21 | typedef vector vp32; 22 | #define ull unsigned long long 23 | #define f(i,e) for(ll i = 0; i < e; i++) 24 | #define fs(i,s,e) for(ll i = s; i < e; i++) 25 | #define fr(i,s) for(ll i = s; i >= 0; i--) 26 | #define frs(i,s,e) for(ll i = s; i >= e; i--) 27 | #define nl "\n" 28 | #define INF 9999 29 | 30 | #define sz(x) ((ll)(x).size()) 31 | 32 | int main(){ 33 | 34 | ios_base::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | cout.tie(NULL); 37 | /* code for minimum spanning Tree using prims algorithm */ 38 | vector> vec ={ 39 | {INF, INF, INF, INF, INF, INF, INF, INF}, 40 | {INF, INF, 25, INF, INF, INF, 5, INF}, 41 | {INF, 25, INF, 12, INF, INF, INF, 10}, 42 | {INF, INF, 12, INF, 8, INF, INF, INF}, 43 | {INF, INF, INF, 8, INF, 16, INF, 14}, 44 | {INF, INF, INF, INF, 16, INF, 20, 18}, 45 | {INF, 5, INF, INF, INF, 20, INF, INF}, 46 | {INF, INF, 10, INF, 14, 18, INF, INF}, 47 | }; 48 | int u , v; 49 | int min = INT_MAX; 50 | f(i,sz(vec)){ 51 | fs(k,i,sz(vec)){ 52 | if(vec[i][k] getRow(int rowIndex) { 8 | 9 | vector ans; 10 | 11 | long long val=1; 12 | 13 | for(int j=0;j<=rowIndex;j++) 14 | { 15 | ans.push_back(val); 16 | val=val* (rowIndex-j) / (j+1); 17 | } 18 | 19 | return ans; 20 | } 21 | }; 22 | 23 | // All test case pass on Leetcode 24 | 25 | 26 | // But on GFG we have more number of rows becoz they are giving rownumber greater than 33 27 | // Space Complexity -- o(n^2) 28 | class Solution{ 29 | public: 30 | vector nthRowOfPascalTriangle(int n) { 31 | 32 | vector> rec; 33 | vector ans; 34 | 35 | if(n==0) 36 | { 37 | ans.push_back(0); 38 | return ans; 39 | } 40 | 41 | for(int i=0;i nthRowOfPascalTriangle(int n) { 66 | // code here 67 | vector ans; 68 | 69 | if(n<0) return ans; 70 | ans.push_back(1); 71 | for(int i=1;i0;j--) 74 | { 75 | ans[j]=(ans[j]+ans[j-1])%1000000007; 76 | } 77 | ans.push_back(1); 78 | } 79 | 80 | return ans; 81 | } 82 | }; 83 | -------------------------------------------------------------------------------- /C++ programs/pythagorean_triplet.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | using namespace std; 4 | 5 | bool check(int n1, int n2, int n3){ 6 | int a,b,c; 7 | a= max(n1,max(n2,n3)); 8 | 9 | if(a==n1){ 10 | b=n2; 11 | c=n3; 12 | } 13 | else if(a==n2){ 14 | b=n1; 15 | c=n3; 16 | } 17 | else{ 18 | b=n1; 19 | c=n2; 20 | } 21 | 22 | if((a*a)==(b*b)+(c*c)){ 23 | return true; 24 | } 25 | else{ 26 | return false; 27 | } 28 | } 29 | 30 | 31 | int main(){ 32 | 33 | int x, y,z; 34 | cin>>x>>y>>z; 35 | 36 | if(check(x,y,z)){ 37 | cout<<"Pythagorean Triplet"; 38 | } 39 | else{ 40 | cout<<"Not Pythagorean Triplet"; 41 | } 42 | } -------------------------------------------------------------------------------- /C++ programs/sortAnArray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | void insert(vector &v,int temp) 6 | { 7 | if(v.size()==0 || v[v.size()-1]<=temp) 8 | { 9 | v.push_back(temp); 10 | return; 11 | } 12 | int val = v[v.size()-1]; 13 | v.pop_back(); 14 | insert(v,temp); 15 | 16 | v.push_back(val); 17 | } 18 | 19 | void Sort(vector &nums) 20 | { 21 | if(nums.size()==1) return; 22 | 23 | int temp = nums[nums.size()-1]; 24 | nums.pop_back(); 25 | 26 | Sort(nums); 27 | insert(nums,temp); 28 | } 29 | 30 | int main() 31 | { 32 | vector st{5,4,6,1,0,7}; 33 | Sort(st); 34 | for(auto A : st) cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | void sort(vector &v) 8 | { 9 | sort(v.begin(),v.end()); 10 | } 11 | void display(vector &v) 12 | { 13 | for (int i = 0; i < v.size(); i++) 14 | { 15 | cout<v; 20 | int t=0,val=0; 21 | cin>>t; 22 | for(int i=0;i>val; 25 | v.push_back(val); 26 | } 27 | sort(v); 28 | display(v); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /C++ programs/stack_impemented_by_ll.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class stack 5 | { 6 | public: 7 | int data; 8 | stack *next; 9 | }; 10 | 11 | stack *push(stack *top,int d) 12 | { 13 | stack *temp=new stack; 14 | if(temp==NULL) 15 | { 16 | cout<<"Overflow"<data=d; 21 | temp->next=top; 22 | top=temp; 23 | } 24 | return top; 25 | } 26 | 27 | stack *pop(stack *top) 28 | { 29 | if(top==NULL) 30 | { 31 | cout<<"UnderFlow"; 32 | } 33 | else 34 | { 35 | stack *temp=top; 36 | top=top->next; 37 | delete(temp); 38 | } 39 | return top; 40 | } 41 | 42 | int topElement(stack top) 43 | { 44 | return top.data; 45 | } 46 | 47 | void Display(stack *top) 48 | { 49 | stack *temp=top; 50 | while(temp!=NULL) 51 | { 52 | cout<data<<"->"; 53 | temp=temp->next; 54 | } 55 | cout<>ch; 67 | switch(ch) 68 | { 69 | case 1: 70 | { 71 | int data; 72 | cin>>data; 73 | top=push(top,data); 74 | cout<<"Updated List :"; 75 | Display(top); 76 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int n,s; 7 | cin>>n>>s; 8 | 9 | int a[n]; 10 | 11 | for(int i=0;i>a[i]; 14 | } 15 | 16 | int i=0, j=0, st=-1, en=-1, sum=0; 17 | 18 | while(js) 34 | { 35 | sum -=a[i]; 36 | i++; 37 | } 38 | 39 | if(sum==s) 40 | { 41 | st=i+1; 42 | en=j+1; 43 | break; 44 | } 45 | j++; 46 | 47 | 48 | } 49 | cout<< st <<" "< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int row,col; 7 | cout<<" Enter the ROW : "; 8 | cin>>row; 9 | cout << " Enter the Col : "; 10 | cin>>col; 11 | 12 | int A[row][col] = {0}; 13 | 14 | for(int i=0;i>A[i][j]; 19 | } 20 | cout<=0;j--) 47 | { 48 | cout<= l) { 5 | int mid = l + (r - l) / 2; 6 | if (arr[mid] == x) 7 | System.out.println("Element found at index:" + mid); 8 | if (arr[mid] > x) 9 | Binary(arr, l, mid - 1, x); 10 | Binary(arr, mid + 1, r, x); 11 | } 12 | } 13 | public static void main(String[] args) { 14 | int[] Arr = new int[20]; 15 | int n; 16 | System.out.println("Enter number of Elements of an array\n"); 17 | Scanner sc = new Scanner(System.in); 18 | n = sc.nextInt(); 19 | System.out.println("Enter Array Elements\n"); 20 | for(int i=0;i sub,List> ans,List arr,int n) { 23 | 24 | if(index >= n) { 25 | 26 | if(target == 0) { 27 | 28 | if(sub.size() == 0) 29 | ans.add(new ArrayList<>()); 30 | 31 | ans.add(new ArrayList<>(sub)); 32 | } 33 | return ; 34 | } 35 | 36 | if((target-arr.get(index)) >= 0) { 37 | 38 | sub.add(arr.get(index)); 39 | printSubWithSum(index,target-arr.get(index),sub,ans,arr,n); //Recursion 40 | sub.remove(sub.size()-1); 41 | } 42 | printSubWithSum(index+1,target,sub,ans,arr,n); //Recursion 43 | } 44 | 45 | 46 | public static void main(String[] args) { //Main method 47 | 48 | 49 | Scanner sc = new Scanner(System.in); 50 | 51 | System.out.println("Enter the size of array : "); 52 | int n; 53 | n = sc.nextInt(); 54 | 55 | List arr = new ArrayList(n); 56 | 57 | System.out.println("Enter array elements : "); 58 | for(int i=0;i> ans = new ArrayList<>(); 67 | List sub = new ArrayList<>(); 68 | 69 | CombinationSum obj = new CombinationSum(); 70 | obj.printSubWithSum(0,target,sub,ans,arr,n); //Function Calling 71 | 72 | System.out.println("All possible combinations porducing sum "+target+" in array is : "); 73 | ans.forEach(System.out::println); 74 | 75 | sc.close(); 76 | 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /Java programs/NQueens.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class NQueens 4 | { 5 | static int N = 4; 6 | 7 | static int []ld = new int[30]; 8 | 9 | static int []rd = new int[30]; 10 | 11 | static int []cl = new int[30]; 12 | 13 | static void printSolution(int board[][]) 14 | { 15 | for (int i = 0; i < N; i++) 16 | { 17 | for (int j = 0; j < N; j++) 18 | System.out.printf(" %d ", board[i][j]); 19 | System.out.printf("\n"); 20 | } 21 | } 22 | 23 | static boolean solveNQUtil(int board[][], int col) 24 | { 25 | 26 | if (col >= N) 27 | return true; 28 | 29 | for (int i = 0; i < N; i++) 30 | { 31 | 32 | if ((ld[i - col + N - 1] != 1 && 33 | rd[i + col] != 1) && cl[i] != 1) 34 | { 35 | board[i][col] = 1; 36 | ld[i - col + N - 1] = 37 | rd[i + col] = cl[i] = 1; 38 | 39 | if (solveNQUtil(board, col + 1)) 40 | return true; 41 | 42 | board[i][col] = 0; 43 | ld[i - col + N - 1] = 44 | rd[i + col] = cl[i] = 0; 45 | } 46 | } 47 | 48 | return false; 49 | } 50 | 51 | static boolean solveNQ() 52 | { 53 | int board[][] = {{ 0, 0, 0, 0 }, 54 | { 0, 0, 0, 0 }, 55 | { 0, 0, 0, 0 }, 56 | { 0, 0, 0, 0 }}; 57 | 58 | if (solveNQUtil(board, 0) == false) 59 | { 60 | System.out.printf("Solution does not exist"); 61 | return false; 62 | } 63 | 64 | printSolution(board); 65 | return true; 66 | } 67 | 68 | public static void main(String[] args) 69 | { 70 | solveNQ(); 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /Java programs/QuickSort.java: -------------------------------------------------------------------------------- 1 | class QuickSort 2 | { 3 | int partition(int arr[], int low, int high) 4 | { 5 | int pivot = arr[high]; 6 | int i = (low-1); 7 | for (int j=low; j= 10; i -= 10) 54 | llist.push(i); 55 | System.out.println("Given list : "); 56 | llist.printList(); 57 | llist.rotate(4); 58 | System.out.println("Rotated Linked List : "); 59 | llist.printList(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Java programs/SMPAIR.java: -------------------------------------------------------------------------------- 1 | /* package codechef; // don't place package name! */ 2 | 3 | import java.util.*; 4 | import java.lang.*; 5 | import java.io.*; 6 | 7 | /* Name of the class has to be "Main" only if the class is public. */ 8 | class Codechef 9 | { 10 | public static void main (String[] args) throws java.lang.Exception 11 | { 12 | Scanner sc = new Scanner(System.in); 13 | int t = sc.nextInt(); 14 | while(t-- > 0) { 15 | int n = sc.nextInt(); 16 | long[] arr = new long[n]; 17 | for(int i=0; i0) 13 | { 14 | p = p/10; 15 | git++; 16 | } 17 | p = n; 18 | while(p>0) 19 | { 20 | 21 | last = p % 10; 22 | 23 | s += (Math.pow(last, git)); 24 | //removes the last digit 25 | p = p/10; 26 | } 27 | 28 | if(n==s) 29 | 30 | return true; 31 | 32 | else return false; 33 | } 34 | 35 | public static void main(String args[]) 36 | { 37 | int number; 38 | Scanner sc= new Scanner(System.in); 39 | System.out.print("Enter the number: "); 40 | 41 | number=sc.nextInt(); 42 | if(Arms(number)) 43 | { 44 | System.out.print(" It is an Armstrong No "); 45 | } 46 | else 47 | { 48 | System.out.print(" It is Not Armstrong "); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Java programs/dog.java: -------------------------------------------------------------------------------- 1 | 2 | // the chosen dog house 3 | //the simple prefix array will do .from left to right side of index 4 | import java.util.Scanner; 5 | class HelloWorld { 6 | public int counter(int N, int I, int arr[]) 7 | { 8 | int c = 0; 9 | for(int i = 0; i<(I-1); i++) 10 | while(arr[i]!=0) 11 | { 12 | arr[i] = arr[i]-1; 13 | arr[i+1] = arr[i+1]+1; 14 | c++; 15 | } 16 | 17 | for(int i = N-1; i>(I-1); i--) 18 | while(arr[i]!=0) 19 | { 20 | arr[i] = arr[i]-1; 21 | arr[i-1] = arr[i-1]+1; 22 | c++; 23 | } 24 | 25 | return c; 26 | } 27 | public static void main(String[] args) { 28 | HelloWorld ob = new HelloWorld(); 29 | Scanner sc = new Scanner(System.in); 30 | int N = sc.nextInt(); 31 | int I = sc.nextInt(); 32 | int arr [] = new int [N]; 33 | for(int i = 0; i ans,String move,int[][]vis) { 9 | //codition to terminate if i&j rech at boundary of matrix 10 | if (i==n-1 && j==n-1){ 11 | ans.add(move); 12 | return ; 13 | } 14 | 15 | //D ->for down , R-> for right ,L -> for left , U -> for up 16 | //selecting shortest way to go by conditions 17 | 18 | //if down-ward have 1 than move 19 | if (i+10 && vis[i][j-1]==0 && a[i][j-1]==1 ){ 26 | vis[i][j] = 1; 27 | solve(i, j-1, a, n, ans, move+"L", vis); 28 | vis[i][j] = 0; 29 | } 30 | //if right side have 1 than move 31 | if (j+10 && vis[i-1][j]==0 && a[i-1][j]==1 ){ 38 | vis[i][j] = 1; 39 | solve(i-1, j, a, n, ans, move+"U", vis); 40 | vis[i][j] = 0; 41 | } 42 | 43 | } 44 | //class to create a new matrix to add visite "1" or "0" not visite in main recive method 45 | public static ArrayList find(int[][] a,int n) { 46 | int[] [] vis= new int[n][n]; 47 | for (int i=0;i ans = new ArrayList<>(); 54 | if (a[0][0] ==1) solve(0,0,a,n,ans,"",vis); 55 | return ans; 56 | } 57 | } 58 | 59 | public class rat { 60 | public static void main(String[] args) { 61 | int n= 4; 62 | // code take input in matrix form 63 | //which is in 0 or 1 and rat will decide what is the minimum rout to go at end corner 64 | //1 is for move and 0 is don't move 65 | 66 | int[][] a={{1,0,0,0},{1,1,0,1},{1,1,0,0},{0,1,1,1}}; 67 | Solution obj=new Solution(); 68 | ArrayList res=obj.find(a, n); 69 | 70 | //print output in form of DRLU which is choice of rat to move in shortest way to reach at opposite corner 71 | if(res.size()>0) { 72 | for (int i=0; i 80 | //DDRDRR and DRDDRR 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Java programs/gcd.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class gcd 3 | { 4 | public static void main(String args[]) 5 | { 6 | Scanner sc=new Scanner(System.in); 7 | int a=sc.nextInt(); 8 | int b=sc.nextInt(); 9 | int temp=0,r=0; 10 | System.out.print("GCD of "+a+" and "+b+" is : "); 11 | if(a>b) 12 | { 13 | temp=a; 14 | a=b; 15 | b=temp; 16 | } 17 | while(b%a!=0) 18 | { 19 | r=b%a; 20 | b=a; 21 | a=r; 22 | } 23 | System.out.println(a); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Java programs/linear.java: -------------------------------------------------------------------------------- 1 | /* Java program of Linear Search */ 2 | 3 | import java.util.Scanner; 4 | 5 | class Main 6 | { 7 | public static void main(String args[]) 8 | { 9 | int L, n, srch, arr[]; 10 | 11 | Scanner in = new Scanner(System.in); 12 | System.out.println("Enter number of elements"); 13 | n = in.nextInt(); 14 | arr= new int[n]; 15 | 16 | System.out.println("Enter those " + n + " elements"); 17 | 18 | for (L = 0; L < n; L++) 19 | arr[L] = in.nextInt(); 20 | 21 | System.out.println("Enter value to find"); 22 | srch = in.nextInt(); 23 | 24 | for (L = 0; L < n; L++) 25 | { 26 | if (arr[L] == srch) /* Searching element is present */ 27 | { 28 | System.out.println(srch + " is present at location " + (L + 1) + "."); 29 | break; 30 | } 31 | } 32 | if (L == n) /* Element to search isn't present */ 33 | System.out.println(srch + " isn't present in array."); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Java programs/loopdetectioninLL.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class LinkedList { 4 | 5 | static Node head; 6 | 7 | 8 | static class Node { 9 | int data; 10 | Node next; 11 | Node(int d) 12 | { 13 | data = d; 14 | next = null; 15 | } 16 | } 17 | 18 | 19 | static public void push(int new_data) 20 | { 21 | 22 | Node new_node = new Node(new_data); 23 | 24 | new_node.next = head; 25 | 26 | 27 | head = new_node; 28 | } 29 | 30 | 31 | static boolean detectLoop(Node h) 32 | { 33 | HashSet s = new HashSet(); 34 | while (h != null) { 35 | 36 | if (s.contains(h)) 37 | return true; 38 | 39 | 40 | s.add(h); 41 | 42 | h = h.next; 43 | } 44 | 45 | return false; 46 | } 47 | 48 | 49 | public static void main(String[] args) 50 | { 51 | LinkedList llist = new LinkedList(); 52 | 53 | llist.push(20); 54 | llist.push(4); 55 | llist.push(15); 56 | llist.push(10); 57 | 58 | 59 | llist.head.next.next.next.next = llist.head; 60 | 61 | if (detectLoop(head)) 62 | System.out.println("Loop found"); 63 | else 64 | System.out.println("No Loop"); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Java programs/merge_sort.java: -------------------------------------------------------------------------------- 1 | /* Java program for Merge Sort */ 2 | class MergeSort 3 | { 4 | void merge(int arr[], int l, int m, int r) 5 | { 6 | 7 | int n1 = m - l + 1; 8 | int n2 = r - m; 9 | 10 | int L[] = new int[n1]; 11 | int R[] = new int[n2]; 12 | 13 | for (int i = 0; i < n1; ++i) 14 | L[i] = arr[l + i]; 15 | for (int j = 0; j < n2; ++j) 16 | R[j] = arr[m + 1 + j]; 17 | 18 | int i = 0, j = 0; 19 | 20 | int k = l; 21 | while (i < n1 && j < n2) { 22 | if (L[i] <= R[j]) { 23 | arr[k] = L[i]; 24 | i++; 25 | } 26 | else { 27 | arr[k] = R[j]; 28 | j++; 29 | } 30 | k++; 31 | } 32 | 33 | while (i < n1) { 34 | arr[k] = L[i]; 35 | i++; 36 | k++; 37 | } 38 | 39 | while (j < n2) { 40 | arr[k] = R[j]; 41 | j++; 42 | k++; 43 | } 44 | } 45 | 46 | void sort(int arr[], int l, int r) 47 | { 48 | if (l < r) { 49 | 50 | int m = l + (r - l) / 2; 51 | 52 | sort(arr, l, m); 53 | sort(arr, m + 1, r); 54 | 55 | 56 | merge(arr, l, m, r); 57 | } 58 | } 59 | 60 | static void printArray(int arr[]) 61 | { 62 | int n = arr.length; 63 | for (int i = 0; i < n; ++i) 64 | System.out.print(arr[i] + " "); 65 | System.out.println(); 66 | } 67 | 68 | public static void main(String args[]) 69 | { 70 | int arr[] = { 12, 11, 13, 5, 6, 7 }; 71 | 72 | System.out.println("Given Array"); 73 | printArray(arr); 74 | 75 | MergeSort ob = new MergeSort(); 76 | ob.sort(arr, 0, arr.length - 1); 77 | 78 | System.out.println("\nSorted array"); 79 | printArray(arr); 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /Java programs/removeduplicates.java: -------------------------------------------------------------------------------- 1 | /* java program of remove duplicates from single linked list */ 2 | public class Main { 3 | 4 | 5 | class Node{ 6 | int ta; 7 | Node se; 8 | 9 | public Node(int ta) { 10 | this.ta = ta; 11 | this.se = null; 12 | } 13 | } 14 | 15 | 16 | public Node head = null; 17 | public Node tail = null; 18 | 19 | 20 | public void addNode(int ta) { 21 | 22 | Node newNode = new Node(ta); 23 | 24 | 25 | if(head == null) { 26 | 27 | head = newNode; 28 | tail = newNode; 29 | } 30 | else { 31 | 32 | tail.se = newNode; 33 | 34 | tail = newNode; 35 | } 36 | } 37 | 38 | 39 | public void removeDuplicate() { 40 | 41 | Node current = head, index = null, c = null; 42 | 43 | if(head == null) { 44 | return; 45 | } 46 | else { 47 | while(current != null){ 48 | 49 | c= current; 50 | 51 | index = current.se; 52 | 53 | while(index != null) { 54 | 55 | if(current.ta == index.ta) { 56 | 57 | c.se = index.se; 58 | } 59 | else { 60 | 61 | c= index; 62 | } 63 | index = index.se; 64 | } 65 | current = current.se; 66 | } 67 | } 68 | } 69 | 70 | 71 | public void display() { 72 | 73 | Node current = head; 74 | if(head == null) { 75 | System.out.println("List is empty"); 76 | return; 77 | } 78 | while(current != null) { 79 | 80 | System.out.print(current.ta + " "); 81 | current = current.se; 82 | } 83 | System.out.println(); 84 | } 85 | 86 | public static void main(String[] args) { 87 | 88 | Main msli = new Main(); 89 | 90 | //Adds data to the list 91 | msli.addNode(1); 92 | msli.addNode(2); 93 | msli.addNode(3); 94 | msli.addNode(2); 95 | msli.addNode(2); 96 | msli.addNode(4); 97 | msli.addNode(1); 98 | 99 | System.out.println("Originals list: "); 100 | msli.display(); 101 | 102 | 103 | msli.removeDuplicate(); 104 | 105 | System.out.println("List after removing duplicates: "); 106 | msli.display(); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Java programs/stack.java: -------------------------------------------------------------------------------- 1 | /* Java program to implement basic stack operations */ 2 | 3 | class Stack { 4 | static final int MAX = 1000; 5 | int tp; 6 | int ss[] = new int[MAX]; 7 | 8 | boolean isEmp() 9 | { 10 | return (tp < 0); 11 | } 12 | Stack() 13 | { 14 | tp = -1; 15 | } 16 | 17 | boolean push(int pp) 18 | { 19 | if (tp >= (MAX - 1)) { 20 | System.out.println("Stack Overflow"); 21 | return false; 22 | } 23 | else { 24 | ss[++tp] = pp; 25 | System.out.println(pp + " pushed into stack"); 26 | return true; 27 | } 28 | } 29 | 30 | int pop() 31 | { 32 | if (tp < 0) { 33 | System.out.println("Stack Underflow"); 34 | return 0; 35 | } 36 | else { 37 | int pp= ss[tp--]; 38 | return pp; 39 | } 40 | } 41 | 42 | int peek() 43 | { 44 | if (tp < 0) { 45 | System.out.println("Stack Underflow"); 46 | return 0; 47 | } 48 | else { 49 | int pp = ss[tp]; 50 | return pp; 51 | } 52 | } 53 | 54 | void print(){ 55 | for(int i = tp;i>-1;i--){ 56 | System.out.print(" "+ ss[i]); 57 | } 58 | } 59 | } 60 | 61 | class Main { 62 | public static void main(String args[]) 63 | { 64 | Stack s = new Stack(); 65 | s.push(10); 66 | s.push(20); 67 | s.push(30); 68 | System.out.println(s.pop() + " Popped from stack"); 69 | System.out.println("Top element is :" + s.peek()); 70 | System.out.print("Elements present in stack :"); 71 | s.print(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Java programs/suduko.java: -------------------------------------------------------------------------------- 1 | //in this code we can find the missing terms of suduko 2 | //I am using recursion to solve it 3 | 4 | //parent class for suduko solve 5 | 6 | public class suduko { 7 | //solving by recursion 8 | //solve is recursive method 9 | public static boolean solve(char[][] board){ 10 | 11 | //checking for blank terms 12 | for (int i=0; i<9; i++) { 13 | for (int j=0; j<9; j++) { 14 | 15 | if(board[i][j]=='.'){ 16 | 17 | //run from 1 to 9 values 18 | for (char k='1'; k<='9'; k++) { 19 | //isTrue will check all the value which is not in row,column,3x3 box 20 | if(isTrue(board,i,j,k)){ 21 | 22 | board[i][j] = k; 23 | if(solve(board)){ 24 | return true; 25 | }else{ 26 | board[i][j] ='.'; 27 | } 28 | } 29 | } 30 | return false; 31 | } 32 | } 33 | } 34 | return true; 35 | } 36 | 37 | //class for creating board of suduko and call to suduko class 38 | //it will check for row,colunm and 3x3 matrix 39 | public static boolean isTrue(char[][] board, int row, int col, char k) { 40 | 41 | for (int i=0; i<9; i++) { 42 | //check in same row 43 | if (board[row][i]==k) return false; 44 | //check in same column 45 | if(board[i][col]==k) return false; 46 | //check in 3x3 in which it is prasent 47 | if(board[3*(row/3)+(i/3)][3*(col/3)+(i%3)]==k) return false; 48 | 49 | } 50 | return true; 51 | 52 | } 53 | //main method 54 | public static void main(String[] args) { 55 | 56 | //creating 2d array for suduko 57 | char[][] board= { 58 | {'9', '5', '7', '.', '1', '3', '.', '8', '4'}, 59 | {'4', '8', '3', '.', '5', '7', '1', '.', '6'}, 60 | {'.', '1', '2', '.', '4', '9', '5', '3', '7'}, 61 | {'1', '7', '.', '3', '.', '4', '9', '.', '2'}, 62 | {'5', '.', '4', '9', '7', '.', '3', '6', '.'}, 63 | {'3', '.', '9', '5', '.', '8', '7', '.', '1'}, 64 | {'8', '4', '5', '7', '9', '.', '6', '1', '3'}, 65 | {'.', '9', '1', '.', '3', '6', '.', '7', '5'}, 66 | {'7', '.', '6', '1', '8', '5', '4', '.', '9'} 67 | }; 68 | 69 | // calling solve to run program 70 | solve(board); 71 | 72 | //now answer is printing 73 | for (int i = 0; i < 9; i++){ 74 | for (int j = 0; j < 9; j++) { 75 | System.out.print(board[i][j]+" "); 76 | } 77 | System.out.println(); 78 | } 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Java programs/zerosumtriplet.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | class num { 4 | 5 | static void findTriplets(int[] arr, int n) 6 | { 7 | boolean found = false; 8 | for (int i = 0; i < n - 2; i++) { 9 | for (int j = i + 1; j < n - 1; j++) { 10 | for (int k = j + 1; k < n; k++) { 11 | if (arr[i] + arr[j] + arr[k] == 0) { 12 | System.out.println(arr[i] + " " 13 | + arr[j] + " " 14 | + arr[k]); 15 | found = true; 16 | } 17 | } 18 | } 19 | } 20 | 21 | 22 | if (found == false) 23 | System.out.println(" not exist "); 24 | } 25 | 26 | 27 | public static void main(String[] args) 28 | { 29 | int arr[] = { 0, -1, 2, -3, 1 }; 30 | int n = arr.length; 31 | findTriplets(arr, n); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 abhiramkg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Python/Calculator.py: -------------------------------------------------------------------------------- 1 | from kivy.app import App 2 | from kivy.uix.button import Button 3 | from kivy.uix.boxlayout import BoxLayout 4 | from kivy.uix.gridlayout import GridLayout # to make everything in a grid like 5 | #make all symbols in center ,proper space between row and column 6 | from kivy.uix.label import Label 7 | 8 | class Calculator(App): 9 | def build(self): 10 | root_widget = BoxLayout(orientation="vertical") 11 | output_label = Label(size_hint_y=0.75, font_size=50) 12 | button_symbols = ('1','2','3','+', 13 | '4','5','6','-', 14 | '7','8','9','.', 15 | '0','*','/','=') 16 | button_grid = GridLayout(cols=4, size_hint_y=2) 17 | for symbol in button_symbols: 18 | button_grid.add_widget(Button(text=symbol)) 19 | 20 | clear_button = Button(text="CLEAR", size_hint_y=None ,height=100) 21 | 22 | def print_button_text(instance): 23 | output_label.text += instance.text 24 | 25 | for button in button_grid.children[1:]: 26 | button.bind(on_press=print_button_text) 27 | 28 | def resize_label_text(label, new_height): 29 | label.fontsize = 0.5*label.height 30 | 31 | output_label.bind(height=resize_label_text) 32 | 33 | def evaluate_result(instance): 34 | try: 35 | output_label.text = str(eval(output_label.text)) 36 | except SyntaxError: 37 | output_label.text = "Python Syntax Error!" 38 | button_grid.children[0].bind(on_press=evaluate_result) 39 | 40 | def clear_label(instance): 41 | output_label.text=" " 42 | clear_button.bind(on_press=clear_label) 43 | 44 | root_widget.add_widget(output_label) 45 | root_widget.add_widget(button_grid) 46 | root_widget.add_widget(clear_button) 47 | return root_widget 48 | 49 | Calculator().run() 50 | -------------------------------------------------------------------------------- /Python/Creating _cross.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | tur = turtle.Turtle() 3 | def spiral(m,n): 4 | 5 | for i in range(m): 6 | tur.dot() 7 | tur.forward(n) 8 | tur.right(90) 9 | n=n-1 10 | tur.penup() 11 | spiral(40,40) 12 | -------------------------------------------------------------------------------- /Python/Python Program to check whether input is well-formatted: -------------------------------------------------------------------------------- 1 | #Q.Write a recursive python function which returns True if the input is well-formatted with respect to the list labels. Else it should return False. 2 | 3 | #We say that an input is well-formatted with respect to the labels if: 4 | #(a) input item is a list 5 | #(b) input item has length at least two 6 | #(c) input’s first item is in the list labels 7 | #(d) each of the remaining items in input is either a string or a well-formatted list 8 | 9 | 10 | def check_well_formatted(input_item,list_label): 11 | 12 | if isinstance(input_item, list)== False: 13 | return False 14 | 15 | if isinstance(input_item, list): 16 | flag=False 17 | if len(input_item)<2: 18 | return False 19 | if input_item[0] not in list_label: 20 | return False 21 | for i in range(1,len(input_item)): 22 | if isinstance(input_item[i] , list): 23 | flag = check_well_formatted(input_item[i],list_label) 24 | if flag==False: 25 | return False 26 | elif isinstance(input_item[i] , str)== False: 27 | return False 28 | else: 29 | flag = True 30 | return flag 31 | 32 | 33 | 34 | input_list1=['VP', ['V', 'eat']] 35 | list_label1=['VP', 'V'] 36 | result=check_well_formatted(input_list1,list_label1) 37 | if result is True: 38 | print("Well formatted") 39 | else: 40 | print("Not Well formatted") 41 | -------------------------------------------------------------------------------- /Python/Snake and Ladder/snake_and_ladder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhiramkg2000/HackOctober22/175fe0c6a49ddef7a2b5c761eddd5fd910dacc41/Python/Snake and Ladder/snake_and_ladder.png -------------------------------------------------------------------------------- /Web Development/Calculator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Simple Calculator using HTML, CSS and JavaScript 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 | -------------------------------------------------------------------------------- /Web Development/Calculator/script.js: -------------------------------------------------------------------------------- 1 | // This function clear all the values 2 | function clearScreen() { 3 | document.getElementById("result").value = ""; 4 | } 5 | 6 | // This function display values 7 | function display(value) { 8 | document.getElementById("result").value += value; 9 | } 10 | 11 | // This function evaluates the expression and returns result 12 | function calculate() { 13 | var p = document.getElementById("result").value; 14 | var q = eval(p); 15 | document.getElementById("result").value = q; 16 | } -------------------------------------------------------------------------------- /Web Development/Calculator/style.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Orbitron&display=swap'); 2 | .calculator { 3 | padding: 10px; 4 | border-radius: 1em; 5 | height: 380px; 6 | width: 400px; 7 | margin: auto; 8 | background-color: #191b28; 9 | box-shadow: rgba(0, 0, 0, 0.19) 0px 10px 20px, rgba(0, 0, 0, 0.23) 0px 6px 6px; 10 | } 11 | .display-box { 12 | font-family: 'Orbitron', sans-serif; 13 | background-color: #dcdbe1; 14 | border: solid black 0.5px; 15 | color: black; 16 | border-radius: 5px; 17 | width: 100%; 18 | height: 65%; 19 | } 20 | #btn { 21 | background-color: #fb0066; 22 | } 23 | input[type=button] { 24 | font-family: 'Orbitron', sans-serif; 25 | background-color: #64278f; 26 | color: white; 27 | border: solid black 0.5px; 28 | width: 100%; 29 | border-radius: 5px; 30 | height: 70%; 31 | outline: none; 32 | } 33 | input:active[type=button] { 34 | background: #e5e5e5; 35 | -webkit-box-shadow: inset 0px 0px 5px #c1c1c1; 36 | -moz-box-shadow: inset 0px 0px 5px #c1c1c1; 37 | box-shadow: inset 0px 0px 5px #c1c1c1; 38 | } -------------------------------------------------------------------------------- /Web Development/Digital StopWatch/app.js: -------------------------------------------------------------------------------- 1 | let [milliseconds, seconds, minutes, hours] = [0, 0, 0, 0]; 2 | let timerRef = document.querySelector('.timerDisplay'); 3 | let int = null; 4 | 5 | document.getElementById('startTimer').addEventListener('click', () => { 6 | if (int !== null) { 7 | clearInterval(int); 8 | } 9 | int = setInterval(displayTimer, 10); 10 | }); 11 | 12 | document.getElementById('pauseTimer').addEventListener('click', () => { 13 | clearInterval(int); 14 | }); 15 | 16 | document.getElementById('resetTimer').addEventListener('click', () => { 17 | clearInterval(int); 18 | [milliseconds, seconds, minutes, hours] = [0, 0, 0, 0]; 19 | timerRef.innerHTML = '00:00:00:000'; 20 | }); 21 | 22 | function displayTimer() { 23 | milliseconds += 10; 24 | if (milliseconds == 1000) { 25 | milliseconds = 0; 26 | seconds++; 27 | if (seconds == 60) { 28 | seconds = 0; 29 | minutes++; 30 | if (minutes == 60) { 31 | minutes = 0; 32 | hours++; 33 | } 34 | } 35 | } 36 | let h = hours < 10 ? "0" + hours : hours; 37 | let m = minutes < 10 ? "0" + minutes : minutes; 38 | let s = seconds < 10 ? "0" + seconds : seconds; 39 | let ms = milliseconds < 10 ? "00" + milliseconds : milliseconds < 100 ? "0" + milliseconds : milliseconds; 40 | 41 | timerRef.innerHTML = `${h}:${m}:${s}:${ms}`; 42 | } 43 | -------------------------------------------------------------------------------- /Web Development/Digital StopWatch/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Stop watch 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 |
13 | 00:00:00:000 14 |
15 | 16 |
17 | 18 | 19 | 20 |
21 |
22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Web Development/Digital StopWatch/stylesheet.css: -------------------------------------------------------------------------------- 1 | *, 2 | *:before, 3 | *:after { 4 | padding: 0; 5 | margin: 0; 6 | box-sizing: border-box; 7 | } 8 | 9 | .container { 10 | background-color: #141313; 11 | width: 40%; 12 | min-width: 500px; 13 | position: absolute; 14 | transform: translate(-50%, -50%); 15 | top: 50%; 16 | left: 50%; 17 | padding: 60px 0; 18 | border-radius: 10px; 19 | } 20 | 21 | .timerDisplay { 22 | position: relative; 23 | width: 110%; 24 | background: linear-gradient(-135deg, #0048ce, #008bfd); 25 | left: -5%; 26 | padding: 40px 0; 27 | font-family: 'Roboto mono', monospace; 28 | color: #ffffff; 29 | font-size: 40px; 30 | display: flex; 31 | align-items: center; 32 | justify-content: space-around; 33 | border-radius: 5px; 34 | box-shadow: 0 0 20px rgba(0, 139, 253, 0.25); 35 | } 36 | 37 | .buttons { 38 | width: 80%; 39 | margin: 60px auto 0 auto; 40 | display: flex; 41 | justify-content: space-around; 42 | } 43 | 44 | .buttons button { 45 | padding: 10px 20px; 46 | background-color: #ffffff; 47 | color: #141313; 48 | border: none; 49 | font-family: 'Poppins', sans-serif; 50 | font-size: 18px; 51 | border-radius: 5px; 52 | cursor: pointer; 53 | outline: none; 54 | } 55 | -------------------------------------------------------------------------------- /Web Development/Password Strength Checker/app.js: -------------------------------------------------------------------------------- 1 | let parameters = { 2 | count: false, 3 | letter: false, 4 | numbers: false, 5 | special: false 6 | } 7 | let strengthBar = document.getElementById("strength-bar"); 8 | let msg = document.getElementById("msg"); 9 | 10 | function strengthChecker() { 11 | let password = document.getElementById("password").value; 12 | 13 | parameters.letter = (/[A-Za-z]+/.test(password)) ? true : false; 14 | parameters.numbers = (/[0-9]+/.test(password)) ? true : false; 15 | parameters.special = (/[!\"$%&/()=?@~`\\.\';:+=^*_-]+/.test(password)) ? true : false; 16 | parameters.count = (password.length > 7) ? true : false; 17 | 18 | let barLength = Object.values(parameters).filter(value => value); 19 | 20 | console.log(Object.values(parameters), barLength); 21 | 22 | strengthBar.innerHTML = ""; 23 | for (let i in barLength) { 24 | let span = document.createElement("span"); 25 | span.classList.add("strength"); 26 | strengthBar.appendChild(span); 27 | } 28 | 29 | let spanRef = document.getElementsByClassName("strength"); 30 | for (let i = 0; i < spanRef.length; i++) { 31 | switch (spanRef.length - 1) { 32 | case 0: 33 | spanRef[i].style.background = "#ff3e36"; 34 | msg.textContent = "Your password is very weak"; 35 | break; 36 | case 1: 37 | spanRef[i].style.background = "ff691f"; 38 | msg.textContent = "Your password is weak"; 39 | break; 40 | case 2: 41 | spanRef[i].style.background = "#ffda36"; 42 | msg.textContent = "Your password is good"; 43 | break; 44 | case 3: 45 | spanRef[i].style.background = "#0be881"; 46 | msg.textContent = "Your password is strong"; 47 | break; 48 | } 49 | } 50 | } 51 | 52 | function toggle() { 53 | let password = document.getElementById("password"); 54 | let eye = document.getElementById("toggle"); 55 | 56 | if (password.getAttribute("type") == "password") { 57 | password.setAttribute("type", "text"); 58 | eye.style.color = "#0be881"; 59 | } else { 60 | password.setAttribute("type", "password"); 61 | eye.style.color = "#808080"; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Web Development/Password Strength Checker/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Password Strength Checker 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 | 18 | 19 | 20 |
21 |
22 |

23 |
24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Web Development/Password Strength Checker/stylesheet.css: -------------------------------------------------------------------------------- 1 | *, 2 | *:before, 3 | *:after{ 4 | padding:0; 5 | margin:0; 6 | box-sizing:border-box; 7 | } 8 | 9 | body{ 10 | height:100vh; 11 | background:linear-gradient(135deg, #61d954, #2ebf75); 12 | } 13 | 14 | .wrapper{ 15 | background-color:#ffffff; 16 | width:450px; 17 | padding:50px 0; 18 | position:absolute; 19 | transform:translate(-50%,-50%); 20 | left:50%; 21 | top:50%; 22 | border-radius:8px; 23 | box-shadow:0 20px 25px rgba(0,0,0,0.2); 24 | } 25 | 26 | .container{ 27 | width:300px; 28 | position:relative; 29 | margin:auto; 30 | } 31 | 32 | input,p{ 33 | font-family:"Roboto Mono",monospace; 34 | 35 | } 36 | 37 | input{ 38 | width:100%; 39 | height:50px; 40 | padding:0 40px 0 20px; 41 | position:relative; 42 | background-color:#f5f5f5; 43 | border:none; 44 | outline:none; 45 | border-radius:5px 5px 0 0; 46 | } 47 | 48 | #toggle{ 49 | position:absolute; 50 | top:17px; 51 | right:15px; 52 | color:#808080; 53 | cursor:pointer; 54 | } 55 | 56 | .strength{ 57 | width:25%; 58 | display:inline-block; 59 | position:relative; 60 | height:100%; 61 | bottom:5px; 62 | } 63 | 64 | #strength-bar{ 65 | background-color:#dcdcdc; 66 | height:10px; 67 | position:relative; 68 | } 69 | 70 | p{ 71 | width:100%; 72 | text-align:center; 73 | margin-top:20px; 74 | } 75 | -------------------------------------------------------------------------------- /Web Development/Rock Paper Scissors Game/app.js: -------------------------------------------------------------------------------- 1 | let [computer_score, user_score] = [0, 0]; 2 | let result_ref = document.getElementById("result"); 3 | let choices_object = { 4 | 'rock': { 5 | 'rock': 'draw', 6 | 'scissor': 'win', 7 | 'paper': 'lose' 8 | }, 9 | 'scissor': { 10 | 'rock': 'lose', 11 | 'scissor': 'draw', 12 | 'paper': 'win' 13 | }, 14 | 'paper': { 15 | 'rock': 'win', 16 | 'scissor': 'lose', 17 | 'paper': 'draw' 18 | } 19 | } 20 | 21 | function checker(input) { 22 | var choices = ["rock", "paper", "scissor"]; 23 | var num = Math.floor(Math.random() * 3); 24 | 25 | document.getElementById("comp_choice").innerHTML = `Computer choose ${choices[num].toUpperCase()}`; 26 | 27 | document.getElementById("user_choice").innerHTML = ` You choose ${input.toUpperCase()}`; 28 | 29 | let computer_choice = choices[num]; 30 | 31 | switch (choices_object[input][computer_choice]) { 32 | case 'win': 33 | result_ref.style.cssText = "background-color: #cefdce; color: #689f38"; 34 | result_ref.innerHTML = "YOU WIN"; 35 | user_score++; 36 | break; 37 | case 'lose': 38 | result_ref.style.cssText = "background-color:#ffdde0; color:#d32f2f"; 39 | result_ref.innerHTML = "YOU LOSE"; 40 | computer_score++; 41 | break; 42 | default: 43 | result_ref.style.cssText = "background-color: #e5e5e5; color: #808080"; 44 | result_ref.innerHTML = "DRAW"; 45 | break; 46 | } 47 | 48 | document.getElementById("computer_score").innerHTML = computer_score; 49 | document.getElementById("user_score").innerHTML = user_score; 50 | } 51 | -------------------------------------------------------------------------------- /Web Development/Rock Paper Scissors Game/download.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhiramkg2000/HackOctober22/175fe0c6a49ddef7a2b5c761eddd5fd910dacc41/Web Development/Rock Paper Scissors Game/download.jpg -------------------------------------------------------------------------------- /Web Development/Rock Paper Scissors Game/g.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhiramkg2000/HackOctober22/175fe0c6a49ddef7a2b5c761eddd5fd910dacc41/Web Development/Rock Paper Scissors Game/g.jpg -------------------------------------------------------------------------------- /Web Development/Rock Paper Scissors Game/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Rock Paper Scissor Game 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |

Computer: 19 | 0 20 |

21 |

22 | You: 23 | 0 24 |

25 |
26 |
27 | 29 | 31 | 33 |
34 |
35 |

36 |

37 |

38 |
39 |
40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Web Development/Rock Paper Scissors Game/stylesheet.css: -------------------------------------------------------------------------------- 1 | *, 2 | *:before, 3 | *:after{ 4 | padding:0; 5 | margin:0; 6 | box-sizing:border-box; 7 | 8 | } 9 | 10 | body{ 11 | height:100vh; 12 | background:linear-gradient(135deg, hsl(49, 100%, 54%), #d3965d); 13 | } 14 | 15 | .container{ 16 | background-image:url("download.jpg"); 17 | 18 | width:45%; 19 | min-width:500px; 20 | background-color:#ffffff; 21 | padding:40px 30px; 22 | position:absolute; 23 | transform:translate(-50%,-50%); 24 | top:50%; 25 | left:50%; 26 | border-radius:95px; 27 | box-shadow:0 15px 25px rgba(0,0,0,0.15); 28 | 29 | } 30 | .container:hover 31 | { 32 | 33 | box-shadow: 0 0 20px hsl(49, 86%, 61%),0 0 20px #ffd51b,0 0 20px hsl(49, 86%, 61%); 34 | } 35 | 36 | .scores{ 37 | margin-bottom:50px; 38 | text-align:right; 39 | } 40 | 41 | .weapons{ 42 | width:90%; 43 | margin:auto; 44 | display:flex; 45 | justify-content:space-around; 46 | } 47 | 48 | .weapons button{ 49 | background-color:#ffd51b; 50 | color:#000000; 51 | border:none; 52 | font-size:50px; 53 | height:100px; 54 | width:100px; 55 | border-radius:50%; 56 | outline:none; 57 | cursor:pointer; 58 | } 59 | .weapons button:hover 60 | { 61 | box-shadow: 0 0 20px hsl(49, 86%, 61%),0 0 20px #ffd51b,0 0 20px hsl(49, 86%, 61%); 62 | } 63 | 64 | .details{ 65 | margin-top:30px; 66 | text-align:center; 67 | 68 | } 69 | 70 | .scores, .details{ 71 | font-family:'Poppins',sans-serif; 72 | font-weight:400; 73 | font-size:15px; 74 | } 75 | 76 | #result{ 77 | width:180px; 78 | padding:10px 0; 79 | margin:30px auto; 80 | font-weight:600; 81 | letter-spacing:0.5px; 82 | border-radius: 10px; 83 | } 84 | 85 | #user_choice, 86 | #computer_choice{ 87 | font-weight:400; 88 | margin-bottom:10px; 89 | } 90 | 91 | span{ 92 | font-weight:600; 93 | } 94 | -------------------------------------------------------------------------------- /Web Development/TIC-TAC-TOE/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |

TIC TAC TOE

18 | 19 | 20 |

Game starts by just Tap on 21 | box

First Player starts as 22 | Player X
And
Second 23 | Player as Player 0 24 |

25 | 26 | 27 | 28 | 29 |

30 | 31 | 33 | 34 | 36 | 37 | 39 |

40 | 41 | 43 | 44 | 46 | 47 | 49 |

50 | 51 | 53 | 54 | 56 | 57 | 59 | 60 | 61 |


62 | 63 | 66 | 67 |

68 | 69 |

70 | 71 | 72 | 73 | 74 |
75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /Web Development/TIC-TAC-TOE/tic.css: -------------------------------------------------------------------------------- 1 | 2 | h1 { 3 | color: orangered; 4 | font-size: 45px; 5 | } 6 | 7 | /* 3*3 Grid */ 8 | #b1, #b2, #b3, #b4, #b5, 9 | #b6, #b7, #b8, #b9 { 10 | width: 80px; 11 | height: 52px; 12 | margin: auto; 13 | border: 1px solid gray; 14 | border-radius: 6px; 15 | font-size: 30px; 16 | text-align: center; 17 | } 18 | 19 | /* Reset Button */ 20 | #but { 21 | box-sizing: border-box; 22 | width: 95px; 23 | height: 40px; 24 | border: 1px solid dodgerblue; 25 | margin: auto; 26 | border-radius: 4px; 27 | font-family: Verdana, 28 | Geneva, Tahoma, sans-serif; 29 | 30 | background-color: dodgerblue; 31 | color: white; 32 | font-size: 20px; 33 | cursor: pointer; 34 | } 35 | 36 | /* Player turn space */ 37 | #print { 38 | font-family: Verdana, 39 | Geneva, Tahoma, sans-serif; 40 | 41 | color: dodgerblue; 42 | font-size: 20px; 43 | } 44 | 45 | /* Main Container */ 46 | #main { 47 | text-align: center; 48 | } 49 | 50 | /* Game Instruction Text */ 51 | #ins { 52 | font-family: Verdana, 53 | Geneva, Tahoma, sans-serif; 54 | 55 | color: dodgerblue; 56 | font-size: 17px; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Web Development/Typing Speed Test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Typing Speed Test 9 | 10 | 11 |
12 | 13 |
14 |
15 |

16 |
17 |
18 |
    19 |
  • 20 |

    Time Left:

    21 | 22 | 60s 23 | 24 |
  • 25 |
  • 26 |

    Mistakes:

    27 | 0 28 |
  • 29 |
  • 30 |

    WPM:

    31 | 0 32 |
  • 33 |
34 | 35 |
36 |
37 |
38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Web Development/Typing Speed Test/script.js: -------------------------------------------------------------------------------- 1 | const typingText = document.querySelector(".typing-text p"), 2 | inpField = document.querySelector(".wrapper .input-field"), 3 | tryAgainBtn = document.querySelector(".content button"), 4 | timeTag = document.querySelector(".time span b"), 5 | mistakeTag = document.querySelector(".mistake span"), 6 | wpmTag = document.querySelector(".wpm span"), 7 | cpmTag = document.querySelector(".cpm span"); 8 | 9 | let timer, 10 | maxTime = 60, 11 | timeLeft = maxTime, 12 | charIndex = mistakes = isTyping = 0; 13 | 14 | function loadParagraph() { 15 | const ranIndex = Math.floor(Math.random() * paragraphs.length); 16 | typingText.innerHTML = ""; 17 | paragraphs[ranIndex].split("").forEach(char => { 18 | let span = `${char}` 19 | typingText.innerHTML += span; 20 | }); 21 | typingText.querySelectorAll("span")[0].classList.add("active"); 22 | document.addEventListener("keydown", () => inpField.focus()); 23 | typingText.addEventListener("click", () => inpField.focus()); 24 | } 25 | 26 | function initTyping() { 27 | let characters = typingText.querySelectorAll("span"); 28 | let typedChar = inpField.value.split("")[charIndex]; 29 | if(charIndex < characters.length - 1 && timeLeft > 0) { 30 | if(!isTyping) { 31 | timer = setInterval(initTimer, 1000); 32 | isTyping = true; 33 | } 34 | if(typedChar == null) { 35 | if(charIndex > 0) { 36 | charIndex--; 37 | if(characters[charIndex].classList.contains("incorrect")) { 38 | mistakes--; 39 | } 40 | characters[charIndex].classList.remove("correct", "incorrect"); 41 | } 42 | } else { 43 | if(characters[charIndex].innerText == typedChar) { 44 | characters[charIndex].classList.add("correct"); 45 | } else { 46 | mistakes++; 47 | characters[charIndex].classList.add("incorrect"); 48 | } 49 | charIndex++; 50 | } 51 | characters.forEach(span => span.classList.remove("active")); 52 | characters[charIndex].classList.add("active"); 53 | 54 | let wpm = Math.round(((charIndex - mistakes) / 5) / (maxTime - timeLeft) * 60); 55 | wpm = wpm < 0 || !wpm || wpm === Infinity ? 0 : wpm; 56 | 57 | wpmTag.innerText = wpm; 58 | mistakeTag.innerText = mistakes; 59 | cpmTag.innerText = charIndex - mistakes; 60 | } else { 61 | clearInterval(timer); 62 | inpField.value = ""; 63 | } 64 | } 65 | 66 | function initTimer() { 67 | if(timeLeft > 0) { 68 | timeLeft--; 69 | timeTag.innerText = timeLeft; 70 | let wpm = Math.round(((charIndex - mistakes) / 5) / (maxTime - timeLeft) * 60); 71 | wpmTag.innerText = wpm; 72 | } else { 73 | clearInterval(timer); 74 | } 75 | } 76 | 77 | function resetGame() { 78 | loadParagraph(); 79 | clearInterval(timer); 80 | timeLeft = maxTime; 81 | charIndex = mistakes = isTyping = 0; 82 | inpField.value = ""; 83 | timeTag.innerText = timeLeft; 84 | wpmTag.innerText = 0; 85 | mistakeTag.innerText = 0; 86 | cpmTag.innerText = 0; 87 | } 88 | 89 | loadParagraph(); 90 | inpField.addEventListener("input", initTyping); 91 | tryAgainBtn.addEventListener("click", resetGame); 92 | -------------------------------------------------------------------------------- /Web Development/file_handling/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /Web Development/file_handling/app.js: -------------------------------------------------------------------------------- 1 | //core modules 2 | // const http = require("http"); 3 | 4 | //3rd party modules 5 | const express = require("express"); 6 | 7 | //own modules 8 | // const file_store = require("./file_store"); 9 | 10 | // fs.writeFileSync("hello.text", "Where is my node"); 11 | 12 | const app = express(); 13 | 14 | // app.use((req, res, next) => { 15 | // console.log("in worlddd of hello"); 16 | 17 | // next(); 18 | // }); 19 | 20 | // app.use((req, res, next) => { 21 | // console.log("in worlddd of hellossss"); 22 | // res.send("yoooo"); 23 | // }); 24 | 25 | app.use("/users", (req, res, next) => { 26 | res.send("Yoo users"); 27 | }); 28 | 29 | app.use("/", (req, res, next) => { 30 | res.send("in worlddd of hello"); 31 | }); 32 | 33 | // const server = http.createServer(app); 34 | 35 | // server.listen(3000); 36 | 37 | app.listen(3000); 38 | -------------------------------------------------------------------------------- /Web Development/file_handling/file_store.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const file_store = (req, res) => { 3 | const url = req.url; 4 | const method = req.method; 5 | 6 | if (url === "/") { 7 | res.write(""); 8 | res.write(""); 9 | res.write( 10 | "
" 11 | ); 12 | res.write(""); 13 | res.write(""); 14 | 15 | return res.end(); 16 | } 17 | if (url === "/message" && method === "POST") { 18 | const body = []; 19 | 20 | req.on("data", (chunk) => { 21 | console.log(chunk); 22 | body.push(chunk); 23 | }); 24 | req.on("end", () => { 25 | const parsedBody = Buffer.concat(body).toString(); 26 | console.log(parsedBody); 27 | const message = parsedBody.split("=")[1]; 28 | fs.writeFileSync("message.txt", message); 29 | }); 30 | 31 | return res.end(); 32 | } 33 | 34 | res.setHeader("Content-Type", "text/html"); 35 | res.write(""); 36 | res.write(""); 37 | res.write("

hello from mrigesh

"); 38 | res.write(""); 39 | res.write(""); 40 | 41 | res.end(); 42 | }; 43 | 44 | module.exports = file_store; 45 | -------------------------------------------------------------------------------- /Web Development/file_handling/hello.text: -------------------------------------------------------------------------------- 1 | Where is my node -------------------------------------------------------------------------------- /Web Development/file_handling/meesage.txt: -------------------------------------------------------------------------------- 1 | Dummy -------------------------------------------------------------------------------- /Web Development/file_handling/message.txt: -------------------------------------------------------------------------------- 1 | mehul -------------------------------------------------------------------------------- /Web Development/file_handling/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "file_handling", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "nodemon app.js" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "express": "^4.18.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Web Development/loginPage/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 37 | 38 | -------------------------------------------------------------------------------- /Web Development/netflix clone/script.js: -------------------------------------------------------------------------------- 1 | let accordian = document.getElementsByClassName("FAQ__title"); 2 | 3 | for (let i = 0; i < accordian.length; i++) { 4 | accordian[i].addEventListener("click", function () { 5 | if (this.childNodes[1].classList.contains("fa-plus")) { 6 | this.childNodes[1].classList.remove("fa-plus"); 7 | this.childNodes[1].classList.add("fa-times"); 8 | } else { 9 | this.childNodes[1].classList.remove("fa-times"); 10 | this.childNodes[1].classList.add("fa-plus"); 11 | } 12 | 13 | let content = this.nextElementSibling; 14 | if (content.style.maxHeight) { 15 | content.style.maxHeight = null; 16 | } else { 17 | content.style.maxHeight = content.scrollHeight + "px"; 18 | } 19 | }); 20 | } -------------------------------------------------------------------------------- /Web Development/simpleTabs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Tabs Using HTML CSS 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 |
19 |

Tab One

20 |

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et 21 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 22 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu 23 | fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia 24 | deserunt mollit anim id est laborum.

25 |

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et 26 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 27 | ex ea commodo consequat

28 |
29 | 30 | 31 | 32 | 33 |
34 |

Tab Two

35 |

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et 36 | dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 37 | ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu 38 | fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia 39 | deserunt mollit anim id est laborum.

40 |
41 |
42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Web Development/simpleTabs/style.css: -------------------------------------------------------------------------------- 1 | /* 2 | To use in personal projects try changing the following attributes for better integration : 3 | 4 | body { 5 | min-height, max-width 6 | padding and margins 7 | } 8 | 9 | .tabs label{ 10 | padding, margins 11 | } 12 | */ 13 | 14 | :root{ 15 | --box-shadow:0 1px 10px rgba(0,0,0,0.5) , 16 | 0 1px 10px rgba(0,0,0,0.5); 17 | } 18 | 19 | @import url('https://fonts.googleapis.com/css2?family=Outfit:wght@100;200;300;400;500;600;700;800;900&display=swap'); 20 | 21 | body { 22 | background: #000000; 23 | min-height: 100vh; 24 | box-sizing: border-box; 25 | padding-top: 10vh; 26 | font-weight: 300; 27 | line-height: 1.5; 28 | max-width: 60rem; 29 | margin: 0 auto; 30 | font-size: 112%; 31 | } 32 | 33 | .tabs { 34 | display: flex; 35 | flex-wrap: wrap; 36 | font-family: 'Outfit', sans-serif; 37 | } 38 | 39 | .tabs label { 40 | order: 1; 41 | display: block; 42 | padding: 1rem 2rem; 43 | margin-right: 0.2rem; 44 | cursor: pointer; 45 | background: #fff; 46 | font-weight: bold; 47 | transition: ease 0.2s; 48 | border-radius: 10px 10px 0 0; 49 | } 50 | 51 | .tabs .tab { 52 | order: 99; 53 | flex-grow: 1; 54 | width: 100%; 55 | display: none; 56 | padding: 1rem; 57 | background: #fff; 58 | border-radius: 0 10px 10px 10px; 59 | box-shadow: var(--box-shadow); 60 | } 61 | 62 | .tabs input[type="radio"] { 63 | display: none; 64 | } 65 | 66 | .tabs input[type="radio"]:checked+label { 67 | background-color: #FF9F29; 68 | } 69 | 70 | .tabs input[type="radio"]:checked+label+.tab { 71 | display: block; 72 | } -------------------------------------------------------------------------------- /Web Development/stylishStaticCV/Readme.md: -------------------------------------------------------------------------------- 1 |

Hacktoberfest2022

2 | 3 | A simple personal site / CV to showcase your skills. Code filled with comments to help you with almost any issue.
4 | Dark Mode❤️ 5 |
6 |
7 | Screenshot 1 8 | S2 9 |
10 |
11 | Screenshot 2 12 | S2 13 |
14 |
15 | Screenshot 3 16 | S3 17 |
18 |
19 |
20 | Publish your site for free! : [GitHub Pages](https://docs.github.com/en/pages/quickstart) 21 | -------------------------------------------------------------------------------- /Web Development/stylishStaticCV/images/Cat.webm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhiramkg2000/HackOctober22/175fe0c6a49ddef7a2b5c761eddd5fd910dacc41/Web Development/stylishStaticCV/images/Cat.webm -------------------------------------------------------------------------------- /Web Development/stylishStaticCV/images/Productivity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhiramkg2000/HackOctober22/175fe0c6a49ddef7a2b5c761eddd5fd910dacc41/Web Development/stylishStaticCV/images/Productivity.png -------------------------------------------------------------------------------- /Web Development/stylishStaticCV/images/clouds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhiramkg2000/HackOctober22/175fe0c6a49ddef7a2b5c761eddd5fd910dacc41/Web Development/stylishStaticCV/images/clouds.png -------------------------------------------------------------------------------- /Web Development/stylishStaticCV/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhiramkg2000/HackOctober22/175fe0c6a49ddef7a2b5c761eddd5fd910dacc41/Web Development/stylishStaticCV/images/favicon.ico -------------------------------------------------------------------------------- /Web Development/stylishStaticCV/images/mountain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhiramkg2000/HackOctober22/175fe0c6a49ddef7a2b5c761eddd5fd910dacc41/Web Development/stylishStaticCV/images/mountain.png -------------------------------------------------------------------------------- /Web Development/toDoList/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Expense Tracker 8 | 9 | 10 | 11 |
12 |

Expense Tracker

13 |

Your Balance

14 |

₹00.00

15 | 16 |
17 | 18 |
19 |

Income

20 |

₹00.00

21 |
22 | 23 |
24 |

Expense

25 |

₹00.00

26 |
27 | 28 |
29 | 30 |
31 |

History

32 |
    33 |
  • 34 |
  • 35 |
36 |
37 | 38 |
39 |

Add New Transaction

40 |
41 |
42 | 43 | 44 |
45 |
46 | 47 | 48 |
49 | 50 |
51 |
52 | 53 |
54 | 55 | -------------------------------------------------------------------------------- /Web Development/toDoList/script.js: -------------------------------------------------------------------------------- 1 | const balance = document.getElementById("balance"); 2 | const credit = document.getElementById("credit"); 3 | const debit = document.getElementById("debit"); 4 | const allRecs = document.getElementById("allRecs"); 5 | const form = document.getElementById("form"); 6 | const details = document.getElementById("details"); 7 | const amount = document.getElementById("amount"); 8 | 9 | const localStorageTransactions = JSON.parse(localStorage.getItem('transactions')); 10 | let transactions = localStorage.getItem('transactions') !== null ? localStorageTransactions : []; 11 | 12 | //Add Transaction 13 | function addTransaction(e){ 14 | e.preventDefault(); 15 | if(details.value.trim() === ''){ 16 | alert("Please Enter Details"); 17 | }else if(amount.value.trim() === ''){ 18 | alert("Please Enter Amount"); 19 | } 20 | else { 21 | const transaction = { 22 | id: generateID(), 23 | details: details.value, 24 | amount: +amount.value 25 | } 26 | 27 | transactions.push(transaction); 28 | 29 | addTransactionDOM(transaction); 30 | 31 | updateLocalStorage(); 32 | updateValues(); 33 | details.value = ''; 34 | amount.value = ''; 35 | } 36 | } 37 | 38 | //Generate ID 39 | function generateID() { 40 | return Math.floor(Math.random() * 100000000); 41 | } 42 | 43 | function addTransactionDOM(transaction) { 44 | const sign = transaction.amount < 0 ? "-" : "+"; 45 | const item = document.createElement("li"); 46 | 47 | item.classList.add( 48 | transaction.amount < 0 ? "recDebit" : "recCredit" 49 | ); 50 | 51 | item.innerHTML = ` 52 | ${transaction.details}${sign}${Math.abs(transaction.amount)} 53 | 55 | `; 56 | 57 | allRecs.appendChild(item); 58 | } 59 | 60 | //Delete Transaction 61 | function delTransaction(id){ 62 | transactions = transactions.filter(transaction => transaction.id !== id) 63 | updateLocalStorage(); 64 | Init(); 65 | } 66 | 67 | //Update Balance 68 | function updateValues() { 69 | const amounts = transactions.map((transaction) => transaction.amount); 70 | const total = amounts.reduce((acc, item) => (acc += item), 0).toFixed(2); 71 | const income = amounts 72 | .filter((item) => item > 0) 73 | .reduce((acc, item) => (acc += item), 0) 74 | .toFixed(2); 75 | const expense = ( 76 | amounts.filter((item) => item < 0).reduce((acc, item) => (acc += item), 0) * 77 | -1).toFixed(2); 78 | 79 | balance.innerText = `₹${total}`; 80 | credit.innerText = `₹${income}`; 81 | debit.innerText = `₹${expense}`; 82 | } 83 | 84 | //Local Storage 85 | function updateLocalStorage(){ 86 | localStorage.setItem( 87 | "transactions", JSON.stringify(transactions) 88 | ) 89 | } 90 | 91 | //Init App 92 | function Init() { 93 | allRecs.innerHTML = ""; 94 | transactions.forEach(addTransactionDOM); 95 | updateValues(); 96 | } 97 | 98 | Init(); 99 | 100 | form.addEventListener('submit',addTransaction); 101 | -------------------------------------------------------------------------------- /Web Development/toDoList/style.css: -------------------------------------------------------------------------------- 1 | :root{ 2 | --box-shadow:0 1px 3px rgba(0,0,0,0.12) , 3 | 0 1px 3px rgba(0,0,0,0.24); 4 | } 5 | 6 | *{ 7 | box-sizing: border-box; 8 | } 9 | 10 | body{ 11 | display: flex; 12 | flex-direction: column; 13 | align-items: center; 14 | height: 100vh; 15 | margin: 0; 16 | font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; 17 | background-color: #172031; 18 | color: white; 19 | } 20 | 21 | #balance{ 22 | font-size: 25px; 23 | } 24 | 25 | h1{ 26 | margin-top: auto; 27 | } 28 | 29 | h2{ 30 | font-size: 25px; 31 | margin-bottom: -18px; 32 | } 33 | 34 | .mainCont{ 35 | margin: 30px auto; 36 | width: 400px; 37 | padding: 40px; 38 | background: rgba(0, 0, 0, .5); 39 | box-shadow: var(--box-shadow); 40 | border-radius: 10px; 41 | } 42 | 43 | h3{ 44 | border-bottom: 1px solid #bbb; 45 | padding-bottom: 4px ; 46 | } 47 | 48 | .transCont{ 49 | display: flex; 50 | justify-content: center; 51 | margin: 20px 0; 52 | } 53 | 54 | .transCont div{ 55 | flex: 1; 56 | text-align: center; 57 | } 58 | 59 | .transCont div:first-of-type{ 60 | border-right: 1px solid #bbb; 61 | } 62 | 63 | #credit{ 64 | color: green; 65 | font-size: larger; 66 | } 67 | 68 | #debit{ 69 | color: red; 70 | font-size: larger; 71 | } 72 | 73 | .histCont{ 74 | margin-bottom: 50px; 75 | } 76 | 77 | label{ 78 | display: inline-block; 79 | margin: 10px 0; 80 | } 81 | 82 | input{ 83 | border:1px solid #dedede; 84 | border-radius: 2px; 85 | display: block; 86 | font-size: 16px; 87 | padding: 10px; 88 | width: 100%; 89 | } 90 | 91 | .exec{ 92 | cursor: pointer; 93 | background-color: #FF9F29; 94 | box-shadow: var(--box-shadow); 95 | color: #fff; 96 | display: block; 97 | border: 0px; 98 | margin: 10px 0 30px; 99 | padding: 10px; 100 | width: 100%; 101 | } 102 | 103 | .exec:focus, del:focus{ 104 | outline: 0; 105 | } 106 | 107 | .allRecs{ 108 | list-style-type:none; 109 | padding: 0; 110 | margin-bottom: 40px; 111 | } 112 | 113 | .recCredit,.recDebit{ 114 | background-color: #fff; 115 | box-shadow: var(--box-shadow); 116 | color: #323; 117 | display: flex; 118 | justify-content: space-between; 119 | position: relative; 120 | margin: 10px 0; 121 | padding: 10px; 122 | } 123 | 124 | .recCredit{ 125 | border-right: 5px solid green; 126 | } 127 | 128 | .recDebit{ 129 | border-right: 5px solid red; 130 | } 131 | 132 | .del{ 133 | cursor: pointer; 134 | background-color: #fc344b; 135 | box-shadow: var(--box-shadow); 136 | border: 0; 137 | position: absolute; 138 | top: 50%; 139 | left: 0; 140 | transform: translate(-100%,-50%); 141 | opacity: 1; 142 | transition: opacity 0.3s ease; 143 | } 144 | 145 | .recCredit:hover .del{ 146 | opacity: 1; 147 | } 148 | 149 | .del img{ 150 | width: 30px; 151 | height: 34px; 152 | padding: 2px 5px; 153 | } 154 | 155 | .detCont{ 156 | margin-top: -15px; 157 | } -------------------------------------------------------------------------------- /Web Development/toDoList/trashbin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abhiramkg2000/HackOctober22/175fe0c6a49ddef7a2b5c761eddd5fd910dacc41/Web Development/toDoList/trashbin.png -------------------------------------------------------------------------------- /Web Development/todoslist project/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | To-Do's List 7 | 8 | 9 | 10 | 11 | 12 |
13 |

To-do list

14 | 15 |
16 | 17 | 18 |
19 | 20 |
21 |
    22 |
  • add some work
  • 23 |
  • add some work
  • 24 |
25 |
26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Web Development/todoslist project/script.js: -------------------------------------------------------------------------------- 1 | 2 | const input = document.querySelector("#add"); 3 | const btn = document.querySelector("#btn"); 4 | const list = document.querySelector("#list"); 5 | var el = document.getElementsByTagName('li'); 6 | 7 | btn.onclick = function(){ 8 | 9 | var txt = input.value; 10 | if(txt ==''){ 11 | alert('you must write something'); 12 | }else{ 13 | li = document.createElement('li'); 14 | li.innerHTML = txt; 15 | list.insertBefore(li,list.childNodes[0]); 16 | input.value = ''; 17 | } 18 | 19 | }; 20 | 21 | 22 | list.onclick = function(ev){ 23 | if(ev.target.tagName == 'LI'){ 24 | ev.target.classList.toggle('checked'); 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /Web Development/todoslist project/style.css: -------------------------------------------------------------------------------- 1 | 2 | @import url('https://fonts.googleapis.com/css?family=Nunito&display=swap'); 3 | *{ 4 | margin: 0; 5 | padding: 0; 6 | outline: 0; 7 | } 8 | body 9 | { 10 | background: #f6d365 11 | } 12 | 13 | .container 14 | { 15 | position: absolute; 16 | left: 50%; 17 | top: 50%; 18 | transform: translate(-50%,-50%); 19 | background-color: #fafafa; 20 | box-shadow: 0 2px 8px rgba(0,0,0,.16); 21 | width: 460px; 22 | height: 680px; 23 | text-align: center; 24 | font-family: 'Nunito',sans-serif; 25 | 26 | } 27 | h1 28 | { 29 | margin: 12px 0; 30 | } 31 | .add-elements{ 32 | margin: 12px 0; 33 | 34 | } 35 | input{ 36 | padding: 6px 4px; 37 | width: 70%; 38 | } 39 | button{ 40 | padding: 7px 14px; 41 | background-color: #00b0ff; 42 | border: none; 43 | border-radius: 4px; 44 | color: #fafafa; 45 | 46 | } 47 | .element-list{ 48 | height: 550px; 49 | overflow-y: scroll 50 | } 51 | ul{ 52 | padding: 15px; 53 | 54 | } 55 | li{ 56 | list-style: none; 57 | padding: 10px 5px; 58 | background-color: #fff; 59 | margin: 12px 0; 60 | box-shadow: 0 2px 8px rgba(0,0,0,.16); 61 | border-radius: 3px; 62 | transition: .4s; 63 | } 64 | button:hover{ 65 | background-color: #1565c0; 66 | } 67 | 68 | li:hover{ 69 | background-color: #e0e0e0; 70 | } 71 | 72 | .checked{ 73 | text-decoration: line-through; 74 | background-color: #e0e0e0; 75 | } 76 | --------------------------------------------------------------------------------