├── .github ├── FUNDING.yml └── ISSUE_TEMPLATE │ └── contribution.md ├── .idea └── .gitignore ├── C++ ├── Kosaraju's algorithm.cpp ├── Kruskal Algorithm.cpp ├── Program - 28 │ ├── program-28.cpp │ └── readme.md ├── Program 22 │ ├── adding_two_string.cpp │ └── readme.md ├── Program 23 │ ├── readme.md │ └── sum_of_square_of_binomial_coefficient.cpp ├── Program 26 │ ├── PrimeNo.cpp │ └── ReadMe.md ├── Program 28 │ ├── README.md │ └── menu driven linear search.cpp ├── Program 29 │ ├── DecimaltoBinary.cpp │ └── Readme.md ├── Program-01 │ ├── Program.cpp │ └── README.md ├── Program-10 │ ├── program.cpp │ └── readme.md ├── Program-12 │ ├── README.md │ └── program.cpp ├── Program-13 │ ├── README.md │ └── program.cpp ├── Program-14 │ ├── README.md │ └── program.cpp ├── Program-15 │ └── program.cpp ├── Program-16 │ ├── README.md │ └── rightangle.cpp ├── Program-17 │ ├── README.md │ └── randomcolorscreen.cpp ├── Program-18 │ ├── README.md │ └── getWeekday.cpp ├── Program-2 │ ├── Readme.md │ └── number_of_occurrence.cpp ├── Program-20 │ ├── README.md │ └── program.cpp ├── Program-21 │ ├── README.md │ └── program.cpp ├── Program-3 │ ├── Readme.md │ └── program.cpp ├── Program-30 │ ├── README.md │ └── program.c ├── Program-4 │ ├── README.md │ ├── program.cpp │ └── readme.md ├── Program-5 │ ├── Readme.md │ └── program.cpp ├── Program-6 │ ├── Readme.md │ └── program.cpp ├── Program-7 │ ├── program.cpp │ └── readme.md ├── Program-8 │ ├── README.md │ └── program.cpp ├── Program-9 │ ├── program.cpp │ └── readme.md ├── Program11 │ ├── Program11.cpp │ └── ReadMe.txt ├── Program18 │ ├── PrintSeries.cpp │ └── Readme.md ├── Program_24 │ ├── HexaDecimal-Decimal.cpp │ └── README.md ├── Program_25 │ ├── Queues_Using_Linked_Lists.cpp │ └── README.md ├── Program_26 │ ├── README.md │ └── StacksUsingLL.cpp ├── Program_27 │ ├── Polynomial_Expression.cpp │ └── README.md ├── README.md ├── See wifi pass.cpp ├── Sparse Table.cpp ├── program 29 │ ├── PROGRAM.CPP │ └── README.md ├── program-10 │ ├── Program10.cpp │ └── Readme.txt ├── program-19 │ ├── Read me.md │ └── palindrome.cpp ├── program-26 │ └── Cycle_Detection_in Directed_Graph.cpp └── program_30 │ └── operator_overloading.cpp ├── C ├── README.md ├── program-1 │ ├── README.md │ └── program.c ├── program-10 │ ├── README.md │ └── program.c ├── program-11 │ ├── README.md │ └── program.c ├── program-12 │ ├── README.md │ └── program.c ├── program-13 │ ├── README.md │ └── program.c ├── program-14 │ ├── README.md │ └── program.c ├── program-15 │ ├── program.c │ └── readme.md ├── program-16 │ ├── program.c │ └── readme.md ├── program-17 │ ├── README.md │ └── program.c ├── program-18 │ ├── README.md │ └── program.c ├── program-19 │ └── program.c ├── program-2 │ ├── README.md │ └── program.c ├── program-20 │ └── program.c ├── program-21 │ └── program.c ├── program-22 │ └── program.c ├── program-23 │ └── program.c ├── program-24 │ └── program.c ├── program-25 │ ├── program.c │ └── readme.md ├── program-26 │ └── program.c ├── program-27 │ └── program.c ├── program-28 │ └── program.c ├── program-29 │ └── program.c ├── program-3 │ ├── README.md │ └── program.c ├── program-30 │ └── program.c ├── program-31 │ └── program.c ├── program-32 │ └── program.c ├── program-33 │ └── program.c ├── program-34 │ └── program.c ├── program-35 │ └── program.c ├── program-36 │ └── program.c ├── program-37 │ └── program.c ├── program-38 │ └── program.c ├── program-39 │ └── program.c ├── program-4 │ ├── README.md │ └── program.c ├── program-40 │ └── program.c ├── program-41 │ └── program.c ├── program-42 │ └── program.c ├── program-43 │ └── program.c ├── program-44 │ └── program.c ├── program-45 │ └── program.c ├── program-46 │ └── program.c ├── program-47 │ ├── Readme.md │ ├── program 47.c │ └── program.c ├── program-48 │ ├── README.md │ └── program.c ├── program-49 │ ├── README.md │ └── program.c ├── program-5 │ ├── README.md │ └── program.c ├── program-50 │ ├── Readme.md │ └── program.c ├── program-51 │ ├── README.md │ └── program.c ├── program-52 │ ├── README.md │ └── program.c ├── program-53 │ ├── Readme.md │ └── program.c ├── program-54 │ ├── Readme.md │ └── program.c ├── program-55 │ ├── program.c │ └── readme.md ├── program-56 │ ├── README.md │ └── program.c ├── program-57 │ ├── program.c │ └── readme.md ├── program-58 │ ├── Program.c │ └── readme.md ├── program-59 │ ├── program.c │ └── readme.md ├── program-6 │ ├── README.md │ └── program.c ├── program-60 │ ├── program.c │ └── readme.md ├── program-61 │ └── program.c ├── program-62 │ └── program.c ├── program-63 │ ├── README.md │ └── program.c ├── program-64 │ ├── ArmstrongNumber.c │ └── README.md ├── program-65 │ ├── README.md │ └── program.c ├── program-66 │ ├── README.md │ └── fibonacciSeries.c ├── program-67 │ └── program.c ├── program-68 │ ├── program-68.c │ └── readme.md ├── program-69 │ ├── README.md │ └── strongNumber.c ├── program-7 │ ├── README.md │ └── program.c ├── program-70 │ ├── README.md │ └── program70.c ├── program-71 │ └── program.c ├── program-72 │ ├── program.c │ └── readme.md ├── program-74 │ ├── program.c │ └── readme.md ├── program-77 │ ├── program.c │ └── readme.md ├── program-78 │ ├── program.c │ └── readme.md ├── program-79 │ ├── program.c │ └── readme.md ├── program-8 │ ├── README.md │ └── program.c ├── program-80 │ └── program.c ├── program-81 │ ├── README.md │ └── program.c ├── program-82 │ ├── README.md │ └── program.c ├── program-83 │ ├── README.md │ ├── polynomial.c │ ├── program-83.c │ ├── program.c │ └── readme.md ├── program-84 │ ├── program.c │ ├── program84.c │ └── readme.md ├── program-86 │ ├── README.md │ └── fibonacci.c ├── program-9 │ ├── README.md │ └── program.c ├── sample.c └── samzmaths.c ├── Dart ├── Program1 │ ├── README.md │ └── checkevenodd.dart └── README.md ├── Interview Questions ├── Stack using Array │ ├── README.MD │ └── implementing_stack_using_array_and_linked_list.c ├── Trapping Rain Water │ ├── README.md │ └── Trapping Rain Water.cpp └── Two Sum Problem │ └── two_sum.py ├── Java ├── Program 21 │ └── Quick_Sort.java ├── Program 5 │ ├── README.md.txt │ └── program.java.txt ├── Program 6 │ ├── README.md.txt │ └── program.java.txt ├── Program-11 │ ├── Program.java │ └── Readme.md ├── Program-12 │ └── Program-12.java ├── Program-13 │ └── Program Number to Word.java ├── Program-16 │ ├── CSAOfCylinder.class │ ├── CSAOfCylinder.java │ └── README.md ├── Program-17 │ ├── ReverseString.java │ └── readme.md ├── Program-18 │ ├── ElectricityBill.java │ └── readme.md ├── Program-19 │ ├── Discount.java │ └── readme.md ├── Program-20 │ ├── BattingAverage.java │ └── readme.md ├── Program-21 │ ├── K_Equal_Sum_Subset.java │ └── readme.md ├── Program-8 │ ├── README.md │ └── program.java ├── Program.java ├── Readme.md ├── program-1 │ ├── README.md │ └── program.java ├── program-10 │ ├── Program.java │ └── Readme.md ├── program-14 │ ├── program.java │ └── readme.md ├── program-15 │ ├── program.java │ └── readme.md ├── program-2 │ ├── README.md │ └── program.java ├── program-3 │ ├── README.md │ └── program.java ├── program-4 │ ├── README.md │ └── program.java ├── program-7 │ ├── README.md │ └── program.java └── program-9 │ ├── Readme.md │ └── program.java ├── Javascript ├── README.md ├── program - 16 │ ├── program-16.js │ └── read.md ├── program- 17 │ ├── index.html │ ├── p5.js │ ├── p5.sound.min.js │ ├── sketch.js │ └── style.css ├── program-1 │ ├── program-1.html │ └── read.md ├── program-10 │ ├── program-10.html │ └── read.md ├── program-11 │ ├── program.js │ └── readme.md ├── program-12 │ └── program.js ├── program-13 │ └── program.js ├── program-14 │ └── program.js ├── program-15 │ └── program.js ├── program-16 │ ├── index.html │ ├── index.js │ └── readme.md ├── program-2 │ ├── program-2.html │ └── read.md ├── program-3 │ ├── program-3.html │ └── read.md ├── program-4 │ ├── program-4.html │ └── read.md ├── program-5 │ ├── program-5.html │ └── read.md ├── program-6 │ ├── program-6.html │ └── read.md ├── program-7 │ ├── program-7.html │ ├── program.js │ └── read.md ├── program-8 │ ├── program-8.html │ └── read.md └── program-9 │ ├── program-9.html │ └── read.md ├── Program-28 ├── Bin Packing Problem.cpp └── Readme.md ├── Python ├── Program 35 │ ├── Program35.py │ └── readme.md ├── Program 42 │ ├── program42.py │ └── readme.md ├── Program 48 │ └── Find_area _of_triangle.py ├── Program-21 │ ├── Program 21.py.txt │ └── README.md.txt ├── Program-22 │ ├── Plot_function │ ├── Program 22.py.txt │ ├── README.md │ └── README.md.txt ├── Program-23 │ ├── Program 23.py.txt │ └── README.md.txt ├── Program-24 │ ├── Program 24.txt │ └── README.md.txt ├── Program-25 │ ├── Program 25.py.txt │ └── README.md.txt ├── Program-26 │ ├── Program 26.py.txt │ └── README.md.txt ├── Program-27 │ ├── Program 27.txt │ └── README.md.txt ├── Program-28 │ ├── Program 28.txt │ └── README.md.txt ├── Program-29 │ ├── Program 29.py │ └── README.md ├── Program-3 │ └── program.py ├── Program-30 │ ├── README.md │ └── program.py ├── Program-31 │ ├── Program 31.py │ └── README.md ├── Program-33 │ ├── Program33.py │ └── Readme.md ├── Program-36 │ ├── Program-36.py │ └── README.md ├── Program-48 │ ├── .DS_Store │ ├── Find_area _of_triangle.py │ ├── README.md │ ├── laneDectectionVideo.py │ └── media │ │ ├── averagedLines.jpg │ │ ├── carDashCam.mp4 │ │ ├── edgeFrame.png │ │ ├── final.gif │ │ ├── gaussianFrame.png │ │ ├── grayFrame.png │ │ ├── houghLinesFrame.png │ │ ├── originalFrame.png │ │ ├── output.mp4 │ │ ├── roiFrame.png │ │ └── roiMask.png ├── Program34 │ ├── Program34.py │ └── Readme.md ├── Program43 │ ├── Program43.py │ └── Readme.md ├── Program44 │ ├── Program44.py │ └── Readme.md ├── Program45 │ ├── Program45.py │ └── Readme.md ├── Program46 │ ├── Program46.py │ └── Readme.md ├── Program47 │ ├── Program47.py │ └── Readme.md ├── README.md ├── program-1 │ └── program.py ├── program-10 │ └── program.py ├── program-11 │ └── program.py ├── program-12 │ └── program.py ├── program-13 │ ├── program.py │ └── readme.md ├── program-14 │ └── program.py ├── program-15 │ └── program.py ├── program-16 │ └── program.py ├── program-17 │ └── program.py ├── program-18 │ └── program.py ├── program-19 │ └── program.py ├── program-2 │ └── program.py ├── program-20 │ └── program.py ├── program-32 │ ├── Program32.py │ ├── Readme (2).md │ ├── program.py │ └── readme.md ├── program-4 │ └── program.py ├── program-40 │ ├── BasicGraphs.py │ └── Readme.md.txt ├── program-41 │ ├── README.md │ └── TicTacToe Game.py ├── program-5 │ ├── README.md │ ├── pragram.py │ └── program.py ├── program-6 │ ├── README.md │ └── program.py ├── program-7 │ ├── program.py │ └── readme.md ├── program-8 │ ├── program.py │ └── readme.md └── program-9 │ └── program.py ├── colorgame.py ├── currencyconvertor.py ├── flask app ├── app.py ├── static │ ├── 1.jpg │ └── 1.png └── templates │ └── index.html ├── gif └── giphy.gif ├── index.html ├── kotlin ├── Program1 │ ├── README.md │ └── pattern.kt ├── Program2 │ ├── README.md │ └── extension.kt ├── Program3 │ ├── README.md │ └── filterList.kt └── README.md ├── pattern.py ├── program.py ├── readme.md └── src ├── css └── index.css ├── images └── 1.jpg └── js └── index.js /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: https://www.buymeacoffee.com/swaazshetty 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/contribution.md: -------------------------------------------------------------------------------- 1 | # Contribution 2 | - Fork this [repo](https://github.com/swaaz/basicprograms) 3 | - Clone it using command : 4 |
 $ git clone paste_the_copied_url.
5 | - Open folder "basicprograms" : 6 |
$ cd basicprograms
7 | - Open folder "C/Python" : 8 |
$ cd folder_name
9 | eg:cd C 10 | - Create new branch : 11 |
 $ git branch new_branch_name
12 | eg:git branch swaaz 13 | - Checkout to new branch from master branch : 14 |
$ git checkout new_branch_name
15 | eg-git checkout swaaz 16 | ## Check whether the program which you want is exist in the _readme_ file 17 | ### If it's existing then don't waste your time by adding it again and think of adding some other program 18 | ### If it's not existing then 19 | - Create a new folder 20 |
 $ mkdir program-number 
21 | eg:mkdir program-35 22 | - Change directory to the new created folder 23 |
 $ cd folder_name 
24 | - Create a file *program.c* 25 | - Write the code inside program.c file 26 | ### NOTE: Before writng code refer [*sample*](https://github.com/swaaz/basicprograms/blob/swaaz/C/sample.c) file and write the code in the same format as given 27 | - Add file : 28 |
$ git add -A
29 | - Commit file : 30 |
$ git commit -m "comment"
31 | eg-git commit -m "program added" 32 | - Push the file : 33 |
$ git push origin -u 'branch_name'
34 | eg-git push origin -u swaaz 35 | - The given link should be copied and pasted in web browser or go to your repo in web browser 36 | - Create a pull request 37 | - tag @swaaz under review section 38 | ## If you are contributing for the first time,then : 39 | [click here](https://gitme.js.org/) 40 | 41 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /C++/Program - 28/program-28.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to find number of bins required using 2 | // next fit algorithm. 3 | #include 4 | using namespace std; 5 | 6 | // Returns number of bins required using next fit 7 | // online algorithm 8 | int nextFit(int weight[], int n, int c) 9 | { 10 | // Initialize result (Count of bins) and remaining 11 | // capacity in current bin. 12 | int res = 0, bin_rem = c; 13 | 14 | // Place items one by one 15 | for (int i = 0; i < n; i++) { 16 | // If this item can't fit in current bin 17 | if (weight[i] > bin_rem) { 18 | res++; // Use a new bin 19 | bin_rem = c - weight[i]; 20 | } 21 | else 22 | bin_rem -= weight[i]; 23 | } 24 | return res; 25 | } 26 | 27 | // Driver program 28 | int main() 29 | { 30 | int weight[] = { 2, 5, 4, 7, 1, 3, 8 }; 31 | int c = 10; 32 | int n = sizeof(weight) / sizeof(weight[0]); 33 | cout << "Number of bins required in Next Fit : " 34 | << nextFit(weight, n, c); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /C++/Program - 28/readme.md: -------------------------------------------------------------------------------- 1 | ## Given n items of different weights and bins each of capacity c, assign each item to a bin such that number of total used bins is minimized. It may be assumed that all items have weights smaller than bin capacity. 2 | 3 | ### Example: Input: weight[] = {4, 8, 1, 4, 2, 1} Bin Capacity c = 10 Output: 2 We need minimum 2 bins to accommodate all items First bin contains {4, 4, 2} and second bin {8, 1, 1} 4 | 5 | ### Input: weight[] = {9, 8, 2, 2, 5, 4} Bin Capacity c = 10 Output: 4 We need minimum 4 bins to accommodate all items. 6 | 7 | ### Input: weight[] = {2, 5, 4, 7, 1, 3, 8}; Bin Capacity c = 10 Output: 3 -------------------------------------------------------------------------------- /C++/Program 22/adding_two_string.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Program : To add 2 string 3 | 4 | this Program is Contributed by Abhishek Jaiswal 5 | */ 6 | 7 | #include 8 | using namespace std; 9 | 10 | int Len(string &str1, string &str2) 11 | { 12 | int len1 = str1.size(); 13 | int len2 = str2.size(); 14 | if (len1 < len2) 15 | { 16 | for (int i = 0 ; i < len2 - len1 ; i++) 17 | str1 = '0' + str1; 18 | return len2; 19 | } 20 | else if (len1 > len2) 21 | { 22 | for (int i = 0 ; i < len1 - len2 ; i++) 23 | str2 = '0' + str2; 24 | } 25 | return len1; 26 | } 27 | 28 | string add( string a, string b ) 29 | { 30 | string result; 31 | int len = Len(a, b); 32 | 33 | int carry = 0; 34 | for (int i = len-1 ; i >= 0 ; i--) 35 | { 36 | int aBit = a.at(i) - '0'; 37 | int bBit = b.at(i) - '0'; 38 | int sum = (aBit ^ bBit ^ carry)+'0'; 39 | 40 | result = (char)sum + result; 41 | carry = (aBit & bBit) | (bBit & carry) | (aBit & carry); 42 | } 43 | 44 | if (carry) 45 | result = '1' + result; 46 | 47 | return result; 48 | } 49 | 50 | int main() 51 | { 52 | string str1,str2; 53 | cout<<"Enter the string 1 :"; 54 | cin>>str1; 55 | cout<<"Enter the string 2 :"; 56 | cin>>str2; 57 | cout << "Sum is " << add(str1, str2); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /C++/Program 22/readme.md: -------------------------------------------------------------------------------- 1 | Program : To add Two Binary Number 2 | Input : Two Number consitising of 0 and 1 3 | Output : Number Constisting of 0 and 1 4 | -------------------------------------------------------------------------------- /C++/Program 23/readme.md: -------------------------------------------------------------------------------- 1 | Program :To find the sum of square of binomial coefficient 2 | Input : Integer 3 | Output : Integer 4 | 5 | -------------------------------------------------------------------------------- /C++/Program 23/sum_of_square_of_binomial_coefficient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Program :To find the sum of square of 3 | binomial coefficient. 4 | 5 | This Program is contributed by Abhishek Jaiswal 6 | */ 7 | #include 8 | using namespace std; 9 | 10 | int factorial(int begin, int end) 11 | { 12 | int num = 1; 13 | for (int i = begin; i <= end; i++) 14 | num *= i; 15 | 16 | return num; 17 | } 18 | 19 | int square(int n) 20 | { 21 | return factorial(n + 1, 2 * n) / factorial(1, n); 22 | } 23 | 24 | int main() 25 | { 26 | int n; 27 | cout << "Enter the number :"; 28 | cin >> n; 29 | cout << "The Sum of Square is " << square(n) << endl; 30 | return 0; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /C++/Program 26/PrimeNo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n,k=0; 5 | cout<<"Check the no is prime or not"<>n; 7 | for(int i=1;i<=n;i++){ 8 | if(n%i==0){ 9 | k++; 10 | } 11 | } 12 | if(k==2){ 13 | cout<<"No. is Prime"; 14 | } 15 | else{ 16 | cout<<"No. is not prime"; 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C++/Program 26/ReadMe.md: -------------------------------------------------------------------------------- 1 | Program to check whether the no. is prime or not 2 | 3 | Input: 6 4 | Output: No. is not prime 5 | 6 | Input: 5 7 | Output: No. is prime -------------------------------------------------------------------------------- /C++/Program 28/README.md: -------------------------------------------------------------------------------- 1 | program for linear search using menu driven program -------------------------------------------------------------------------------- /C++/Program 28/menu driven linear search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define R 3 4 | #define C 3 5 | int enter(int arr[R][C], int r, int c) 6 | { 7 | 8 | for(int i=0; i>arr[i][j]; 14 | } 15 | } 16 | } 17 | int display(int arr[R][C], int r, int c) 18 | { 19 | cout<<".................the matrix is ................"<>item; 34 | 35 | for(int i=0; i>ch; 60 | switch(ch) 61 | { 62 | case 1 : 63 | { 64 | enter(arr,R,C); 65 | break; 66 | } 67 | case 2: 68 | { 69 | display(arr,R,C); 70 | break; 71 | } 72 | case 3: 73 | { 74 | search(arr,R,C); 75 | break; 76 | } 77 | default: 78 | { 79 | cout<<"invalid choice"; 80 | } 81 | } 82 | } 83 | while(ch!=3); 84 | return 0; 85 | } 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /C++/Program 29/DecimaltoBinary.cpp: -------------------------------------------------------------------------------- 1 | // number to binary number 2 | 3 | #include 4 | using namespace std; 5 | 6 | // function to convert decimal to binary 7 | void decToBinary(int n) 8 | { 9 | // array to store binary number 10 | int binaryNum[32]; 11 | 12 | // counter for binary array 13 | int i = 0; 14 | while (n > 0) { 15 | 16 | // storing remainder in binary array 17 | binaryNum[i] = n % 2; 18 | n = n / 2; 19 | i++; 20 | } 21 | 22 | // printing binary array in reverse order 23 | for (int j = i - 1; j >= 0; j--) 24 | cout << binaryNum[j]; 25 | } 26 | 27 | // Driver program to test above function 28 | int main() 29 | { 30 | int n = 17; 31 | decToBinary(n); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C++/Program 29/Readme.md: -------------------------------------------------------------------------------- 1 | THE PROGRAM IS FOR THE BINARY SEARCH 2 | -------------------------------------------------------------------------------- /C++/Program-01/Program.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #include 4 | int main() { 5 | cout<<"Enter the number of elements "<>n;//Input the size of array 8 | int arr[n]; 9 | int min=INT_MAX; 10 | int max=INT_MIN; 11 | cout<<"Enter the elements"<>arr[i]; 15 | if(arr[i]max)//if current element is greater than max 18 | max=arr[i];//max is updated 19 | } 20 | cout<<"Minimum element is:"< 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int firstUniqChar(string s) { 8 | unordered_map m; 9 | 10 | for(int i=0; s[i]; i++) 11 | m[s[i]]++; 12 | 13 | for(int i=0; s[i]; i++) 14 | if(m[s[i]] == 1) 15 | return i; 16 | 17 | return -1; 18 | 19 | } 20 | }; 21 | 22 | int main(){ 23 | Solution S; 24 | string s; 25 | getline(cin,s); 26 | cout< 2 | 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | string longestPalindrome(string s) { 8 | if(s.empty() || s.length() < 1) return ""; 9 | 10 | int start = 0; 11 | int end = 0; 12 | 13 | for(int i=0;i end - start){ 19 | start = i - ((len-1)/2); 20 | end = i + (len/2); 21 | } 22 | 23 | } 24 | return s.substr(start,end-start+1); 25 | } 26 | int MiddleExpand(string s,int left,int right){ 27 | if(s.empty() || left > right) return 0; 28 | 29 | while(left >= 0 && right < s.length() && s.at(left)==s.at(right)){ 30 | left--; 31 | right++; 32 | } 33 | return right-left-1; 34 | } 35 | }; 36 | 37 | int main(){ 38 | string s; 39 | getline(cin,s); 40 | 41 | Solution sol; 42 | cout< 2 | using namespace std; 3 | 4 | /* 5 | Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product. 6 | 7 | Example 1: 8 | 9 | Input: [2,3,-2,4] 10 | Output: 6 11 | Explanation: [2,3] has the largest product 6. 12 | Example 2: 13 | 14 | Input: [-2,0,-1] 15 | Output: 0 16 | Explanation: The result cannot be 2, because [-2,-1] is not a subarray. 17 | */ 18 | class Solution { 19 | public: 20 | //O(n) O(1) 21 | int maxProduct(vector& nums) { 22 | int max_overall = nums[0]; 23 | int max_ending_here = nums[0], min_ending_here = nums[0]; 24 | 25 | for(int i=1;i v; 39 | int n;cin>>n; 40 | for(int i=0;i>x; 42 | v.push_back(x); 43 | } 44 | cout< 8 | using namespace std; 9 | 10 | // This function returns value of (x^y)%mod. 11 | int power(int x, int y, int mod) 12 | { 13 | int answer = 1; // Initialise the answer 14 | 15 | x = x % mod; 16 | 17 | if(x == 0) return 0; // If x is divisible by mod 18 | 19 | while(y > 0) 20 | { 21 | if(y % 2 == 1) // If y is odd multiply x with answer 22 | { 23 | answer = (answer*x) % mod; 24 | } 25 | 26 | y /= 2; // reduce the value of y 27 | x = (x*x) % mod; // increment the value of x 28 | } 29 | 30 | return answer; 31 | } 32 | 33 | 34 | // Main function 35 | int main() 36 | { 37 | int x = 2, y = 10, mod = 1000000007; 38 | int result = power(x, y, mod); 39 | cout << result << '\n'; 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /C++/Program-16/README.md: -------------------------------------------------------------------------------- 1 | # Program for right angled patterns 2 | -------------------------------------------------------------------------------- /C++/Program-16/rightangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | int i, space, rows, k=1; 8 | 9 | cout<<"Enter the number of rows: "; 10 | cin>>rows; 11 | 12 | for(i=1; i<=rows; i++) { 13 | for(space=i; space 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | 9 | int color; 10 | int bcolor; 11 | int x,y; 12 | int d; 13 | 14 | //init random to return random value each time 15 | randomize(); 16 | //clears the screen 17 | clrscr(); 18 | 19 | //infinite loop until key is not pressed 20 | while(!kbhit()) 21 | { 22 | //gerenate randon text and background color 23 | color =rand()%16; 24 | bcolor=rand()%16; 25 | 26 | //define text color 27 | textcolor(color); 28 | //define background color 29 | textbackground(bcolor); 30 | //check if both colors are same, continue the loop 31 | if(color==bcolor) 32 | continue; 33 | 34 | //generate random X and Y Co-ordinates 35 | x = rand()%75; 36 | y = rand()%20; 37 | //define position to print the text 38 | gotoxy(x,y); 39 | //print the text 40 | cprintf("IncludeHelp"); 41 | //delay 42 | delay(100); 43 | } 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /C++/Program-18/README.md: -------------------------------------------------------------------------------- 1 | # Program to get weekday with given day. 2 | -------------------------------------------------------------------------------- /C++/Program-18/getWeekday.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //function to get date and return weekday number [0-6] 5 | int getWeekDay(int yy, int mm, int dd) 6 | { 7 | //formula to get weekday number 8 | int rst = 9 | dd 10 | + ((153 * (mm + 12 * ((14 - mm) / 12) - 3) + 2) / 5) 11 | + (365 * (yy + 4800 - ((14 - mm) / 12))) 12 | + ((yy + 4800 - ((14 - mm) / 12)) / 4) 13 | - ((yy + 4800 - ((14 - mm) / 12)) / 100) 14 | + ((yy + 4800 - ((14 - mm) / 12)) / 400) 15 | - 32045; 16 | 17 | return (rst+1)%7 ; 18 | } 19 | 20 | //main program/code 21 | int main() 22 | { 23 | //declaring array of weekdays` 24 | const char *Names[] = {"Sunday","Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday"}; 25 | int day = 0; 26 | int y,m,d; 27 | cin>>y; 28 | cin>>m; 29 | cin>>d; 30 | //calling function, storing weekday number in day 31 | day= getWeekDay(y,m,d); 32 | //printing the weekday from given array 33 | cout<<"Day : "< 5 | n = size of array/ number of element 6 | x = Element to be counted in array 7 | count = veriable to count the X-number in array 8 | -------------------------------------------------------------------------------- /C++/Program-2/number_of_occurrence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Solution{ 6 | public: 7 | 8 | /* 9 | if x is present in arr[] then returns the count 10 | of occurrences of x, otherwise returns 0. 11 | */ 12 | 13 | int count(int arr[], int n, int x) { 14 | 15 | int count = 0; 16 | for(int i=0;i> n ; 32 | cout<<"Enter a number to be counted: "; 33 | cin>>x; 34 | int arr[n]; 35 | for (int i = 0; i < n; i++) { 36 | cin >> arr[i]; 37 | } 38 | Solution ob; 39 | auto ans = ob.count(arr, n, x); 40 | cout<< "number "< 2 | using namespace std; 3 | 4 | 5 | float square_root(int num,int p) { 6 | int s=0; 7 | int e=num; 8 | float ans=-1; 9 | while(s<=e) { 10 | int mid=s+e>>1; // (s+e)/2 11 | if(mid*mid==num) { 12 | return mid; 13 | } 14 | else if(mid*mid>=num) { 15 | e=mid-1; 16 | 17 | } 18 | else { //as 7*7 is vey close to 50 19 | s=mid+1; 20 | ans=mid; 21 | } 22 | } 23 | 24 | //for floating part 25 | //brute force 26 | float inc=0.1; 27 | for(int i=1;i<=p;i++) { 28 | while(ans*ans<=num) { 29 | ans=ans+inc; 30 | } 31 | //when this blows up 32 | ans=ans-inc;//comeback 1 step 33 | inc/=10; 34 | } 35 | return ans; 36 | 37 | } 38 | 39 | int main() { 40 | int num,p; 41 | cin>>num;///the input number of which you want to find the square root 42 | cin>>p;//find the square root upto "p" no of places 43 | cout< 4 | using namespace std; 5 | typedef long long int ll; 6 | 7 | void solve() 8 | { 9 | ll n = 0, m = 0; 10 | int b[60] = {0, 1, 2, 4, 7, 2, 0, 3, 4, 8, 3, 2, 6, 9, 6, 6, 3, 0, 4, 5, 0, 6, 7, 4, 2, 7, 0, 8, 9, 8, 8, 7, 6, 4, 1, 6, 8, 5, 4, 0, 5, 6, 2, 9, 2, 2, 5, 8, 4, 3, 8, 2, 1, 4, 6, 1, 8, 0, 9, 0}; 11 | int i = 0, j = 0, sum = 0; 12 | 13 | cin >> n >> m; 14 | 15 | i = (n-1) % 60; 16 | j = m % 60; 17 | 18 | if(b[j] >= b[i]) 19 | { 20 | cout << b[j] - b[i] << "\n"; 21 | } 22 | else 23 | { 24 | b[j] += 10; 25 | cout << b[j] - b[i] << "\n"; 26 | } 27 | } 28 | 29 | int main() 30 | { 31 | //for fast input output 32 | ios_base::sync_with_stdio(false);cin.tie(NULL); 33 | 34 | solve(); 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /C++/Program-3/Readme.md: -------------------------------------------------------------------------------- 1 | Program to Swap the Kth Elements of a series. 2 | variable description --> 3 | n = number of elements/size 4 | k = Kth element for swaping 5 | -------------------------------------------------------------------------------- /C++/Program-3/program.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std ; 4 | 5 | void takeInput(int a[], int n){ 6 | for(int i=1;i<=n;i++){ 7 | cin>>a[i]; 8 | } 9 | } 10 | 11 | void swap_k(int a[], int n, int k){ 12 | 13 | int i , count = n ; 14 | for(i=1 ; i<=n , count >= 1 ; i++ , count--){ 15 | 16 | if(k == i || k == count){ 17 | swap(a[k],a[count]); 18 | } 19 | 20 | } 21 | 22 | for(i=1;i<=n;i++){ 23 | cout<>n ; 33 | 34 | int k; 35 | cout<<"Enter Kth element to swap:"; 36 | cin>>k ; 37 | 38 | int a[1000]; 39 | takeInput(a,n); 40 | 41 | swap_k(a,n,k); 42 | cout<<"\n"; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /C++/Program-30/README.md: -------------------------------------------------------------------------------- 1 | Program to convert number in characters. 2 | -------------------------------------------------------------------------------- /C++/Program-30/program.c: -------------------------------------------------------------------------------- 1 | //Program to convert number in characters 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | long int n,sum=0,r; 7 | cout<<"Enter the Number= "; 8 | cin>>n; 9 | while(n>0) 10 | { 11 | r=n%10; 12 | sum=sum*10+r; 13 | n=n/10; 14 | } 15 | n=sum; 16 | while(n>0) 17 | { 18 | r=n%10; 19 | switch(r) 20 | { 21 | case 1: 22 | cout<<"one "; 23 | break; 24 | case 2: 25 | cout<<"two "; 26 | break; 27 | case 3: 28 | cout<<"three "; 29 | break; 30 | case 4: 31 | cout<<"four "; 32 | break; 33 | case 5: 34 | cout<<"five "; 35 | break; 36 | case 6: 37 | cout<<"six "; 38 | break; 39 | case 7: 40 | cout<<"seven "; 41 | break; 42 | case 8: 43 | cout<<"eight "; 44 | break; 45 | case 9: 46 | cout<<"nine "; 47 | break; 48 | case 0: 49 | cout<<"zero "; 50 | break; 51 | default: 52 | cout<<"tttt "; 53 | break; 54 | } 55 | n=n/10; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /C++/Program-4/README.md: -------------------------------------------------------------------------------- 1 | Program -4 2 | Program to find the reverse of a string 3 | -------------------------------------------------------------------------------- /C++/Program-4/program.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int n,size=200,fact[size],j=size-1,carry=0; 9 | cin>>n; 10 | fact[size-1]=1; 11 | while(n>1){ 12 | int x; 13 | for(int k=size-1;k>=j;k--){ 14 | x=fact[k]*n+carry; 15 | fact[k]=x%10; 16 | carry=x/10;} 17 | while(carry>0){ 18 | fact[--j]= carry%10; 19 | carry/=10;} 20 | n--; 21 | } 22 | for(int k=j;k 2 | using namespace std; 3 | 4 | int main() { 5 | cout<<"enter the number\n"; 6 | int n; 7 | cin>>n; 8 | int temp, rem, sum = 0; 9 | temp = n; 10 | while(temp>0) 11 | { 12 | rem = temp%10; 13 | temp = temp/10; 14 | sum+=rem; 15 | } 16 | cout<<"\nThe sum is "< 2 | using namespace std; 3 | int gcd(int x,int y) 4 | { 5 | if(y==0) 6 | return x; 7 | return gcd(y,x%y); 8 | } 9 | 10 | int main() { 11 | cout<<"enter the numbers\n"; 12 | int x,y; 13 | cin>>x>>y; 14 | cout<<"The GCD is "< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int rows, n = 1; 7 | 8 | cout << "Enter number of rows: \n"; 9 | cin >> rows; 10 | 11 | for(int i = 0; i < rows; i++) 12 | { 13 | for(int line = 1; line <= rows-i; line++) 14 | cout <<" "; 15 | 16 | for(int j = 0; j <= i; j++) 17 | { 18 | if (j == 0 || i == 0) 19 | n = 1; 20 | else 21 | n = n*(i-j+1)/j; 22 | 23 | cout << n << " "; 24 | } 25 | cout << endl; 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C++/Program-7/readme.md: -------------------------------------------------------------------------------- 1 | C++ Program to print Pascal' triangle -------------------------------------------------------------------------------- /C++/Program-8/README.md: -------------------------------------------------------------------------------- 1 | Program to reverse the given string. -------------------------------------------------------------------------------- /C++/Program-8/program.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | string s; 6 | cout<<"Enter the string"<>s; 8 | int n=s.length(); 9 | for (int i = 0; i < n / 2; i++) 10 | swap(s[i], s[n - i - 1]); 11 | cout< 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | void main() { 9 | 10 | string str; 11 | char cstr[100]; 12 | cin.getline(cstr, 100); 13 | str = cstr; 14 | for (int i = 0; i < str.length(); i++) { 15 | if (i == 0) 16 | str[i] = toupper(str[i]); 17 | else if (str[i - 1] == ' ') 18 | str[i] = toupper(str[i]); 19 | } 20 | cout << "\n" << str; 21 | } -------------------------------------------------------------------------------- /C++/Program11/ReadMe.txt: -------------------------------------------------------------------------------- 1 | this program Camel cases an input sentence 2 | 3 | Example: 4 | input: Camel case this sentence 5 | output: Camel ase This Sentence -------------------------------------------------------------------------------- /C++/Program18/PrintSeries.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void printSeries(int num1,int num2){ 6 | int count = 1; 7 | int i = 1; 8 | while(count < num1+1){ 9 | int num = (3 * i) + 2; 10 | i++; 11 | 12 | if((num % num2) == 0){ 13 | 14 | }else{ 15 | cout<>num1>>num2; 25 | printSeries(num1,num2); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /C++/Program18/Readme.md: -------------------------------------------------------------------------------- 1 | ## Problem 2 | 3 | ```bash 4 | Write a function which prints first num1 terms of the series 3n+2 which are not multiples of num2. 5 | ``` 6 | 7 | ## Take Input 8 | ```bash 9 | Number 1(num1) 10 | Number 2(num2) 11 | 0 < num1 < 100 & 0 < num2 < 100 12 | ``` 13 | 14 | ## Sample Input 15 | 16 | ```bash 17 | num1 = 10; 18 | num2 = 4; 19 | ``` 20 | ## Sample Output 21 | 22 | ```bash 23 | 5 24 | 11 25 | 14 26 | 17 27 | 23 28 | 26 29 | 29 30 | 35 31 | 38 32 | 41 33 | ``` 34 | -------------------------------------------------------------------------------- /C++/Program_24/HexaDecimal-Decimal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int convert(string n){ 4 | int sum=0,s; 5 | int x=1; 6 | s = n.size(); 7 | for (int i = s-1; i >=0; i--) 8 | { 9 | if(n[i]>='0'&&n[i]<='9'){ 10 | sum += x*(n[i]-'0'); 11 | } 12 | else if(n[i]>='A'&&n[i]<='F'){ 13 | sum += x* (n[i]-'A'+ 10); 14 | } 15 | x *= 16; 16 | } 17 | return sum; 18 | } 19 | int main(){ 20 | string n; 21 | cin>>n; 22 | int d=convert(n); 23 | cout< 3 | using namespace std; 4 | 5 | class node{ 6 | public: 7 | int data; 8 | node *link; 9 | }*front=NULL,*rear=NULL; 10 | 11 | void enqueue(int x){ 12 | node *t; 13 | t = new node; 14 | if(t==NULL) 15 | cout<<"Queue is Full"<data = x; 18 | t->link = NULL; 19 | } 20 | if(front==NULL){ 21 | front = rear = t; 22 | } 23 | else{ 24 | rear->link=t; 25 | rear = t; 26 | } 27 | } 28 | 29 | int dequeue(){ 30 | node *p; 31 | int x = -1; 32 | if(front==NULL) 33 | cout<<"Queue is Empty!"<link; 36 | x = p->data; 37 | delete p; 38 | } 39 | return x; 40 | } 41 | 42 | void display(){ 43 | node *p=front; 44 | while(p){ 45 | cout<data<<" "; 46 | p = p->link; 47 | } 48 | cout<>c; 57 | switch (c) 58 | { 59 | case '1': 60 | cout<<"Enter the element : "; 61 | cin>>x; 62 | enqueue(x); 63 | break; 64 | case '2': 65 | x=dequeue(); 66 | if(x!=-1) 67 | cout<<"Deleted element is "< 3 | using namespace std; 4 | class node{ 5 | public: 6 | int data; 7 | node *link; 8 | }*top=NULL; 9 | 10 | void push(int x){ 11 | node *t; 12 | t = new node; 13 | if(t==NULL){ 14 | cout<<"Stack is full[Satck overflow]"<data = x; 18 | t->link = top; 19 | top = t; 20 | } 21 | } 22 | 23 | void display(node *p){ 24 | while(p){ 25 | cout<data<<" "; 26 | p = p->link; 27 | } 28 | cout<link; 38 | x = p->data; 39 | delete p; 40 | } 41 | return x; 42 | 43 | } 44 | 45 | int main(){ 46 | 47 | int x; 48 | char c; 49 | while(1){ 50 | cout<<"Choose an Operation : \n1.Push\n2.Pop\n3.Display\n4.Exit"<>c; 52 | switch (c) 53 | { 54 | case '1': 55 | cout<<"Enter the element : "; 56 | cin>>x; 57 | push(x); 58 | break; 59 | case '2': 60 | x=pop(); 61 | cout<<"Poped element is "< 3 | using namespace std; 4 | class node{ 5 | public: 6 | int c; 7 | int e; 8 | node *link; 9 | }*P=NULL; 10 | 11 | void create(){ 12 | node *last,*t; 13 | int n; 14 | cout<<"Enter the NUmber of Terms : "; 15 | cin>>n; 16 | cout<<"Enter all the Terms in coeffient and exponent form : "<> t->c >> t->e; 20 | t->link = NULL; 21 | if(P==NULL) 22 | last = P = t; 23 | else{ 24 | last->link = t; 25 | last = t; 26 | } 27 | } 28 | 29 | } 30 | 31 | double evalute(int x){ 32 | node *t = P; 33 | double sum = 0.0; 34 | while(t){ 35 | sum += t->c*pow(x,t->e); 36 | t = t->link; 37 | } 38 | return sum; 39 | } 40 | 41 | int main(){ 42 | int n; 43 | create(); 44 | cout<<"Enter the Value of x : "; 45 | cin>>n; 46 | double r = evalute(n); 47 | cout<<"The value of the polynomial expression when x = "< 2 | #include 3 | using namespace std; 4 | string x; 5 | int y; 6 | int main() 7 | { 8 | system("color e"); 9 | cout<< ("\nsamz>\t"); 10 | system("netsh wlan show profile"); 11 | cout << ("WHICH ONE?--"); 12 | string z = "netsh wlan show profile\t \""; 13 | string n = "\"\tkey=clear"; 14 | cin >> x; 15 | z = z + x + n; 16 | system(z.c_str()); 17 | } 18 | -------------------------------------------------------------------------------- /C++/program 29/PROGRAM.CPP: -------------------------------------------------------------------------------- 1 | // Program to demonstrate BINARY SEARCH 2 | #include 3 | #define SIZE 8 4 | using namespace std; 5 | int binarySearch(int list[], int size, int item) 6 | { 7 | int low = 0, mid = 0; 8 | int high = size - 1; 9 | for (low = 0; low <= high; ) 10 | { 11 | mid = (low + high)/2; 12 | if (item > list[mid]) 13 | { 14 | low = mid + 1; //Search in Right half 15 | } 16 | else if (item < list[mid]) 17 | { 18 | high = mid - 1; ////Search in left half 19 | } 20 | else 21 | return mid; 22 | } 23 | return -1; 24 | } 25 | int main() 26 | { 27 | int item; 28 | int flag = -1; //We assume that if function returns an invalid index (say -1) means item NOT found... 29 | int list[] = {1,2,3,4,5,6,11,18}; 30 | cout<<"Enter item to be searched : "; 31 | cin>>item; 32 | flag = binarySearch(list,SIZE,item); 33 | if (flag == -1) 34 | { 35 | cout< 5 | #include 6 | 7 | using namespace std; 8 | 9 | string reverse_string(string str) { 10 | string temp_str = str; 11 | int index_pos = 0; 12 | 13 | for (int x = temp_str.length() - 1; x >= 0; x--) 14 | { 15 | 16 | str[index_pos] = temp_str[x]; 17 | //cout << str[index_pos]; 18 | index_pos++; 19 | } 20 | return str; 21 | } 22 | 23 | int main() 24 | { 25 | //taking string input 26 | string str; 27 | char str1[100]; 28 | cout << "String: "; 29 | cin.getline(str1, 25); 30 | 31 | int j = 0, begin, end, temp; 32 | 33 | //reverse whole string 34 | str = reverse_string(str1); 35 | //reverse each word seperately 36 | for (int i = 0; i < str.length(); i++) { 37 | if (str[i] == ' ' || str[i] == '\0') { 38 | for (begin = j, end = i - 1; begin < (i + j) / 2; begin++, end--) { 39 | temp = str[begin]; 40 | str[begin] = str[end]; 41 | str[end] = temp; 42 | } 43 | j = i + 1; 44 | } 45 | } 46 | //printing the words 47 | cout << str; 48 | } 49 | -------------------------------------------------------------------------------- /C++/program-10/Readme.txt: -------------------------------------------------------------------------------- 1 | Program to Reverse the words in the string: 2 | Example: 3 | input 4 | String: I love hactoberfest 5 | 6 | Output 7 | hactoberfest love I 8 | 9 | -------------------------------------------------------------------------------- /C++/program-19/Read me.md: -------------------------------------------------------------------------------- 1 | # To check whether a number is in palindrome or not -------------------------------------------------------------------------------- /C++/program-19/palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int num, temp, digit, rev = 0; 6 | 7 | cout << "Enter a positive number: "; 8 | cin >> num; 9 | temp = num; 10 | while (num != 0){ 11 | digit = num % 10; 12 | rev = (rev * 10) + digit; 13 | num = num / 10; 14 | } 15 | cout << "The reverse of the number is: " << rev << endl; 16 | if (temp == rev){ 17 | cout<<"The number is a palindrome."; 18 | } 19 | else{ 20 | cout << "The number is not a palindrome."; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /C++/program-26/Cycle_Detection_in Directed_Graph.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long 4 | #define mod 1000000007 5 | #define mod9 998244353 6 | #define raftaar \ 7 | ios_base::sync_with_stdio(false); \ 8 | cin.tie(NULL); \ 9 | cout.tie(NULL) 10 | #define endl "\n" 11 | bool dfs(int node, vector adj[], vector &vis, vector &check) 12 | { 13 | vis[node] = 1; 14 | check[node] = 1; 15 | for (auto x : adj[node]) 16 | { 17 | if (!vis[x]) 18 | { 19 | if (dfs(x, adj, vis, check)) 20 | { 21 | return true; 22 | } 23 | } 24 | if (check[x]) 25 | { 26 | return true; 27 | } 28 | } 29 | check[node] = 0; 30 | return false; 31 | } 32 | bool isCyclic(int V, vector adj[]) 33 | { 34 | vector vis(V, 0); 35 | vector check(V, 0); 36 | 37 | for (int i = 0; i < V; i++) 38 | { 39 | if (!vis[i]) 40 | { 41 | if (dfs(i, adj, vis, check)) 42 | { 43 | return true; 44 | } 45 | } 46 | } 47 | 48 | return false; 49 | } 50 | int main() 51 | { 52 | raftaar; 53 | int node, edges; 54 | cin >> node >> edges; 55 | vector adj[node]; 56 | for (int i = 0; i < edges; i++) 57 | { 58 | int u, v; 59 | cin >> u >> v; 60 | adj[u].push_back(v); 61 | } 62 | bool ans = isCyclic(node, adj); 63 | if (ans) 64 | { 65 | cout << "The Graph contain cycle" << endl; 66 | } 67 | else 68 | { 69 | cout << "The Graph does not contain cycle" << endl; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /C++/program_30/operator_overloading.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | cpp program for operator overloading 4 | Author: Anil Kumar 5 | Date modified:21-10-2021 6 | */ 7 | 8 | 9 | #include 10 | using namespace std; 11 | 12 | class complex 13 | { 14 | private: 15 | float a,b; 16 | public: 17 | 18 | void set(float x, float y){ 19 | a=x; 20 | b=y; 21 | } 22 | complex operator+(complex c){ 23 | complex t; 24 | t.a=a+c.a; 25 | t.b=b+c.b; 26 | return t; 27 | } 28 | complex operator-(){ 29 | complex t; 30 | t.a=-a; 31 | t.b=-b; 32 | return t; 33 | } 34 | 35 | void display(){ 36 | cout< 3 | #includeR 4 | int main() 5 | { 6 | /*initialization */ 7 | clrscr(); 8 | int n,i,j; 9 | printf("Enter the number of rows"); /*Input the number of rows */ 10 | scanf("%d",&i); 11 | print("Enter the number of columns"); 12 | scanf("%d",&j); 13 | for(i=1;i<=n;i++) /*condition */ 14 | { 15 | for(j=1;j<=i;j++) 16 | { 17 | printf("%d",n); /*output */ 18 | } 19 | printf("\n"); 20 | }return 0; 21 | } -------------------------------------------------------------------------------- /C/program-10/README.md: -------------------------------------------------------------------------------- 1 | Program to find square and half of given number without using built-in function and arithmetic operator 2 | -------------------------------------------------------------------------------- /C/program-10/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a,b,c; 6 | printf("enter the a"); 7 | scanf("%d",&a); 8 | b=a<<1; 9 | c=a>>1; 10 | printf("%d\n%d",b,c); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /C/program-11/README.md: -------------------------------------------------------------------------------- 1 | Program on arithmetic operators 2 | -------------------------------------------------------------------------------- /C/program-11/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { int a,b; 6 | printf("enter 2 no\n"); 7 | scanf("%d%d",&a,&b); 8 | printf("*** A.O ***\n"); 9 | printf("%d + %d = %d\n",a,b,a+b); 10 | printf("%d - %d = %d\n",a,b,a-b); 11 | printf("%d * %d = %d\n",a,b,a*b); 12 | printf("%d / %d = %.2f\n",a,b,(float)a/b); 13 | printf("%d %% %d = %d\n",a,b,a%b); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /C/program-12/README.md: -------------------------------------------------------------------------------- 1 | Program on relational operators 2 | -------------------------------------------------------------------------------- /C/program-12/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { int a,b; 6 | printf("enter 2 no\n"); 7 | scanf("%d%d",&a,&b); 8 | printf("*** relational operator ***\n"); 9 | printf("%d > %d = %d\n",a,b,a>b); 10 | printf("%d < %d = %d\n",a,b,a= %d = %d\n",a,b,a>=b); 12 | printf("%d <= %d = %d\n",a,b,a<=b); 13 | printf("%d != %d = %d\n",a,b,a!=b); 14 | printf("%d == %d = %d\n",a,b,a==b); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /C/program-13/README.md: -------------------------------------------------------------------------------- 1 | Program on bit-wise operator. 2 | -------------------------------------------------------------------------------- /C/program-13/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { int a,b; 5 | printf("enter 2 no\n"); 6 | scanf("%d%d",&a,&b); 7 | printf("*** bitwise operator ***\n"); 8 | printf("%d >> %d = %d\n",a,b,a>>b); 9 | printf("%d << %d = %d\n",a,b,a< 2 | 3 | int main() 4 | { int a,b,c,d; 5 | printf("enter 1 no\n"); 6 | scanf("%d",&a); 7 | b=c=d=a; 8 | printf("*** increment and decrement operator ***\n"); 9 | printf("%d \n",++a); 10 | printf("%d \n",--b); 11 | 12 | printf("%d\n",c++); 13 | printf("%d\n",d--); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /C/program-15/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a,b,r=0,i; 5 | printf("enter the range\n"); 6 | scanf("%d%d",&a,&b); 7 | for(i=a;i<=b;i++) 8 | { 9 | if(i%3==0) r=r+i; 10 | } 11 | printf("sum=%d\n",r); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C/program-15/readme.md: -------------------------------------------------------------------------------- 1 | # Program-15 2 | ## This is a c program to find sum of number which are divisible by 3 -------------------------------------------------------------------------------- /C/program-16/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n,s,sum=0,r; 5 | printf("enter the number\n"); 6 | scanf("%d",&n); 7 | s=n*n; 8 | while(s!=0) 9 | { 10 | r=s%10; 11 | sum+=r; 12 | s/=10; 13 | } 14 | if(n==sum) printf("Neon number\n"); 15 | else printf("not neon number"); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C/program-16/readme.md: -------------------------------------------------------------------------------- 1 | # Program-16 2 | ## This is a c program to check given number is neon number -------------------------------------------------------------------------------- /C/program-17/README.md: -------------------------------------------------------------------------------- 1 | Program to check whether the given number is prefect or not 2 | -------------------------------------------------------------------------------- /C/program-17/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n,s,i; 5 | printf("enter the number\n"); 6 | scanf("%d",&n); 7 | for(i=1;i<(n/2)+1;i++) 8 | { 9 | if(n%i==0) s+=i; 10 | } 11 | if(n==s) printf("perfect number\n"); 12 | else printf("non-perfect number\n"); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C/program-18/README.md: -------------------------------------------------------------------------------- 1 | Program to check given number is Armstrong or not 2 | -------------------------------------------------------------------------------- /C/program-18/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int c=0,a,temp; 5 | int n; 6 | printf("Enter the number"); 7 | scanf("%d",&n); 8 | temp=n; 9 | while(n>0) 10 | { 11 | a=n%10; 12 | n=n/10; 13 | c=c+(a*a*a); 14 | } 15 | if(temp==c) 16 | printf("armstrong number\n"); 17 | else 18 | printf("Not armstrong number\n"); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C/program-19/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,x,y,t; 5 | printf("enter x and y\n"); 6 | scanf("%d%d",&x,&y); 7 | t=x; 8 | for(i=1;i 2 | int isprime(int n) /*user defined function */ 3 | { 4 | if(n==0 || n==1) 5 | { 6 | return 0; 7 | 8 | } 9 | for(int i=2;i 2 | #include 3 | 4 | int main() 5 | { int a=7,b=2; 6 | // printf("enter two number !\n"); 7 | //scanf("%d%d",&a,&b); 8 | printf("%d",a/b); 9 | 10 | printf("%d\n",(float)a/b); 11 | printf("%d\n",(float)a/(float)b); 12 | printf("%d\n",a/(float)b); 13 | 14 | printf("%f\n",a/b); 15 | printf("%f\n",(float)(a/b)); 16 | printf("%f\n",(float) a/b); 17 | printf("%f\n",(float)a/(float)b); 18 | printf("%f\n",a/(float)b); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C/program-21/program.c: -------------------------------------------------------------------------------- 1 | /* 2 | You are given a sorted (either in the increasing or in the decreasing order) sequence of numbers, ending with a -1. You can assume that are at least two numbers before the ending -1. 3 | 4 | Let us call the sequence x0 x1 ... xn -1. 5 | 6 | You have to output the number of distinct elements in the sorted sequence. 7 | 8 | Kindly do not use arrays in the code. 9 | */ 10 | 11 | 12 | #include 13 | #include 14 | 15 | int main() 16 | { 17 | int count=0,n=0; 18 | while(n!=-1) 19 | { 20 | scanf("%d",&n); 21 | count++; 22 | 23 | } 24 | printf("%d",count-1); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /C/program-22/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a,r,l,b; 5 | printf("enter the two number\n"); 6 | scanf("%d%d",&a,&b); 7 | int x=a; 8 | int y=b; 9 | while(b!=0) 10 | { 11 | r=a%b; 12 | a=b; 13 | b=r; 14 | } 15 | l=(x*y)/a; 16 | printf("GCD=%d & LCM=%d\n",a,l); 17 | } 18 | -------------------------------------------------------------------------------- /C/program-23/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n,count=0; 5 | printf("Enter the number\n"); 6 | scanf("%d",&n); 7 | while(n!=0) 8 | { 9 | count++; 10 | n/=10; 11 | } 12 | printf("number of digits =%d\n",count); 13 | } -------------------------------------------------------------------------------- /C/program-24/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j,r,c; 5 | printf("Enter the number of rows and columns\n"); 6 | scanf("%d%d",&r,&c); 7 | for(i=0;i 2 | int main() 3 | { 4 | int i,j,r; 5 | printf("Enter the number of rows\n"); 6 | scanf("%d",&r); 7 | for(i=0;i 2 | int main() 3 | { 4 | /*initialization */ 5 | int n,i,j,count=0; 6 | printf("enter the number of rows\n"); /*Input the number of rows */ 7 | scanf("%d",&n); 8 | for(i=1;i<=n;i++) /*condition */ 9 | { 10 | for(j=1;j<=i;j++) 11 | { 12 | printf("\t%d",count++); /*output */ 13 | } 14 | printf("\n"); 15 | }return 0; 16 | } -------------------------------------------------------------------------------- /C/program-27/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j,r; 5 | printf("Enter the number of rows\n"); 6 | scanf("%d",&r); 7 | for(i=0;i0;i--) 16 | { 17 | for(j=i;j>0;j--) 18 | { 19 | printf("\t*"); 20 | } 21 | printf("\n"); 22 | } 23 | } -------------------------------------------------------------------------------- /C/program-28/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | /*initialization */ 5 | int n,i,j; 6 | printf("enter the number of rows\n"); /*Input the number of rows */ 7 | scanf("%d",&n); 8 | for(i=n;i>0;i--) /*condition */ 9 | { 10 | for(j=i;j>0;j--) 11 | { 12 | printf("\t*"); /*output */ 13 | } 14 | printf("\n"); 15 | }return 0; 16 | } -------------------------------------------------------------------------------- /C/program-29/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j,r; 5 | printf("Enter the number of rows\n"); 6 | scanf("%d",&r); 7 | for(i=0;i0;i--) 16 | {int x=0; 17 | for(j=i;j>0;j--) 18 | { 19 | 20 | printf("\t%d",x++); 21 | } 22 | printf("\n"); 23 | } 24 | } -------------------------------------------------------------------------------- /C/program-3/README.md: -------------------------------------------------------------------------------- 1 | Program to find greater of 3 numbers using if 2 | -------------------------------------------------------------------------------- /C/program-3/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a,b,c; 5 | printf("enter a,b,c"); 6 | scanf("%d%d%d",&a,&b,&c); 7 | if(a>b && a>c) printf("a is larger"); 8 | if(b>a && b>c) printf("b is larger"); 9 | if(c>a && c >b ) printf("c is larger"); 10 | } 11 | -------------------------------------------------------------------------------- /C/program-30/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i, space, rows, k=0; 5 | printf("Enter number of rows: "); 6 | scanf("%d",&rows); 7 | for(i=1; i<=rows; ++i, k=0) 8 | { 9 | for(space=1; space<=rows-i; ++space) 10 | { 11 | printf(" "); 12 | } 13 | while(k != 2*i-1) 14 | { 15 | printf("* "); 16 | ++k; 17 | } 18 | printf("\n"); 19 | } 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C/program-31/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct student 3 | { 4 | char n[100]; 5 | char u[100]; 6 | int m; 7 | }stud[10],stud2; 8 | int main() 9 | { 10 | int n,i,p=0; 11 | printf("Enter the number of student\n"); 12 | scanf("%d",&n); 13 | for(i=1;i<=n;i++) 14 | { 15 | printf("Enter the details of student - %d\n",i); 16 | printf("Enter the name of the student\n"); 17 | scanf("%s",stud[i].n); 18 | printf("Enter USN\n"); 19 | scanf("%s",stud[i].u); 20 | printf("Enter total marks\n"); 21 | scanf("%d",&stud[i].m); 22 | } 23 | printf("|\tSl.no\t|\tName\t\t|\tUSN\t\t|\tMark\t|\n"); 24 | for(i=1;i<=n;i++) 25 | { 26 | printf("|\t%d\t|\t%-10s\t|\t%s\t|\t%d\t|\n",i,stud[i].n,stud[i].u,stud[i].m); 27 | } 28 | printf("Enter the details of new student\n"); 29 | printf("Enter the name\n"); //preferred to enter equal length of name 30 | scanf("%s",stud2.n); 31 | printf("Enter the USN\n"); 32 | scanf("%s",stud2.u); 33 | printf("Enter the marks\n"); 34 | scanf("%d",&stud2.m); 35 | printf("enter position\n"); 36 | scanf("%d",&p); 37 | 38 | for(i=n+1;i>=p;i--) 39 | { 40 | stud[i+1]=stud[i]; 41 | } 42 | stud[p]=stud2; 43 | printf("|\tSl.no\t|\tName\t\t|\tUSN\t\t |\tMark\t|\n"); 44 | for(i=1;i<=n+1;i++) 45 | { 46 | printf("|\t%d\t|\t%-10s\t|\t%s\t|\t%d\t|\n",i,stud[i].n,stud[i].u,stud[i].m); 47 | 48 | } 49 | 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /C/program-32/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct student 3 | { 4 | char n[100]; 5 | char u[100]; 6 | int m; 7 | }stud[10],stud2; 8 | int main() 9 | { 10 | int n,i=0; 11 | printf("Enter the number of student\n"); 12 | scanf("%d",&n); 13 | for(i=1;i<=n;i++) 14 | { 15 | printf("Enter the details of student - %d\n",i); 16 | printf("Enter the name of the student\n"); 17 | scanf("%s",stud[i].n); 18 | printf("Enter USN\n"); 19 | scanf("%s",stud[i].u); 20 | printf("Enter total marks\n"); 21 | scanf("%d",&stud[i].m); 22 | } 23 | printf("|\tSl.no\t|\tName\t\t|\tUSN\t\t|\tMark\t|\n"); 24 | for(i=1;i<=n;i++) 25 | { 26 | printf("|\t%d\t|\t%-10s\t|\t%s\t|\t%d\t|\n",i,stud[i].n,stud[i].u,stud[i].m); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /C/program-33/program.c: -------------------------------------------------------------------------------- 1 | /* Arithematic operation using pointers */ 2 | #include 3 | #include 4 | int main() 5 | { 6 | int a,b; 7 | int *x,*y; 8 | scanf("%d%d",&a,&b); 9 | x=&a; 10 | y=&b; 11 | //s=; 12 | printf("%d\t%d",*x+*y,abs(*x-*y)); 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /C/program-34/program.c: -------------------------------------------------------------------------------- 1 | /* To determine whether the matrix is a triangular matrix. 2 | First, you will be given N, which is the size of the matrix. 3 | 4 | Then you will be given N rows of integers, where each row consists of 5 | N integers separated by spaces. 6 | If the input matrix is triangular, then print yes. Otherwise, print 7 | no. */ 8 | 9 | 10 | 11 | 12 | 13 | #include 14 | #include 15 | 16 | int main() 17 | { 18 | int a[10][10],n,i,j,flag=0; 19 | scanf("%d",&n); 20 | for(i=0;ij || j>i) ) flag=1; 31 | } 32 | } 33 | if(!(flag))printf("no\n"); 34 | else printf("yes"); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /C/program-35/program.c: -------------------------------------------------------------------------------- 1 | /* You are given a sequence of non-negative integers terminated by -1. 2 | You have to output 1 if there are atleast 2 distinct elements in the sequence and 0 if the sequence consists of only 1 integer. 3 | Note that -1 is not part of the sequence. The sequence is not necessarily sorted. */ 4 | 5 | 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | int a=0,n=0,count=0; 12 | while(n!=-1) 13 | { 14 | scanf("%d",&n); 15 | if(a!=n) 16 | { 17 | a=n; 18 | count++; 19 | } 20 | 21 | } 22 | if(count>=2) printf("%d",1); 23 | else printf("%d",0); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /C/program-36/program.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | You are given a sorted (either in the increasing or in the decreasing order) sequence of numbers, ending with a -1. You can assume that are at least two numbers before the ending -1. 4 | 5 | Let us call the sequence x0 x1 ... xn -1. 6 | 7 | You have to output the number of distinct elements in the sorted sequence. 8 | 9 | Kindly do not use arrays in the code. 10 | 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | int main() 17 | { 18 | int count=0,n=0,m; 19 | while(n!=-1) 20 | { 21 | scanf("%d",&n); 22 | if(m!=n) count++; 23 | else continue; 24 | m=n; 25 | 26 | } 27 | printf("%d",count-1); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /C/program-37/program.c: -------------------------------------------------------------------------------- 1 | /* 2 | Program to find the fibonacci sequnce using recursion 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | int fib(int n) 9 | { 10 | int f; 11 | 12 | if(n==0 || n==1) 13 | { 14 | return 1; 15 | } 16 | else 17 | { 18 | f=fib(n-2)+fib(n-1); 19 | } 20 | return f; 21 | } 22 | 23 | int main() 24 | { 25 | int n; 26 | printf("Enter the number of terms\n"); 27 | scanf("%d",&n); 28 | printf("Fibonacci series=%d \n",fib(n)); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /C/program-38/program.c: -------------------------------------------------------------------------------- 1 | /* 2 | Program to find the factorial of a number using recursion 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | int fact(int n) 9 | { 10 | int f; 11 | 12 | if( n==1) 13 | { 14 | return 1; 15 | } 16 | else 17 | { 18 | f=n*fact(n-1); 19 | } 20 | return f; 21 | } 22 | 23 | int main() 24 | { 25 | int n; 26 | printf("Enter the number \n"); 27 | scanf("%d",&n); 28 | printf("Factorial of a number =% d \n",fact(n)); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /C/program-39/program.c: -------------------------------------------------------------------------------- 1 | /* 2 | Program to find the GCD of a number using recursion 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | int gcd(int a,int b) 9 | { 10 | 11 | if( b!=0) 12 | { 13 | 14 | return gcd(b,a%b);; 15 | } 16 | else 17 | { 18 | return a; 19 | } 20 | 21 | 22 | } 23 | 24 | int main() 25 | { 26 | int a,b; 27 | printf("Enter the two numbers\n"); 28 | scanf("%d%d",&a,&b); 29 | printf("GCD of %d & %d is = %d \n",a,b,gcd(a,b)); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /C/program-4/README.md: -------------------------------------------------------------------------------- 1 | Program to fin 2 | -------------------------------------------------------------------------------- /C/program-4/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a,b,c; 5 | printf("enter a,b,c"); 6 | scanf("%d%d%d",&a,&b,&c); 7 | if(a>b && a>c) printf("a is larger"); 8 | else if(b>a && b>c) printf("b is larger"); 9 | else printf("c is larger"); 10 | } 11 | -------------------------------------------------------------------------------- /C/program-40/program.c: -------------------------------------------------------------------------------- 1 | /*Write a C program to find the Ackermann of 2 Numbers*/ 2 | 3 | #include 4 | int ack(int m,int n) 5 | { 6 | if(m==0) 7 | return n+1; 8 | else if(m!=0 && n==0) 9 | return ack(m-1,1); 10 | else if (m!=0 && n!=0) 11 | return ack(m-1,ack(m,n-1)); 12 | return 0; 13 | } 14 | 15 | int main() 16 | { 17 | int a,b,c; 18 | printf("Enter 2 Elements:\n"); 19 | scanf("%d%d",&a,&b); 20 | c=ack(a,b); 21 | printf("Ackermann(%d,%d)=%d",a,b,c); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /C/program-41/program.c: -------------------------------------------------------------------------------- 1 | /*To find sum of two numbers without using any operator*/ 2 | #include 3 | 4 | int add(int x, int y) 5 | { 6 | return printf("%*c%*c", x, ' ', y, ' '); 7 | } 8 | 9 | // Driver code 10 | int main() 11 | { 12 | printf("Sum = %d", add(3, 4)); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /C/program-42/program.c: -------------------------------------------------------------------------------- 1 | /*C Program to print Floyd’s triangle*/ 2 | // Without using a temporary variable and with only one loop 3 | #include 4 | void floyd(int n){ 5 | int i,j=1; 6 | for (i=1;i<=(n*(n+1))/2;i++){ 7 | printf("%d ",i); 8 | if(i==(j*(j+1))/2){ 9 | printf("\n"); 10 | j++; 11 | } 12 | } 13 | } 14 | 15 | int main(){ 16 | floyd(6); 17 | } 18 | -------------------------------------------------------------------------------- /C/program-43/program.c: -------------------------------------------------------------------------------- 1 | 2 | // C program for printing the hollow triangle pattern 3 | 4 | #include 5 | 6 | // Function for printing pattern 7 | void pattern(int N) 8 | { 9 | int i, j, k = 0, space = 1, rows = N; 10 | 11 | // For printing stars 12 | for (i = rows; i >= 1; i--) { 13 | for (j = 1; j <= i; j++) { 14 | printf("*"); 15 | } 16 | if (i != rows) { 17 | // for printing space 18 | for (k = 1; k <= space; k++) { 19 | printf(" "); 20 | } 21 | 22 | // increment by 2 23 | space = space + 2; 24 | } 25 | for (j = i; j >= 1; j--) { 26 | if (j != rows) 27 | printf("*"); 28 | } 29 | printf("\n"); 30 | } 31 | printf("\n"); 32 | } 33 | 34 | // Driver code 35 | int main() 36 | { 37 | 38 | // Get N 39 | int N = 6; 40 | 41 | // Print the pattern 42 | pattern(N); 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /C/program-44/program.c: -------------------------------------------------------------------------------- 1 | // C implementation of the approach 2 | #include 3 | 4 | // Function to print the desired 5 | // Alphabet Z Pattern 6 | void alphabet_Z_Pattern(int N) 7 | { 8 | int index, side_index; 9 | 10 | // Declaring the values of Right, 11 | // Left and Diagonal values 12 | int Top = 1, Bottom = 1, Diagonal = N - 1; 13 | 14 | // Loop for printing the first row 15 | for (index = 0; index < N; index++) 16 | printf("%d ", Top++); 17 | 18 | printf("\n"); 19 | 20 | // Main Loop for the rows from (2 to n-1) 21 | for (index = 1; index < N - 1; index++) { 22 | 23 | // Spaces for the diagonals 24 | for (side_index = 0; side_index < 2 * (N - index - 1); 25 | side_index++) 26 | printf(" "); 27 | 28 | // Printing the diagonal values 29 | printf("%d", Diagonal--); 30 | 31 | printf("\n"); 32 | } 33 | 34 | // Loop for printing the last row 35 | for (index = 0; index < N; index++) 36 | printf("%d ", Bottom++); 37 | } 38 | 39 | // Driver Code 40 | int main() 41 | { 42 | // Size of the Pattern 43 | int N = 5; 44 | 45 | alphabet_Z_Pattern(N); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /C/program-45/program.c: -------------------------------------------------------------------------------- 1 | 2 | // C program to illustrate the above given pattern of numbers. 3 | #include 4 | 5 | int main() 6 | { 7 | int n = 5, i, j, num = 1, gap; 8 | 9 | gap = n - 1; 10 | 11 | for ( j = 1 ; j <= n ; j++ ) 12 | { 13 | num = j; 14 | 15 | for ( i = 1 ; i <= gap ; i++ ) 16 | printf(" "); 17 | 18 | gap --; 19 | 20 | for ( i = 1 ; i <= j ; i++ ) 21 | { 22 | printf("%d", num); 23 | num++; 24 | } 25 | num--; 26 | num--; 27 | for ( i = 1 ; i < j ; i++) 28 | { 29 | printf("%d", num); 30 | num--; 31 | } 32 | printf("\n"); 33 | 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /C/program-46/program.c: -------------------------------------------------------------------------------- 1 | /* Program to convert binary number to decimal */ 2 | #include 3 | #include 4 | int convertBinaryToDecimal(long long n); 5 | int main() 6 | { 7 | long long n; 8 | printf("Enter a binary number: "); 9 | scanf("%lld", &n); 10 | printf("%lld in binary = %d in decimal", n, convertBinaryToDecimal(n)); 11 | return 0; 12 | } 13 | int convertBinaryToDecimal(long long n) 14 | { 15 | int decimalNumber = 0, i = 0, remainder; 16 | while (n!=0) 17 | { 18 | remainder = n%10; 19 | n /= 10; 20 | decimalNumber += remainder*pow(2,i); 21 | ++i; 22 | } 23 | return decimalNumber; 24 | } 25 | -------------------------------------------------------------------------------- /C/program-47/Readme.md: -------------------------------------------------------------------------------- 1 | Program 47 2 | 3 | Write a program to find the maximum and minimum element in an array. 4 | 5 | Variable description-- 6 | 7 | n=Number of elements in an array 8 | 9 | a=Array of size N 10 | 11 | min= Holds the minimum element 12 | 13 | max=Holds the maximum element 14 | -------------------------------------------------------------------------------- /C/program-47/program 47.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | /* Length of the password */ 8 | int length; 9 | int num; 10 | int temp; 11 | printf("Enter the length of the password: "); 12 | scanf("%d", &length); 13 | printf("\nEnter the number of passwords you want: "); 14 | scanf("%d", &num); 15 | /* Seed number for rand() */ 16 | srand((unsigned int) time(0) + getpid()); 17 | 18 | while(num--) 19 | { 20 | temp = length; 21 | printf("\n"); 22 | while(temp--) { 23 | putchar(rand() % 56 + 65); 24 | srand(rand()); 25 | } 26 | 27 | temp = length; 28 | } 29 | 30 | printf("\n"); 31 | 32 | return EXIT_SUCCESS; 33 | } 34 | -------------------------------------------------------------------------------- /C/program-47/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | 5 | int a[100],n,min,max; 6 | printf("enter the size of the array"); 7 | scanf("%d",&n); 8 | printf("enter the elements of the array"); 9 | for(int i=0;imax) 17 | max=a[i]; 18 | if(a[i] 2 | 3 | int main() { 4 | int num; 5 | printf("Enter a number \n"); 6 | scanf("%d",&num); 7 | if(num%2==0) 8 | printf("%d is an even number",num); 9 | else 10 | printf("%d is an odd number",num); 11 | } -------------------------------------------------------------------------------- /C/program-49/README.md: -------------------------------------------------------------------------------- 1 | Program 49 2 | 3 | Write a program to find the sum of the digits of the given number. 4 | 5 | Variable description-- 6 | num=Number 7 | sum= Holds the sum 8 | dig=Holds the single digit of the number 9 | -------------------------------------------------------------------------------- /C/program-49/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int n; 6 | printf("Enter the number"); 7 | int num; 8 | scanf("%d",&num);//Enter the number 9 | int sum=0,dig=0; 10 | while(num>0) 11 | { 12 | dig=num%10; 13 | sum+=dig; 14 | num/=10; 15 | } 16 | printf("The sum of digits of a number is: %d",sum); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /C/program-5/README.md: -------------------------------------------------------------------------------- 1 | Program to find largest of three number using nested if condition 2 | -------------------------------------------------------------------------------- /C/program-5/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a,b,c; 5 | printf("enter a,b,c"); 6 | scanf("%d%d%d",&a,&b,&c); 7 | if(a>b) 8 | { 9 | if(a>c) printf("a is larger"); 10 | else printf("c is larger"); 11 | } 12 | else 13 | { 14 | if(b>c) printf("b is larger"); 15 | else printf("c is larger"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /C/program-50/Readme.md: -------------------------------------------------------------------------------- 1 | Program 50 2 | 3 | Write a program to check whether a given number is a palindrome or not. 4 | 5 | Variable description-- 6 | 7 | n=Holds the element which is to be checked 8 | 9 | temp=Holds the copy of the element 10 | 11 | rev= Holds the reverse of the number 12 | 13 | rem=Holds the digits of the number 14 | -------------------------------------------------------------------------------- /C/program-50/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int rem,rev=0,temp,n; 5 | printf("Enter the number"); 6 | scanf("%d",&n); 7 | temp=n; 8 | while(n>0) 9 | { 10 | rem=n%10; 11 | n=n/10; 12 | rev=rem+(rev*10); 13 | } 14 | if(temp==rev) 15 | printf("number is palindrome"); 16 | else 17 | printf("number is not palindrome"); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C/program-51/README.md: -------------------------------------------------------------------------------- 1 | Program 51 2 | 3 | Write an program to print duplicates in an array. -------------------------------------------------------------------------------- /C/program-51/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int arr[100],freq[100]; 5 | int n,i; 6 | printf("Enter the number of elements in array \n"); 7 | scanf("%d",&n); 8 | printf("Enter elements in the array \n"); 9 | for(i=0;i1) 17 | printf("%d ",i); 18 | } 19 | printf("\n"); 20 | } -------------------------------------------------------------------------------- /C/program-52/README.md: -------------------------------------------------------------------------------- 1 | Program 52 2 | 3 | Write a program to find whether the given element is present in the array or not. 4 | 5 | -------------------------------------------------------------------------------- /C/program-52/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n;//number of elements of array; 5 | printf("Enter the number of elements"); 6 | scanf("%d",&n); 7 | int arr[n]; 8 | printf("\nEnter the elements"); 9 | for(int i=0;i 2 | int main() 3 | { 4 | int a[100],n,el,i; 5 | printf("Enter the size of the array"); 6 | scanf("%d",&n); 7 | printf("Enter the elements of the array"); 8 | for(int i=0;i 2 | int main() 3 | { 4 | char a[100],b[100]; 5 | int f[26]={0}; 6 | int s[26]={0}; 7 | int k; 8 | int len1,len2; 9 | printf("Enter the two strings\n"); 10 | fgets(a,100,stdin); 11 | fgets(b,100,stdin); 12 | for(int i=0;a[i]!='\0';++i) 13 | f[a[i]-'a']+=1; 14 | for(int i=0;b[i]!='\0';++i) 15 | s[b[i]-'a']+=1; 16 | len1 = sizeof(a)/sizeof(a[0]); 17 | len2 = sizeof(b)/sizeof(b[0]); 18 | if(len1 == len2) 19 | { 20 | for(k=0;k<26;++k) 21 | if(f[k]!=s[k]) 22 | break; 23 | if(k==26) 24 | printf("The strings are anagrams.\n"); 25 | else 26 | printf("The strings aren't anagrams."); 27 | } 28 | else 29 | printf("The strings aren't anagrams."); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /C/program-55/program.c: -------------------------------------------------------------------------------- 1 | /* Program that prints a number in binary*/ 2 | 3 | // start writng code from here 4 | #include 5 | 6 | int main (void) 7 | { 8 | int b; 9 | unsigned int mask = 1<<31; 10 | 11 | printf("Input a 32bits integer number: "); 12 | scanf("%d", &b); 13 | 14 | while (mask != 0){ 15 | printf("%d", b&mask?1:0); 16 | mask >>= 1; 17 | } 18 | 19 | printf("\n"); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C/program-55/readme.md: -------------------------------------------------------------------------------- 1 | # program-55 2 | ## Program that prints a number in binary 3 | 4 | This program uses bitwise operators to print a 32bits integer in binary representation 5 | -------------------------------------------------------------------------------- /C/program-56/README.md: -------------------------------------------------------------------------------- 1 | Program 56 2 | 3 | 4 | Write a program in C to calculate the number of vowels and consonants in a string. 5 | -------------------------------------------------------------------------------- /C/program-56/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char ch[100]; 5 | int i,count; 6 | printf("Enter the string \n"); 7 | fgets(ch,100,stdin); 8 | for(i=0;ch[i]!='\0';i++) 9 | { 10 | if(ch[i]=='a'||ch[i]=='e'||ch[i]=='i'||ch[i]=='o'||ch[i]=='u'||ch[i]=='A'||ch[i]=='E'||ch[i]=='I'||ch[i]=='O'||ch[i]=='U') 11 | count++; 12 | } 13 | printf("Number of vowels are %d \n",count); 14 | printf("Number of consonants are %d",(i-count)); 15 | } 16 | -------------------------------------------------------------------------------- /C/program-57/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () { 4 | float score; 5 | printf("Enter your total score (0-100): "); 6 | scanf("%f",&score); 7 | if(score < 0 || score > 100) { 8 | printf("Enter score 0 - 100 \n"); 9 | } else if(score >= 80) { 10 | printf("Score = %.2f , You Grade : A\n",score); 11 | } else if(score >= 75) { 12 | printf("Score = %.2f , You Grade : B+\n",score); 13 | } else if(score >= 70) { 14 | printf("Score = %.2f , You Grade : B\n",score); 15 | } else if(score >= 65) { 16 | printf("Score = %.2f , You Grade : C+\n",score); 17 | } else if(score >= 60) { 18 | printf("Score = %.2f , You Grade : C\n",score); 19 | } else if(score >= 55) { 20 | printf("Score = %.2f , You Grade : D+\n",score); 21 | } else if(score >= 50) { 22 | printf("Score = %.2f , You Grade : D\n",score); 23 | } else { 24 | printf("Score = %.2f , You Grade : F\n",score); 25 | } 26 | } -------------------------------------------------------------------------------- /C/program-57/readme.md: -------------------------------------------------------------------------------- 1 | Program 57 2 | 3 | 4 | Write a program in C to calculate the grade 5 | -------------------------------------------------------------------------------- /C/program-58/Program.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | 4 | { 5 | //float n[10]; 6 | int i,sum,a,b,x; 7 | printf("enter the size of elements\n"); 8 | scanf("%d", &x); 9 | float n[x]; 10 | printf("enter the values\n"); 11 | for (i=0;i 2 | #include 3 | 4 | typedef struct student 5 | { 6 | 7 | char name[25]; 8 | char usn[15]; 9 | float cgpa; 10 | } S; 11 | S s[70]; 12 | 13 | 14 | void search(char name[],int n) 15 | { 16 | 17 | int i,j; 18 | // printf("%s\n",name); 19 | for(i=0;i 2 | int main() 3 | { 4 | int a,b,c; 5 | printf("enter a,b,c"); 6 | scanf("%d%d%d",&a,&b,&c); 7 | (a>b)?(a>c)?printf("a is larger"):printf("c is larger"):(b>c)?printf("b is larger"):printf("c is larger"); 8 | } 9 | -------------------------------------------------------------------------------- /C/program-60/readme.md: -------------------------------------------------------------------------------- 1 | Program 59 2 | 3 | 4 | Write a program to print kaprekar number in a given range 5 | -------------------------------------------------------------------------------- /C/program-61/program.c: -------------------------------------------------------------------------------- 1 | //C Program For Bubble Sort In Ascending And Descending Order// 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | 8 | int array[100], n, c, d, swap; 9 | 10 | printf("Enter number of elements\n"); 11 | scanf("%d", &n); 12 | 13 | printf("Enter %d integers\n", n); 14 | 15 | for (c = 0; c < n; c++) 16 | scanf("%d", &array[c]); 17 | 18 | for (c = 0 ; c < ( n - 1 ); c++) 19 | { 20 | for (d = 0 ; d < n - c - 1; d++) 21 | { 22 | if (array[d] > array[d+1]) 23 | { 24 | swap = array[d]; 25 | array[d] = array[d+1]; 26 | array[d+1] = swap; 27 | } 28 | } 29 | } 30 | 31 | printf("Sorted list in ascending order:\n"); 32 | 33 | for ( c = 0 ; c < n ; c++ ) 34 | printf("%d\n", array[c]); 35 | 36 | printf("\nSorted list in descending order:\n"); 37 | 38 | for ( c = n-1 ; c >= 0; c-- ) 39 | printf("%d\n", array[c]); 40 | return 0; 41 | 42 | -------------------------------------------------------------------------------- /C/program-62/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int n1,n2,n3,n4,n5; 5 | float t; 6 | 7 | printf("Enter Five Numbers:"); 8 | scanf("%d %d %d %d %d",&n1,&n2,&n3,&n4,&n5); 9 | 10 | t=(n1+n2+n3+n4+n5)/5; 11 | 12 | printf("The Average of %d,%d,%d,%d,%d is %f",n1,n2,n3,n4,n5,t); 13 | 14 | getch(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /C/program-63/README.md: -------------------------------------------------------------------------------- 1 | C program to print Pascal's Triangle 2 | -------------------------------------------------------------------------------- /C/program-63/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int rows, coef = 1, space, i, j; 4 | printf("Enter the number of rows: "); 5 | scanf("%d", &rows); 6 | for (i = 0; i < rows; i++) { 7 | for (space = 1; space <= rows - i; space++) 8 | printf(" "); 9 | for (j = 0; j <= i; j++) { 10 | if (j == 0 || i == 0) 11 | coef = 1; 12 | else 13 | coef = coef * (i - j + 1) / j; 14 | printf("%4d", coef); 15 | } 16 | printf("\n"); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C/program-64/ArmstrongNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int number, originalNumber, remainder, result = 0, n = 0; 6 | scanf("%d", &number); 7 | originalNumber = number; 8 | 9 | while (originalNumber != 0) 10 | { 11 | originalNumber /= 10; 12 | ++n; 13 | } 14 | originalNumber = number; 15 | while (originalNumber != 0) 16 | { 17 | remainder = originalNumber % 10; 18 | result += pow(remainder, n); 19 | originalNumber /= 10; 20 | } 21 | if (result == number) 22 | printf("yes"); 23 | else 24 | printf("no"); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C/program-64/README.md: -------------------------------------------------------------------------------- 1 | A positive integer of n digits is called an Armstrong number of order n (order is number of digits) 2 | 3 | if - 4 | abcd... = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + .... 5 | 6 | Example - 7 | Input : 153 8 | Output : Yes 9 | 153 is an Armstrong number. 10 | 1*1*1 + 5*5*5 + 3*3*3 = 153 -------------------------------------------------------------------------------- /C/program-65/README.md: -------------------------------------------------------------------------------- 1 | Program to Find Transpose of a Matrix 2 | -------------------------------------------------------------------------------- /C/program-65/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int a[10][10], transpose[10][10], r, c, i, j; 4 | printf("Enter rows and columns: "); 5 | scanf("%d %d", &r, &c); 6 | 7 | // Assigning elements to the matrix 8 | printf("\nEnter matrix elements:\n"); 9 | for (i = 0; i < r; ++i) 10 | for (j = 0; j < c; ++j) { 11 | printf("Enter element a%d%d: ", i + 1, j + 1); 12 | scanf("%d", &a[i][j]); 13 | } 14 | 15 | // Displaying the matrix a[][] 16 | printf("\nEntered matrix: \n"); 17 | for (i = 0; i < r; ++i) 18 | for (j = 0; j < c; ++j) { 19 | printf("%d ", a[i][j]); 20 | if (j == c - 1) 21 | printf("\n"); 22 | } 23 | 24 | // Finding the transpose of matrix a 25 | for (i = 0; i < r; ++i) 26 | for (j = 0; j < c; ++j) { 27 | transpose[j][i] = a[i][j]; 28 | } 29 | 30 | // Displaying the transpose of matrix a 31 | printf("\nTranspose of the matrix:\n"); 32 | for (i = 0; i < c; ++i) 33 | for (j = 0; j < r; ++j) { 34 | printf("%d ", transpose[i][j]); 35 | if (j == r - 1) 36 | printf("\n"); 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /C/program-66/README.md: -------------------------------------------------------------------------------- 1 | Program to find fibonacci series upto n values in C language. -------------------------------------------------------------------------------- /C/program-66/fibonacciSeries.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i, n, a = 0, b = 1, c; 6 | printf("enter the no. of values = "); 7 | scanf("%d", &n); 8 | // Initiating the values as 0,1,... 9 | printf("%d,%d,", a, b); 10 | for (i = 1; i <= (n - 2); i++) 11 | { 12 | c = a + b; // creating the new value 13 | printf("%d,", c); 14 | a = b, b = c; // Updating the values 15 | } 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C/program-67/program.c: -------------------------------------------------------------------------------- 1 | /* 2 | This Program calulates all the prime between the range of numbers 3 | includes the numbers which is provided. 4 | 5 | For e.g: 2 7 6 | Prime Numbers are : 2 3 5 7 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | char primecheck(int); 13 | 14 | int main() 15 | { 16 | int i,num1,num2,cases; 17 | char ans; 18 | printf("Enter Number of Test Cases: "); 19 | scanf("%d",&cases); 20 | while (cases--) 21 | { 22 | printf("Enter First Number: "); 23 | scanf("%d",&num1); 24 | printf("Enter Second Number: "); 25 | scanf("%d",&num2); 26 | 27 | printf("Answer: "); 28 | for(i=num1;i<=num2;i++) 29 | { 30 | ans = primecheck(i); 31 | if (ans == 'y') 32 | printf("%d ",i); 33 | } 34 | printf("\n"); 35 | } 36 | return 0; 37 | } 38 | 39 | char primecheck(int num) 40 | { 41 | int i; 42 | if (num == 0 || num == 1) 43 | return 'n'; 44 | else 45 | { 46 | for(i=(num-1);i>1;i--) 47 | { 48 | if(num%i == 0) 49 | { 50 | return 'n'; 51 | } 52 | else 53 | continue; 54 | } 55 | return 'y'; 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /C/program-68/program-68.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main () 5 | { 6 | char s[50]; 7 | int i, c = 0; 8 | int flag = 0; 9 | 10 | printf ("Input a string\n"); 11 | scanf ("%s", s); 12 | while (s[c] != '\0') 13 | c++; 14 | 15 | 16 | for (i = 0; i < c; i++) 17 | { 18 | if(s[i] !='0' && s[i]!='1') 19 | { 20 | printf("error\n"); 21 | exit(0); 22 | } 23 | 24 | if (s[i] == '0' && s[i + 1] == '0' && s[i + 2] == '0') 25 | { 26 | flag = 1; 27 | } 28 | } 29 | if (flag == 1) 30 | printf ("accepted\n"); 31 | else 32 | printf ("not accepted\n"); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /C/program-68/readme.md: -------------------------------------------------------------------------------- 1 | Program to accept 0s and 1s as input and print if it consists 3 consecutive 0s 2 | -------------------------------------------------------------------------------- /C/program-69/README.md: -------------------------------------------------------------------------------- 1 | Strong Numbers are the numbers whose sum of factorial of digits is equal to the original number. 2 | 3 | Example - 4 | Input : n = 145 5 | Output : Yes 6 | Sum of digit factorials = 1! + 4! + 5! 7 | = 1 + 24 + 120 8 | = 145 -------------------------------------------------------------------------------- /C/program-69/strongNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, f = 1, s = 0, r, i, n1; 6 | scanf("%d", &n); 7 | n = n1; 8 | while (n) 9 | { 10 | r = n % 10; // Taking the last digit of the number 11 | for (i = 1; i <= r; i++) 12 | { 13 | f = f * i; 14 | } 15 | s = s + f; 16 | n /= 10; 17 | } 18 | if (s == n1) 19 | printf("Strong no."); 20 | else 21 | printf("Not Strong no."); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C/program-7/README.md: -------------------------------------------------------------------------------- 1 | Program to find leap year 2 | -------------------------------------------------------------------------------- /C/program-7/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int y; 5 | printf("enter year"); 6 | scanf("%d",&y); 7 | if(y%400 ==0 || (y%4==0 && y%100!=0)) printf("leap year"); 8 | else printf("not a leap year"); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /C/program-70/README.md: -------------------------------------------------------------------------------- 1 | Program 70 2 | 3 | C program to make simple calculator -------------------------------------------------------------------------------- /C/program-70/program70.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char op; 5 | float number1,number2,result; 6 | for(int i=0; i<5;i++) 7 | { 8 | printf("\nEnter\n + for Addition \n - for Subtraction \n * for Multiplication \n / for Division"); 9 | printf("\nEnter the operation you want to perform\n"); 10 | scanf("%s",&op); 11 | printf("Enter two numbers\n"); 12 | scanf("%f %f",&number1,&number2); 13 | switch(op) 14 | { 15 | case'+':result=number1+number2; 16 | printf("Sum is %f\n",result); 17 | break; 18 | case'-':result=number1-number2; 19 | printf("Difference is %f\n",result); 20 | break; 21 | case'*':result=number1*number2; 22 | printf("Product is %f\n",result); 23 | break; 24 | case'/':if(number2==0) 25 | { 26 | printf("Division not possible\n"); 27 | } 28 | else 29 | { 30 | result=number1/number2; 31 | printf("Quotient is %f\n",result); 32 | } 33 | break; 34 | default:printf("Enter proper input\n"); 35 | } 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /C/program-72/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Node 4 | { 5 | int data; 6 | struct Node *next; 7 | }*first=NULL; 8 | void create(int A[],int n) 9 | { 10 | int i; 11 | struct Node *t,*last; 12 | first=(struct Node *)malloc(sizeof(struct Node)); 13 | first->data=A[0]; 14 | first->next=NULL; 15 | last=first; 16 | 17 | for(i=1;idata=A[i]; 21 | t->next=NULL; 22 | last->next=t; 23 | last=t; 24 | } 25 | } 26 | void Display(struct Node *p) 27 | { 28 | while(p!=NULL) 29 | { 30 | printf("%d ",p->data); 31 | p=p->next; 32 | } 33 | } 34 | void RDisplay(struct Node *p) 35 | { 36 | if(p!=NULL) 37 | { 38 | RDisplay(p->next); 39 | printf("%d ",p->data); 40 | 41 | } 42 | } 43 | int main() 44 | { 45 | struct Node *temp; 46 | int A[]={3,5,7,10,25,8,32,2}; 47 | create(A,8); 48 | 49 | Display(first); 50 | 51 | return 0; 52 | } -------------------------------------------------------------------------------- /C/program-72/readme.md: -------------------------------------------------------------------------------- 1 | program 72 2 | 3 | C program to create and display a linked-lists -------------------------------------------------------------------------------- /C/program-74/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n, reverse=0, rem; 5 | printf("Enter a number: "); 6 | scanf("%d", &n); 7 | while(n!=0) 8 | { 9 | rem=n%10; 10 | reverse=reverse*10+rem; 11 | n/=10; 12 | } 13 | printf("Reversed Number: %d",reverse); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C/program-74/readme.md: -------------------------------------------------------------------------------- 1 | C Program to reverse a given number -------------------------------------------------------------------------------- /C/program-77/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int m, n, p, q, c, d, k, sum = 0; 6 | int mat1[10][10], mat2[10][10], mat3[10][10]; 7 | 8 | printf(“Enter number of rows and columns of mat1 matrix\n”); 9 | scanf(“%d%d”, &m, &n); 10 | printf(“Enter elements of matrix 1\n”); 11 | 12 | for (c = 0; c < m; c++) 13 | for (d = 0; d < n; d++) 14 | scanf(“%d”, &mat1[c][d]); 15 | 16 | printf(“\nEnter number of rows and columns of mat2 matrix\n”); 17 | scanf(“%d%d”, &p, &q); 18 | 19 | if (n != p) 20 | printf(“\nThe matrices can’t be multiplied with each other.\n”); 21 | else 22 | { 23 | printf(“\nEnter elements of matrix2\n”); 24 | 25 | for (c = 0; c < p; c++) 26 | for (d = 0; d < q; d++) 27 | scanf(“%d”, &mat2[c][d]); 28 | 29 | for (c = 0; c < m; c++) { 30 | for (d = 0; d < q; d++) { 31 | for (k = 0; k < p; k++) { 32 | sum = sum + mat1[c][k]*mat2[k][d]; 33 | } 34 | 35 | mat3[c][d] = sum; 36 | sum = 0; 37 | } 38 | } 39 | 40 | printf(“\nProduct of the matrices:\n”); 41 | 42 | for (c = 0; c < m; c++) { 43 | for (d = 0; d < q; d++) 44 | printf(“%d\t”, mat3[c][d]); 45 | 46 | printf(“\n”); 47 | } 48 | } 49 | 50 | return 0; 51 | } -------------------------------------------------------------------------------- /C/program-77/readme.md: -------------------------------------------------------------------------------- 1 | C program to multiply matrices -------------------------------------------------------------------------------- /C/program-78/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); 6 | int h, b; 7 | float area; 8 | printf("\n\nEnter the height of the Triangle: "); 9 | scanf("%d", &h); 10 | printf("\n\nEnter the base of the Triangle: "); 11 | scanf("%d", &b); 12 | 13 | /* 14 | Formula for the area of the triangle = (height x base)/2 15 | 16 | Also, typecasting denominator from int to float 17 | to get the output in float 18 | */ 19 | area = (h*b)/(float)2; 20 | printf("\n\n\nThe area of the triangle is: %f", area); 21 | 22 | printf("\n\n\t\t\tCoding is Fun !\n\n\n"); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C/program-78/readme.md: -------------------------------------------------------------------------------- 1 | C Program to find the Area of Triangle using Base and Height -------------------------------------------------------------------------------- /C/program-79/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() 4 | { 5 | printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); 6 | float principal_amt, rate, simple_interest; 7 | int time; 8 | printf("Enter the value of principal amount, rate and time\n\n\n"); 9 | scanf("%f%f%d", &principal_amt, &rate, &time); 10 | 11 | // considering rate is in percentage 12 | simple_interest = (principal_amt*rate*time)/100.0; 13 | 14 | // usually used to align text in form of columns in table 15 | printf("\n\n\t\t\tAmount = Rs.%7.3f\n ", principal_amt); 16 | 17 | printf("\n\n\t\t\tRate = Rs.%7.3f\n ", rate); 18 | printf("\n\n\t\t\tTime= %d years \n", time); 19 | printf("\n\n\t\t\tSimple Interest = Rs.%7.3f\n ", simple_interest); 20 | printf("\n\n\t\t\tCoding is Fun !\n\n\n"); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C/program-79/readme.md: -------------------------------------------------------------------------------- 1 | C Program to calculate Simple Interest -------------------------------------------------------------------------------- /C/program-8/README.md: -------------------------------------------------------------------------------- 1 | Program to calculate years ,months ,days 2 | -------------------------------------------------------------------------------- /C/program-8/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | clrscr(); 5 | int y,n,m,d,j; 6 | printf("enter the input"); 7 | scanf("%d",&n); 8 | y=n/365; 9 | m=n%365; 10 | j=n/30; 11 | d=n%30; 12 | printf("year=%d",y); 13 | printf("months =%d",j); 14 | printf("days=%d",d); 15 | getch(); 16 | } 17 | -------------------------------------------------------------------------------- /C/program-80/program.c: -------------------------------------------------------------------------------- 1 | /* 2 | This Program calulates all the prime between the range of numbers 3 | includes the numbers which is provided. 4 | 5 | For e.g: 2 7 6 | Prime Numbers are : 2 3 5 7 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | char primecheck(int); 13 | 14 | int main() 15 | { 16 | int i,num1,num2,cases; 17 | char ans; 18 | printf("Enter Number of Test Cases: "); 19 | scanf("%d",&cases); 20 | while (cases--) 21 | { 22 | printf("Enter First Number: "); 23 | scanf("%d",&num1); 24 | printf("Enter Second Number: "); 25 | scanf("%d",&num2); 26 | 27 | printf("Answer: "); 28 | for(i=num1;i<=num2;i++) 29 | { 30 | ans = primecheck(i); 31 | if (ans == 'y') 32 | printf("%d ",i); 33 | } 34 | printf("\n"); 35 | } 36 | return 0; 37 | } 38 | 39 | char primecheck(int num) 40 | { 41 | int i; 42 | if (num == 0 || num == 1) 43 | return 'n'; 44 | else 45 | { 46 | for(i=(num-1);i>1;i--) 47 | { 48 | if(num%i == 0) 49 | { 50 | return 'n'; 51 | } 52 | else 53 | continue; 54 | } 55 | return 'y'; 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /C/program-81/README.md: -------------------------------------------------------------------------------- 1 | Program 81 2 | 3 | C Program to implement Linked Lists. 4 | -------------------------------------------------------------------------------- /C/program-81/program.c: -------------------------------------------------------------------------------- 1 | /* Implementing a Linked list*/ 2 | 3 | 4 | #include 5 | #include 6 | struct node{ 7 | int data; 8 | struct node *next; 9 | }; 10 | typedef struct node NODE; 11 | NODE *head=NULL; 12 | NODE *end=NULL; 13 | 14 | void create( int data){ 15 | NODE *temp; 16 | temp =(NODE*)malloc(sizeof(NODE)); 17 | temp->data=data; 18 | if(head==NULL){ 19 | head=temp; 20 | end=temp; 21 | } 22 | else{ 23 | end->next=temp; 24 | end=temp; 25 | temp->next=NULL; 26 | 27 | } 28 | } 29 | void display(){ 30 | NODE *temp; 31 | temp = head; 32 | while(temp!=NULL){ 33 | printf("%d", temp->data); 34 | printf(" \n"); 35 | temp=temp->next; 36 | } 37 | } 38 | 39 | int main(){ 40 | int n; 41 | printf(" Enter the number of nodes in list: "); 42 | scanf(" %d", &n); 43 | printf("Enter the elements in the list: "); 44 | for(int i=0; i 2 | #include 3 | 4 | struct poly 5 | { 6 | int coeff; 7 | int exp; 8 | struct poly *next; 9 | }; 10 | 11 | void add(struct poly **p,int c,int e) // adding nodes for each order 12 | { 13 | struct poly *new=*p,*temp; 14 | new=(struct poly *)malloc(sizeof(struct poly)); 15 | new->coeff=c; 16 | new->exp=e; 17 | new->next=NULL; 18 | 19 | if(*p==NULL) // if start is null 20 | *p=new; 21 | else 22 | { 23 | struct poly *temp=*p; 24 | while(temp->next!=NULL) 25 | temp=temp->next; 26 | temp->next=new; 27 | } 28 | 29 | } 30 | 31 | void display(struct poly **p) // for displaying each node that contains different order of X 32 | { 33 | struct poly*temp=*p; 34 | while(temp!=NULL) 35 | { 36 | printf("+%d",temp->coeff); 37 | if(temp->exp!=0) 38 | printf("x^%d",temp->exp); 39 | temp=temp->next; 40 | } 41 | } 42 | 43 | int main() 44 | { 45 | int co,ex; 46 | char ch='y'; 47 | struct poly *start=NULL; 48 | printf("Enter the polynomial from highest order to lowest\n"); 49 | while(ch=='y') 50 | { 51 | printf("Enter the coefficient of x:\n"); 52 | scanf("%d",&co); 53 | printf("enter the exponent of x:\n"); 54 | scanf("%d",&ex); 55 | add(&start,co,ex); //calling add function 56 | printf("\n\tDo u want to add more (y/n)"); 57 | getchar(); 58 | scanf("%c",&ch); 59 | 60 | } 61 | 62 | printf("\n\tThe polynomial expression is:\t"); 63 | display(&start); //final display 64 | printf("\n"); 65 | return 0; 66 | } 67 | 68 | -------------------------------------------------------------------------------- /C/program-83/program-83.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | int a[10][10],b[10][10],mul[10][10],r,c,i,j,k; 5 | system("cls"); 6 | printf("enter the number of row="); 7 | scanf("%d",&r); 8 | printf("enter the number of column="); 9 | scanf("%d",&c); 10 | printf("enter the first matrix element=\n"); 11 | for(i=0;i 4 | 5 | int main(){ 6 | 7 | float current_btc_price, avg_cost; 8 | float total_btc, profitloss; 9 | 10 | printf("Enter Your Total Bitcoin: "); 11 | scanf("%f",&total_btc); 12 | 13 | printf("Enter Current Bitcoin Price: "); 14 | scanf("%f",¤t_btc_price); 15 | 16 | printf("Your Average Bitcoin Purchase Price: "); 17 | scanf("%f",&avg_cost); 18 | 19 | //profitloss = (current_btc_price - averagecost) x total_btc 20 | 21 | profitloss = (current_btc_price - avg_cost) * total_btc; 22 | 23 | if(profitloss > 0) 24 | printf("Bitcoin Trading Profit is: %0.2f",profitloss); 25 | else 26 | printf("Bitcoin Trading Loss is: %0.2f",profitloss); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C/program-83/readme.md: -------------------------------------------------------------------------------- 1 | Program to multiply two matrices -------------------------------------------------------------------------------- /C/program-84/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char str[100]; 4 | int i=0; 5 | printf("Enter any string:"); 6 | gets(str); 7 | //converting to uppercase 8 | while(str[i]!= '\0'){ 9 | if(str[i]>=97&&str[i]<=122){ 10 | str[i]=str[i]-32; 11 | } 12 | i++; 13 | } 14 | printf("\nThe converted string is:%s", str); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /C/program-84/readme.md: -------------------------------------------------------------------------------- 1 | # snake game in c -------------------------------------------------------------------------------- /C/program-86/README.md: -------------------------------------------------------------------------------- 1 | program 86 2 | 3 | C program to create and list of N fibonacci terms -------------------------------------------------------------------------------- /C/program-86/fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | main() { 7 | 8 | 9 | 10 | int a, b, aux, i, n; 11 | 12 | a = 0; 13 | b = 1; 14 | 15 | printf("type a number: "); 16 | scanf("%d", &n); 17 | printf("\nFibonacci:\n"); 18 | printf("%d\n", b); 19 | 20 | for(i = 0; i < n; i++) { 21 | 22 | aux = a + b; 23 | a = b; 24 | b = aux; 25 | 26 | printf("%d\n", aux); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /C/program-9/README.md: -------------------------------------------------------------------------------- 1 | Program to check two number are equal without logical operator 2 | -------------------------------------------------------------------------------- /C/program-9/program.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a,b; 6 | printf("enter the a,b"); 7 | scanf("%d%d",&a,&b); 8 | if((a^b)) printf("not similar"); 9 | else printf("similar"); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /C/sample.c: -------------------------------------------------------------------------------- 1 | /* Write the complete question between these tags*/ 2 | 3 | // start writng code from here 4 | -------------------------------------------------------------------------------- /C/samzmaths.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | 7 | system("color 4"); 8 | printf("\nSamz math>\t"); 9 | 10 | 11 | float a,d,p=1,i; 12 | char operator; 13 | 14 | scanf("%f", &a); 15 | scanf("%c", &operator); 16 | scanf("%f", &d); 17 | 18 | for(i=1;i<=d;i++) 19 | p=p*a; 20 | 21 | switch(operator) 22 | { 23 | 24 | case '+': 25 | printf("=%.2f\n\n", a+d); 26 | break; 27 | 28 | case '-': 29 | printf("=%.2f\n\n", a-d); 30 | break; 31 | 32 | case '*': 33 | printf("=%.2f\n\n", a*d); 34 | break; 35 | 36 | case '/': 37 | printf("=%.2f\n\n", a/d); 38 | break; 39 | 40 | case '^': 41 | printf("=%.2f\n\n", p); 42 | break; 43 | 44 | 45 | } 46 | 47 | 48 | main(); 49 | getch(); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Dart/Program1/README.md: -------------------------------------------------------------------------------- 1 | Q1. Write a program to check given number is even or odd. 2 | 3 | Ask the number from user in variable "number" 4 | -------------------------------------------------------------------------------- /Dart/Program1/checkevenodd.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | void main() { 4 | int number; 5 | 6 | print("Enter a number : "); 7 | number = int.parse(stdin.readLineSync()); 8 | 9 | if (number.isEven) { 10 | print("$number is an even number"); 11 | } else if (number.isOdd) { 12 | print("$number is an odd number"); 13 | } 14 | } -------------------------------------------------------------------------------- /Dart/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Dart 4 | | Program No.| Question | 5 | | ------- | ------ | 6 | | [Program-1](https://github.com/NamanManjkhola/basicprograms/blob/780344803c8bc91a4a83acaa60c81f982a3df760/Dart/Program1/checkevenodd.dart) | Program to check given number is even or odd. 7 |
8 | -------------------------------------------------------------------------------- /Interview Questions/Stack using Array/README.MD: -------------------------------------------------------------------------------- 1 | # Interview Questions and Answers 2 | 3 | | Sl no. | Question | Answer link | Language | Contributor | 4 | |---|---|---|---|---| 5 | | 1 | Implementing **Stack** using **Array** and **Linked List** | [code here](https://github.com/nitinkumar30/basicprograms/blob/master/Interview%20Questions/implementing_stack_using_array_and_linked_list.c) | C | [Nitin Kumar](https://github.com/nitinkumar30/) 6 | 7 | 8 | # Repo contributed by 9 | 10 | [Nitin Kumar](https://github.com/nitinkumar30/) 11 | -------------------------------------------------------------------------------- /Interview Questions/Trapping Rain Water/README.md: -------------------------------------------------------------------------------- 1 | Trapping Rain Water 2 | 3 | 4 | Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. 5 | 6 | Input: arr[] = {3, 0, 2, 0, 4} 7 | Output: 7 8 | 9 | Explanation: 10 | We can trap "3 units" of water between 3 and 2, 11 | "1 unit" on top of bar 2 and "3 units" between 2 12 | and 4. -------------------------------------------------------------------------------- /Interview Questions/Trapping Rain Water/Trapping Rain Water.cpp: -------------------------------------------------------------------------------- 1 | // C++ implementation of the approach 2 | #include 3 | using namespace std; 4 | 5 | int maxWater(int arr[], int n) 6 | { 7 | 8 | // indices to traverse the array 9 | int left = 0; 10 | int right = n-1; 11 | 12 | // To store Left max and right max 13 | // for two pointers left and right 14 | int l_max = 0; 15 | int r_max = 0; 16 | 17 | // To store the total amount 18 | // of rain water trapped 19 | int result = 0; 20 | while (left <= right) 21 | { 22 | 23 | // We need check for minimum of left 24 | // and right max for each element 25 | if(r_max <= l_max) 26 | { 27 | 28 | // Add the difference between 29 | // current value and right max at index r 30 | result += max(0, r_max-arr[right]); 31 | 32 | // Update right max 33 | r_max = max(r_max, arr[right]); 34 | 35 | // Update right pointer 36 | right -= 1; 37 | } 38 | else 39 | { 40 | 41 | // Add the difference between 42 | // current value and left max at index l 43 | result += max(0, l_max-arr[left]); 44 | 45 | // Update left max 46 | l_max = max(l_max, arr[left]); 47 | 48 | // Update left pointer 49 | left += 1; 50 | } 51 | } 52 | return result; 53 | } 54 | 55 | // Driver code 56 | int main() { 57 | int arr[] = {0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1}; 58 | int n = sizeof(arr)/sizeof(arr[0]); 59 | cout << maxWater(arr, n) << endl; 60 | return 0; 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /Interview Questions/Two Sum Problem/two_sum.py: -------------------------------------------------------------------------------- 1 | def twoSum(self, nums: List[int], target: int) -> List[int]: 2 | 3 | m = {} # store compliment and index of other value 4 | 5 | for i in range(len(nums)): 6 | n = nums[i] 7 | c = target - n 8 | 9 | if n in m: 10 | i1 = m[n] 11 | return [i1, i] 12 | else: 13 | m[c] = i -------------------------------------------------------------------------------- /Java/Program 5/README.md.txt: -------------------------------------------------------------------------------- 1 | Q. check if the given no. is part of the fibonacci series. 2 | If so, print the continuation of fibonacci upto next 5 terms. 3 | 4 | 5 | What is a fibonacci series? 6 | A serie with first term 1 and second term 2 which proceeds in the fashion that 7 | the next term is the sum of previous two terms. 8 | 9 | 10 | Ex. 11 | INPUT: 5 12 | OUTPUT: 5 8 13 21 44 65 13 | LOGIC: 1,2,3,5,8.... is the fibonacci and 5 is a member 14 | 5+3=8, 8+5=13... so on -------------------------------------------------------------------------------- /Java/Program 5/program.java.txt: -------------------------------------------------------------------------------- 1 | //Author @ArjunBhandari.666 2 | //github.com/ArjunBhandari-666 3 | //alternative solution to problem 4 irrespective of case input 4 | import java.io.*; 5 | import java.util.Scanner; 6 | class fibonacci 7 | { 8 | public static void main() 9 | { 10 | Scanner scan=new Scanner(System.in); 11 | System.out.println("\fEnter a number to check"); 12 | int x=scan.nextInt(),a=1,n; //using 3 variables, namely 'i','a',and 'n' to exchange term values 13 | for(int i=2;i<99999;i=n) 14 | { 15 | n=i+a; // next term 16 | if(x==a) 17 | { 18 | System.out.println("Fibbonaci continuation is \n"+a+"\t"+i+"\t"+(a+i)+"\t"+((a+i)+i)+"\t"+(((a+i)+i)+(a+i))+"\t"+((((a+i)+i)+(a+i))+((a+i)+i))); 19 | n=99999; 20 | } 21 | if(i>x && x!=a) 22 | { 23 | System.out.println("NOT A FIBONACCI TERM"); 24 | n=99999; 25 | } 26 | a=i; //updating previous term 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Java/Program 6/README.md.txt: -------------------------------------------------------------------------------- 1 | Q. Check if the given no. is a spy no. or not. 2 | 3 | What is a spy number? 4 | A number whose sum and product of digits is the same. 5 | 6 | 7 | Ex. 8 | INPUT: 123 9 | OUTPUT: YES 10 | LOGIC: 1+2+3=1x2x3 -------------------------------------------------------------------------------- /Java/Program 6/program.java.txt: -------------------------------------------------------------------------------- 1 | //Author @ArjunBhandari.666 2 | //github.com/ArjunBhandari-666 3 | //alternative solution to problem 4 irrespective of case input 4 | import java.io.*; 5 | import java.util.Scanner; 6 | class SpyNumber 7 | { 8 | public static void main() 9 | { 10 | Scanner scan=new Scanner(System.in); 11 | System.out.println("\fEnter a 3 digit number to check"); 12 | int x=scan.nextInt(); 13 | int a,b,c; 14 | a=x/100; //hundred's place 15 | b=(x/10)-(a*10); //ten's place 16 | c=x-(a*100)-(b*10); //unit's place 17 | if(a+b+c==a*b*c) 18 | System.out.println("Yes, it is a Spy Number"); 19 | else 20 | System.out.println("NO, it's not a Spy Number"); 21 | } 22 | } -------------------------------------------------------------------------------- /Java/Program-11/Program.java: -------------------------------------------------------------------------------- 1 | // Java program to find compound interest for 2 | // given values. 3 | import java.io.*; 4 | 5 | class GFG 6 | { 7 | public static void main(String args[]) 8 | { 9 | double principle = 10000, rate = 10.25, time = 5; 10 | 11 | /* Calculate compound interest */ 12 | double CI = principle * 13 | (Math.pow((1 + rate / 100), time)); 14 | 15 | System.out.println("Compound Interest is "+ CI); 16 | } 17 | } 18 | // This code is contributed by Anant Agarwal. 19 | -------------------------------------------------------------------------------- /Java/Program-11/Readme.md: -------------------------------------------------------------------------------- 1 | Q. Java Program for compound interest 2 | 3 | 4 | Formula to calculate compound interest annually is given by: 5 | 6 | Compound Interest = P(1 + R/100)r 7 | Where, 8 | P is principle amount 9 | R is the rate and 10 | T is the time span 11 | 12 | 13 | Input : Principle (amount): 1200 14 | Time: 2 15 | Rate: 5.4 16 | Output : Compound Interest = 1333.099243 -------------------------------------------------------------------------------- /Java/Program-12/Program-12.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | class Prg{ 4 | public static void main(String args[]) 5 | { 6 | Scanner sc=new Scanner(System.in); 7 | String s=sc.next(); 8 | int v=0; 9 | for(int i=0;i=0;i--){ 12 | reversed_string = reversed_string + string.charAt(i); 13 | } 14 | System.out.println("The original string is "+string); 15 | System.out.println("The reversed string is "+reversed_string); 16 | } 17 | } -------------------------------------------------------------------------------- /Java/Program-17/readme.md: -------------------------------------------------------------------------------- 1 | Program 17 2 | 3 | Program to reverse a given string 4 | -------------------------------------------------------------------------------- /Java/Program-18/ElectricityBill.java: -------------------------------------------------------------------------------- 1 | //A consumer consumes n watts per hour daily for one month. 2 | // Calculate the total energy bill of that consumer if per-unit rate is 7? 3 | // ( In $, £, €, INR, DHR, Riyal etc.) [Take 1 month = 30 Days]. 4 | package com.dsa; 5 | 6 | import java.util.Scanner; 7 | 8 | public class ElectricityBill { 9 | public static void main(String[] args) { 10 | Scanner input=new Scanner(System.in); 11 | System.out.println("Enter the watts consumed per hour"); 12 | int watts=input.nextInt(); 13 | int electricity=watts*24*30;//Total watts of electricity consumed in 30 days 14 | int cost=(electricity/1000)*7;//We divide by 1000 to convert watts to kilo-watts 15 | //One unit=One kilo-watt and One unit costs 7 16 | System.out.println("The electricity bill is "+cost); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Java/Program-18/readme.md: -------------------------------------------------------------------------------- 1 | Program-18 2 | 3 | Program to calculate electricity bill -------------------------------------------------------------------------------- /Java/Program-19/Discount.java: -------------------------------------------------------------------------------- 1 | package com.dsa; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Discount { 6 | public static void main(String[] args) { 7 | Scanner input=new Scanner(System.in); 8 | System.out.println("Enter the original price of product"); 9 | int original_price=input.nextInt(); 10 | System.out.println("Enter the discount percentage"); 11 | float discount=input.nextInt(); 12 | float discount_price=original_price*(discount/100); 13 | float final_price=original_price-discount_price; 14 | System.out.println("The discount price is: "+discount_price); 15 | System.out.println("The final price after discount is: "+final_price); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Java/Program-19/readme.md: -------------------------------------------------------------------------------- 1 | Program 19 2 | 3 | Program to calculate discount -------------------------------------------------------------------------------- /Java/Program-20/BattingAverage.java: -------------------------------------------------------------------------------- 1 | package com.dsa; 2 | 3 | import java.util.Scanner; 4 | 5 | public class BattingAverage { 6 | public static void main(String[] args) { 7 | Scanner input=new Scanner(System.in); 8 | System.out.println("Enter the number of runs scored by the batter"); 9 | int runs=input.nextInt(); 10 | System.out.println("Enter the number of times the batter got out "); 11 | int out= input.nextInt(); 12 | int batting_avg=runs/out; 13 | System.out.println("The batting average of the batter is "+batting_avg); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Java/Program-20/readme.md: -------------------------------------------------------------------------------- 1 | Program 20 2 | 3 | Program to calculate batting average 4 | -------------------------------------------------------------------------------- /Java/Program-21/readme.md: -------------------------------------------------------------------------------- 1 | Program 21 2 | 3 | Program to Partition to K Equal Sum Subsets 4 | 5 | Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal. 6 | 7 | Example 1: 8 | 9 | Input: nums = [4,3,2,3,5,2,1], k = 4 10 | Output: true 11 | Explanation: It's possible to divide it into 4 subsets (5), (1, 4), (2,3), (2,3) with equal sums. 12 | -------------------------------------------------------------------------------- /Java/Program-8/README.md: -------------------------------------------------------------------------------- 1 | Q. Java Program to Find if a Given Year is a Leap Year. 2 | 3 | 4 | Leap Year contains 366 days, which comes once every four years. Every leap year corresponds to these facts : 5 | 6 | #A century year is a year ending with 00. A century year is a leap year only if it is divisible by 400. 7 | #A leap year (except a century year) can be identified if it is exactly divisible by 4. 8 | #A century year should be divisible by 4 and 100 both. 9 | #A non-century year should be divisible only by 4. 10 | 11 | 12 | Ex. 13 | INPUT: 2000 14 | OUTPUT: 2000 : Leap-year 15 | LOGIC: 2000 is a century year divisible by 100 and 4. 16 | INPUT: 2002 17 | OUTPUT: 2002 : Non Leap-year 18 | LOGIC: 2002 is not divisible by 4, therefore not a leap year. 19 | -------------------------------------------------------------------------------- /Java/Program-8/program.java: -------------------------------------------------------------------------------- 1 | // Java program to find a leap year 2 | 3 | // Importing Classes/Files 4 | import java.io.*; 5 | 6 | // Class for leap-year dealing 7 | public class GeeksforGeeks { 8 | 9 | // Method to check leap year 10 | public static void isLeapYear(int year) 11 | { 12 | // flag to take a non-leap year by default 13 | boolean is_leap_year = false; 14 | 15 | // If year is divisible by 4 16 | if (year % 4 == 0) { 17 | 18 | // To identify whether it 19 | // is a century year or 20 | // not 21 | if (year % 100 == 0) { 22 | 23 | // Checking if year is divisible by 400 24 | // therefore century leap year 25 | if (year % 400 == 0) { 26 | is_leap_year = true; 27 | } 28 | 29 | else { 30 | is_leap_year = false; 31 | } 32 | } 33 | 34 | // Out of if loop that is Non century year 35 | // but divisible by 4, therefore leap year 36 | is_leap_year = true; 37 | } 38 | 39 | // We land here when corresponding if fails 40 | // If year is not divisible by 4 41 | else 42 | 43 | // Flag dealing- Non leap-year 44 | is_leap_year = false; 45 | 46 | if (!is_leap_year) { 47 | System.out.println(year + " : Non Leap-year"); 48 | } 49 | 50 | else { 51 | System.out.println(year + " : Leap-year"); 52 | } 53 | } 54 | 55 | // Main Driver Code 56 | public static void main(String[] args) 57 | { 58 | // Calling our function by 59 | // passing century year 60 | isLeapYear(2000); 61 | 62 | // Calling our function by 63 | // passing Non-century year 64 | isLeapYear(2002); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Java/Program.java: -------------------------------------------------------------------------------- 1 | class JavaExample 2 | { 3 | void calculateArea(float x) 4 | { 5 | System.out.println("Area of the square: "+x*x+" sq units"); 6 | } 7 | void calculateArea(float x, float y) 8 | { 9 | System.out.println("Area of the rectangle: "+x*y+" sq units"); 10 | } 11 | void calculateArea(double r) 12 | { 13 | double area = 3.14*r*r; 14 | System.out.println("Area of the circle: "+area+" sq units"); 15 | } 16 | public static void main(String args[]){ 17 | JavaExample obj = new JavaExample(); 18 | 19 | /* This statement will call the first area() method 20 | * because we are passing only one argument with 21 | * the "f" suffix. f is used to denote the float numbers 22 | * 23 | */ 24 | obj.calculateArea(6.1f); 25 | 26 | /* This will call the second method because we are passing 27 | * two arguments and only second method has two arguments 28 | */ 29 | obj.calculateArea(10,22); 30 | 31 | /* This will call the second method because we have not suffixed 32 | * the value with "f" when we do not suffix a float value with f 33 | * then it is considered as type double. 34 | */ 35 | obj.calculateArea(6.1); 36 | } 37 | } -------------------------------------------------------------------------------- /Java/program-1/README.md: -------------------------------------------------------------------------------- 1 | Program 1 2 | 3 | Write a program to find the maximum and minimum element in an array. 4 | 5 | Variable description-- 6 | N=Number of elements in an array 7 | arr=Array of size N 8 | min= Holds the minimum element 9 | max=Holds the maximum element -------------------------------------------------------------------------------- /Java/program-1/program.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class prg { 5 | public static void main (String[] args) { 6 | Scanner sc=new Scanner(System.in); 7 | System.out.println("Enter the size of array"); 8 | int N=sc.nextInt(); 9 | int arr[]=new int[N]; 10 | System.out.println("Enter the elements in the array"); 11 | for(int i=0;imax) 22 | max=arr[i]; 23 | } 24 | System.out.println("Minimum="+min+"\nMaximum="+max); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Java/program-10/Program.java: -------------------------------------------------------------------------------- 1 | // A Simple JAVA program to compute 2 | // simple interest for given principal 3 | // amount, time and rate of interest. 4 | import java.io.*; 5 | 6 | class GFG { 7 | public static void main(String args[]) 8 | { 9 | // We can change values here for 10 | // different inputs 11 | float P = 1, R = 1, T = 1; 12 | 13 | /* Calculate simple interest */ 14 | float SI = (P * T * R) / 100; 15 | System.out.println("Simple interest = " + SI); 16 | } 17 | } 18 | 19 | // This code is contributed by Anant Agarwal. 20 | -------------------------------------------------------------------------------- /Java/program-10/Readme.md: -------------------------------------------------------------------------------- 1 | Q. Java Program for simple interest 2 | 3 | Simple interest formula is given by: 4 | Simple Interest = (P x T x R)/100 5 | Where, 6 | P is the principle amount 7 | T is the time and 8 | R is the rate 9 | 10 | 11 | EXAMPLE1: 12 | Input : P = 10000 13 | R = 5 14 | T = 5 15 | Output :2500 16 | We need to find simple interest on 17 | Rs. 10, 000 at the rate of 5% for 5 18 | units of time. 19 | 20 | EXAMPLE2: 21 | Input : P = 3000 22 | R = 7 23 | T = 1 24 | Output :210 25 | -------------------------------------------------------------------------------- /Java/program-14/program.java: -------------------------------------------------------------------------------- 1 | // Java program to convert a decimal 2 | // number to binary number 3 | import java.io.*; 4 | 5 | class GFG 6 | { 7 | // function to convert decimal to binary 8 | static void decToBinary(int n) 9 | { 10 | // array to store binary number 11 | int[] binaryNum = new int[1000]; 12 | 13 | // counter for binary array 14 | int i = 0; 15 | while (n > 0) 16 | { 17 | // storing remainder in binary array 18 | binaryNum[i] = n % 2; 19 | n = n / 2; 20 | i++; 21 | } 22 | 23 | // printing binary array in reverse order 24 | for (int j = i - 1; j >= 0; j--) 25 | System.out.print(binaryNum[j]); 26 | } 27 | 28 | // driver program 29 | public static void main (String[] args) 30 | { 31 | int n = 17; 32 | decToBinary(n); 33 | } 34 | } 35 | 36 | // Contributed by Pramod Kumar 37 | -------------------------------------------------------------------------------- /Java/program-14/readme.md: -------------------------------------------------------------------------------- 1 | Q Java Program for Decimal to Binary Conversion 2 | 3 | Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent binary number. 4 | 5 | Examples: 6 | 7 | Input : 7 8 | Output : 111 9 | 10 | Input : 10 11 | Output : 1010 12 | 13 | Input: 33 14 | Output: 100001 -------------------------------------------------------------------------------- /Java/program-15/program.java: -------------------------------------------------------------------------------- 1 | // Java program to convert a decimal 2 | // number to binary number 3 | import java.io.*; 4 | 5 | class GFG 6 | { 7 | // function to convert decimal to binary 8 | static void decToBinary(int n) 9 | { 10 | // array to store binary number 11 | int[] binaryNum = new int[1000]; 12 | 13 | // counter for binary array 14 | int i = 0; 15 | while (n > 0) 16 | { 17 | // storing remainder in binary array 18 | binaryNum[i] = n % 2; 19 | n = n / 2; 20 | i++; 21 | } 22 | 23 | // printing binary array in reverse order 24 | for (int j = i - 1; j >= 0; j--) 25 | System.out.print(binaryNum[j]); 26 | } 27 | 28 | // driver program 29 | public static void main (String[] args) 30 | { 31 | int n = 17; 32 | decToBinary(n); 33 | } 34 | } 35 | 36 | // Contributed by Pramod Kumar 37 | -------------------------------------------------------------------------------- /Java/program-15/readme.md: -------------------------------------------------------------------------------- 1 | Q Java Program for Decimal to Binary Conversion 2 | 3 | Given a decimal number as input, we need to write a program to convert the given decimal number into equivalent binary number. 4 | 5 | Examples: 6 | 7 | Input : 7 8 | Output : 111 9 | 10 | Input : 10 11 | Output : 1010 12 | 13 | Input: 33 14 | Output: 100001 -------------------------------------------------------------------------------- /Java/program-2/README.md: -------------------------------------------------------------------------------- 1 | Program 2 2 | 3 | Given a String,check if it is a palindrome or not. 4 | 5 | Variable description 6 | s= Input String 7 | start= Starting index of String s 8 | end= Last index of String s 9 | flag= Variable to mark if the String is not a Palindrome -------------------------------------------------------------------------------- /Java/program-2/program.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | class prg{ 4 | public static void main(String args[]) 5 | { 6 | Scanner sc=new Scanner(System.in); 7 | String s=sc.next(); 8 | int start=0; 9 | int end=s.length()-1; 10 | int flag=0; 11 | while(start 0) { 20 | 21 | // Step 1: Find remainder 22 | int r = square % 10; 23 | 24 | // Add remainder to the current sum 25 | sum += r; 26 | 27 | // Drop last digit of the product 28 | // and store the number 29 | square = square / 10; 30 | } 31 | 32 | // Condition check 33 | // Sum of digits of number obtained is 34 | // equal to original number 35 | if (sum == n) 36 | 37 | // number is neon 38 | return true; 39 | else 40 | 41 | // numbe is not neon 42 | return false; 43 | } 44 | 45 | // Main driver method 46 | public static void main(String[] args) 47 | { 48 | // Custom input 49 | int n = 9; 50 | 51 | // Calling above function to check custom number or 52 | // if user entered number via Scanner class 53 | if (checkNeon(n)) 54 | 55 | // Print number considered is neon 56 | System.out.println("Given number " + n 57 | + " is Neon number"); 58 | else 59 | 60 | // Print number considered is not neon 61 | System.out.println("Given number " + n 62 | + " is not a Neon number"); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Javascript/program - 16/program-16.js: -------------------------------------------------------------------------------- 1 | let n = 5; 2 | let string = ""; 3 | // Upside pyramid 4 | // upside diamond 5 | for (let i = 1; i <= n; i++) { 6 | // printing spaces 7 | for (let j = n; j > i; j--) { 8 | string += " "; 9 | } 10 | // printing star 11 | for (let k = 0; k < i * 2 - 1; k++) { 12 | if (k === 0 || k === 2 * i - 2) { 13 | string += "*"; 14 | } 15 | else { 16 | string += " "; 17 | } 18 | } 19 | string += "\n"; 20 | } 21 | // downside diamond 22 | for (let i = 1; i <= n - 1; i++) { 23 | // printing spaces 24 | for (let j = 0; j < i; j++) { 25 | string += " "; 26 | } 27 | // printing star 28 | for (let k = (n - i) * 2 - 1; k >= 1; k--) { 29 | if (k === 1 || k === (n - i) * 2 - 1) { 30 | string += "*"; 31 | } 32 | else { 33 | string += " "; 34 | } 35 | } 36 | string += "\n"; 37 | } 38 | console.log(string); 39 | -------------------------------------------------------------------------------- /Javascript/program - 16/read.md: -------------------------------------------------------------------------------- 1 | # Program-16 2 | ## Program to print hollow diamond -------------------------------------------------------------------------------- /Javascript/program- 17/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Javascript/program- 17/sketch.js: -------------------------------------------------------------------------------- 1 | let cart = []; 2 | let wishlist = []; 3 | 4 | cart.push({name:"Notebook",price:50,brand:"Classmate"}); 5 | cart.push({name:"Laptop",price:40000,brand:"Dell"}); 6 | cart.push({name:"Mouse",price:700,brand:"Dell"}); 7 | 8 | wishlist.push({name:"Pen",price:500,brand:"Parker"}); 9 | wishlist.push({name:"Watch",price:2000,brand:"Titan"}); 10 | wishlist.push({name:"Mobile",price:50000,brand:"Apple"}); 11 | 12 | cart.pop(); 13 | console.log(cart); 14 | console.log("There are "+cart.length +" items in cart"); 15 | console.log(wishlist); 16 | console.log("There are "+wishlist.length +" items in cart"); 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Javascript/program- 17/style.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | margin: 0; 3 | padding: 0; 4 | } 5 | canvas { 6 | display: block; 7 | } 8 | -------------------------------------------------------------------------------- /Javascript/program-1/program-1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | SUM OF THE TWO NUMBERS 4 | 13 | 14 |
15 | ENTER NUMBER1:
16 | ENTER NUMBER2:
17 | Submit: 18 | Reset: 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /Javascript/program-1/read.md: -------------------------------------------------------------------------------- 1 | # Program-1 2 | ## This is a javascript program for adding two numbers 3 | -------------------------------------------------------------------------------- /Javascript/program-10/program-10.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

My First Web Page

6 |

My First Paragraph.

7 | 8 |

9 | 10 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Javascript/program-10/read.md: -------------------------------------------------------------------------------- 1 | # Program-10 2 | 3 | ## This is a javascript program for javascript writing into an html element 4 | 5 | -------------------------------------------------------------------------------- /Javascript/program-11/program.js: -------------------------------------------------------------------------------- 1 | const isIsogram = str => { 2 | str = str.toLowerCase(); 3 | for (let i=0 ; str.length > i ; i++){ 4 | for(let j=1+i ; str.length > j ; j++ ){ 5 | if ( str[i]==str[j] ){ 6 | return false; 7 | } 8 | } 9 | } 10 | return true; 11 | } 12 | 13 | //isIsogram('isogram'); // true 14 | //isIsogram('isIsogram'); // false -------------------------------------------------------------------------------- /Javascript/program-11/readme.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: isIsogram 3 | tags: string,begginer 4 | --- 5 | 6 | Checks if a given word is an isogram or not. An isogram is a word that has no repeating letters. 7 | 8 | - Convert string to `lowercase`/`uppercase` since capital letters do not equate to small letter. 9 | - Iterate the string using 2 for loops using the iterators `i` and `j`. Where `j` starts of 1 more than `i`. 10 | - If at any point `str[i]` is equal to `str[j]` return `false`. 11 | - If the above does not happen till you reach the end of the string return `true`. 12 | -------------------------------------------------------------------------------- /Javascript/program-12/program.js: -------------------------------------------------------------------------------- 1 | // string concatenation 2 | let a = 2 + 2 + '1'; 3 | console.log(a); // 41 4 | 5 | 6 | let b = '1' + 2 + 2; 7 | console.log(b); // 122 8 | 9 | // unary conversion using + 10 | let c = ""; 11 | console.log(+c); // 0 12 | 13 | 14 | let val1 = "2"; 15 | let val2 = "3"; 16 | console.log(+val1 + +val2); // 5 17 | 18 | console.log(+false); 19 | 20 | 21 | // chaining assignment 22 | let x,y,z; 23 | x = y = z = 5; 24 | console.log(x,y,z); // 5 5 5 25 | 26 | // increment/decrement 27 | let counter = 5; 28 | console.log(++counter); // 6 29 | console.log(counter++); //6 30 | console.log(counter); //7 31 | console.log(--counter); // 6 32 | console.log(counter--); //6 33 | console.log(counter); //5 34 | 35 | 36 | //comma operators 37 | let comma = (1+2, 3+4); 38 | console.log(comma); // 7 (returns only the last result) 39 | 40 | let sym1 = Symbol("id"); 41 | let sym2 = Symbol.for("id"); // if doesn't exist creats new one 42 | 43 | let str = "Hello \rworls"; 44 | console.log(str) 45 | 46 | 47 | // Example to find common elements between 2 arrays. 48 | let ar1 = [1,2,3,4,5]; 49 | let ar2 = [4,5,6]; 50 | 51 | let ar = ar1.filter(function(val) { 52 | for(let ke of this) { 53 | if (val == ke) 54 | return true; 55 | } 56 | }, ar2); 57 | 58 | console.log( ar ); -------------------------------------------------------------------------------- /Javascript/program-13/program.js: -------------------------------------------------------------------------------- 1 | `Asyncronous function 2 | async function executes after the main thread is done with execution` 3 | 4 | console.log("first"); 5 | 6 | async function fun() { 7 | let promise = new Promise((resolve, reject) => { 8 | setTimeout(() => resolve("Executed this!"), 2000); 9 | }); 10 | 11 | let result = await promise; 12 | console.log(result); 13 | }; 14 | 15 | fun(); 16 | 17 | console.log("first"); 18 | -------------------------------------------------------------------------------- /Javascript/program-14/program.js: -------------------------------------------------------------------------------- 1 | `Constructor Functions 2 | * Create multiple objects with same body using a constructor function` 3 | 4 | function Person(name, age){ 5 | this.name = name; 6 | this.age = age; 7 | this.greeting = function() { 8 | console.log(`hi ${name}`); 9 | } 10 | } 11 | 12 | 13 | // defining methods outside the constructor 14 | Person.hey = function() {console.log("hello")}; 15 | Person.hey(); 16 | Person.prototype.welcome = function() { 17 | console.log(`welcom ${this.name}`); 18 | } 19 | 20 | 21 | let obj = new Person('abc', 21); 22 | obj.gender = function(gen) { 23 | console.log(this.name, gen); 24 | }; 25 | obj.gender("male"); 26 | console.log(obj); 27 | console.log(obj["name"]); 28 | console.log(obj.age); 29 | obj.greeting(); 30 | obj.welcome(); 31 | 32 | 33 | function Human(name, age, gender) { 34 | Person.call(this, name, age); 35 | this.gender = gender; 36 | this.greet = function() { 37 | console.log(`hello ${this.name}`); 38 | } 39 | } 40 | 41 | let obj2 = new Human('abc', 21, "male"); 42 | console.log(obj); 43 | let obj3 = new Human('abcd', 22, "female"); 44 | console.log(obj2); 45 | 46 | let test1 = { 47 | string: "hey", 48 | } 49 | let test2 = { 50 | number: 50, 51 | } 52 | 53 | // copying objects 54 | Object.assign(test1, test2); 55 | test2.number = 60; 56 | console.log(test1); 57 | console.log(test2); 58 | 59 | console.log('test' in test1); 60 | 61 | // obj2.greet(); 62 | // obj2.greeting(); 63 | // obj3.greeting(); 64 | 65 | // console.log("name" in obj); 66 | 67 | function a() { 68 | console.log("12"); 69 | return function() { 70 | return 1; 71 | } 72 | } 73 | let b = a(); 74 | console.log(b); -------------------------------------------------------------------------------- /Javascript/program-15/program.js: -------------------------------------------------------------------------------- 1 | `class is the blurprint used for object creation. 2 | * class B inherits properties and methods from parent class A. 3 | * And Class B overwrites fun() method.` 4 | 5 | class A { 6 | constructor (name, age) { 7 | this.name = name; 8 | this.age = age; 9 | } 10 | fun() { 11 | console.log(`Saying hello to ${this.name}`); 12 | } 13 | } 14 | 15 | 16 | class B extends A { 17 | constructor (name, age, gender) { 18 | super(name, age); 19 | this.gender = gender; 20 | // this.fun(); 21 | } 22 | fun() { 23 | console.log(`Saying hello to ${this.name} from B`); 24 | } 25 | fun2() { 26 | console.log(`Saying hello to ${this.name} from B fun 2`); 27 | } 28 | } 29 | 30 | 31 | class C extends B { 32 | constructor (name, age, gender, section) { 33 | super(name, age, gender); 34 | // this.name = "fixed"; 35 | this.section = section; 36 | } 37 | fun() { 38 | console.log(`Saying hello to ${this.name} from C`); 39 | } 40 | } 41 | 42 | 43 | let instance = new A("demo", 20); 44 | let instance1 = new B("demo", 20, "male"); 45 | let instance2 = new C("Cclass", 11, "abc", "c"); 46 | 47 | console.log(instance1.name); 48 | console.log(instance1.gender); 49 | instance1.fun(); 50 | 51 | console.log(instance2.name); 52 | console.log(instance2.gender); 53 | instance2.fun(); 54 | instance2.fun2(); 55 | 56 | 57 | console.log(A.prototype); -------------------------------------------------------------------------------- /Javascript/program-16/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Get Data 8 | 9 | 10 |
11 |
12 | 13 | 14 |
15 |
16 | 17 | 18 |
19 |
20 | 21 | 22 | 23 |
24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Javascript/program-16/readme.md: -------------------------------------------------------------------------------- 1 | # Program 16 2 | 3 | Retrieve data from HTML form and validate it 4 | -------------------------------------------------------------------------------- /Javascript/program-2/program-2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | CHARACTER PROCESSING METHODS 4 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Javascript/program-2/read.md: -------------------------------------------------------------------------------- 1 | # Program-2 2 | ## This is a javascript program for string operations 3 | -------------------------------------------------------------------------------- /Javascript/program-3/program-3.html: -------------------------------------------------------------------------------- 1 | 2 | ARMSTRONG NUMBER 3 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Javascript/program-3/read.md: -------------------------------------------------------------------------------- 1 | # Program-3 2 | ## This is a javascript program for armstrong 3 | 4 | -------------------------------------------------------------------------------- /Javascript/program-4/program-4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Check Palindrome with JavaScript Program 5 | 10 | 48 | 49 | 50 |
51 | 52 | 53 |
54 | 55 | -------------------------------------------------------------------------------- /Javascript/program-4/read.md: -------------------------------------------------------------------------------- 1 | # Program-4 2 | ## This is a javascript program for palindrome 3 | 4 | -------------------------------------------------------------------------------- /Javascript/program-5/program-5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | MATHEMATICAL OPERATIONS OF TWO NUMBERS 4 | 34 | 35 |
36 | ENTER NUMBER1:
37 | ENTER NUMBER2:
38 | 39 | 40 | 41 | 42 | Reset: 43 | Result: 44 |
45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Javascript/program-5/read.md: -------------------------------------------------------------------------------- 1 | # Program-5 2 | ## This is a javascript program for mathematical operations 3 | 4 | 5 | -------------------------------------------------------------------------------- /Javascript/program-6/program-6.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | CHARACTER PROCESSING METHODS 4 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Javascript/program-6/read.md: -------------------------------------------------------------------------------- 1 | # Program-6 2 | ## This is a javascript program for character processing 3 | 4 | -------------------------------------------------------------------------------- /Javascript/program-7/program-7.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Searching strings with index Of amd LastIndex of 4 | 5 | 16 | 17 | 18 |
19 |

The String to search is:
abcdefghijklmnopqrstuvwxyzabcdefghijklm

20 |

Enter substring to search for 21 | 22 |

23 |

First Occurace located at index 24 | 25 |
Last occurance located at index 26 | 27 |
First occurance from index l2 located at index 28 | 29 |
last occurance from index l2 located at index 30 |

31 |
32 | 33 | 34 | -------------------------------------------------------------------------------- /Javascript/program-7/program.js: -------------------------------------------------------------------------------- 1 | // program to sort words in alphabetical order 2 | 3 | // take input 4 | const string = prompt('Enter a sentence: '); 5 | 6 | // converting to an array 7 | const words = string.split(' '); 8 | 9 | // sort the array elements 10 | words.sort(); 11 | 12 | // display the sorted words 13 | console.log('The sorted words are:'); 14 | 15 | for (const element of words) { 16 | console.log(element); 17 | } -------------------------------------------------------------------------------- /Javascript/program-7/read.md: -------------------------------------------------------------------------------- 1 | # Program-7 2 | 3 | ## This is a javascript program for string searching 4 | 5 | -------------------------------------------------------------------------------- /Javascript/program-8/program-8.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 |

When you click "Try it", a function will be called.

14 |

The function will display a message.

15 | 16 | 17 | 18 |

19 | 20 | 21 | -------------------------------------------------------------------------------- /Javascript/program-8/read.md: -------------------------------------------------------------------------------- 1 | # Program-8 2 | 3 | ## This is a javascript program for javascript function basic program 4 | 5 | -------------------------------------------------------------------------------- /Javascript/program-9/program-9.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

My First Web Page

6 |

My first paragraph.

7 | 8 |

Never call document.write after the document has finished loading. 9 | It will overwrite the whole document.

10 | 11 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Javascript/program-9/read.md: -------------------------------------------------------------------------------- 1 | # Program-9 2 | 3 | ## This is a javascript program for javascript writing into html output 4 | 5 | -------------------------------------------------------------------------------- /Program-28/Bin Packing Problem.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to find number of bins required using 2 | // next fit algorithm. 3 | #include 4 | using namespace std; 5 | 6 | // Returns number of bins required using next fit 7 | // online algorithm 8 | int nextFit(int weight[], int n, int c) 9 | { 10 | // Initialize result (Count of bins) and remaining 11 | // capacity in current bin. 12 | int res = 0, bin_rem = c; 13 | 14 | // Place items one by one 15 | for (int i = 0; i < n; i++) { 16 | // If this item can't fit in current bin 17 | if (weight[i] > bin_rem) { 18 | res++; // Use a new bin 19 | bin_rem = c - weight[i]; 20 | } 21 | else 22 | bin_rem -= weight[i]; 23 | } 24 | return res; 25 | } 26 | 27 | // Driver program 28 | int main() 29 | { 30 | int weight[] = { 2, 5, 4, 7, 1, 3, 8 }; 31 | int c = 10; 32 | int n = sizeof(weight) / sizeof(weight[0]); 33 | cout << "Number of bins required in Next Fit : " 34 | << nextFit(weight, n, c); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Program-28/Readme.md: -------------------------------------------------------------------------------- 1 | Given n items of different weights and bins each of capacity c, assign each item to a bin such that number of total used bins is minimized. It may be assumed that all items have weights smaller than bin capacity. 2 | 3 | 4 | Example: 5 | Input: weight[] = {4, 8, 1, 4, 2, 1} 6 | Bin Capacity c = 10 7 | Output: 2 8 | We need minimum 2 bins to accommodate all items 9 | First bin contains {4, 4, 2} and second bin {8, 1, 1} 10 | 11 | Input: weight[] = {9, 8, 2, 2, 5, 4} 12 | Bin Capacity c = 10 13 | Output: 4 14 | We need minimum 4 bins to accommodate all items. 15 | 16 | Input: weight[] = {2, 5, 4, 7, 1, 3, 8}; 17 | Bin Capacity c = 10 18 | Output: 3 -------------------------------------------------------------------------------- /Python/Program 35/readme.md: -------------------------------------------------------------------------------- 1 | Python program to search an element in a Circular Linked List -------------------------------------------------------------------------------- /Python/Program 42/program42.py: -------------------------------------------------------------------------------- 1 | def pattern(n): 2 | k = n - 2 3 | for i in range(n, -1 , -1): 4 | for j in range(k , 0 , -1): 5 | print(end=" ") 6 | k = k + 1 7 | for j in range(0, i+1): 8 | print("* " , end="") 9 | print("\r") 10 | k = 2 * n - 2 11 | for i in range(0 , n+1): 12 | for j in range(0 , k): 13 | print(end="") 14 | k = k - 1 15 | for j in range(0, i + 1): 16 | print("* ", end="") 17 | print("\r") 18 | 19 | pattern(5) -------------------------------------------------------------------------------- /Python/Program 42/readme.md: -------------------------------------------------------------------------------- 1 | Python program to print Hourglass pattern -------------------------------------------------------------------------------- /Python/Program 48/Find_area _of_triangle.py: -------------------------------------------------------------------------------- 1 | a = float(input('Enter first side: ')) 2 | b = float(input('Enter second side: ')) 3 | c = float(input('Enter third side: ')) 4 | 5 | s = (a + b + c) / 2 6 | 7 | area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 8 | print('The area of the triangle is:', area) 9 | -------------------------------------------------------------------------------- /Python/Program-21/Program 21.py.txt: -------------------------------------------------------------------------------- 1 | number = input("Enter the number to be converted to *: ") 2 | for item in number: 3 | print('*' * int(item)) -------------------------------------------------------------------------------- /Python/Program-21/README.md.txt: -------------------------------------------------------------------------------- 1 | This program is to print the number of *. Example if user enter 5. Then it'll print ***** 2 | 3 | -------------------------------------------------------------------------------- /Python/Program-22/Program 22.py.txt: -------------------------------------------------------------------------------- 1 | number = int(input("Enter a number: ")) 2 | if (number%2 == 0): 3 | print("the given number is an even number>") 4 | 5 | elif(number%3==0) : 6 | print("The number is an odd number") 7 | 8 | else: 9 | print("It is neither odd nor even number") -------------------------------------------------------------------------------- /Python/Program-22/README.md: -------------------------------------------------------------------------------- 1 | # This program Plots graph for any function. 2 | -------------------------------------------------------------------------------- /Python/Program-22/README.md.txt: -------------------------------------------------------------------------------- 1 | Program to check if a number is even or odd -------------------------------------------------------------------------------- /Python/Program-23/Program 23.py.txt: -------------------------------------------------------------------------------- 1 | start = int(input("Enter the Starting Range: ")) 2 | end = int(input("Enter the End Range: ")) 3 | print("prime numbers in the range",start,"to",end) 4 | for i in range( start, end+1 ): 5 | flag = 0 6 | for j in range(2 , i): 7 | if (i % j == 0): 8 | flag = 1 9 | break 10 | 11 | if (flag == 0): 12 | print( i , end = ' ') -------------------------------------------------------------------------------- /Python/Program-23/README.md.txt: -------------------------------------------------------------------------------- 1 | Program to find the all the prime numbers between the given range. -------------------------------------------------------------------------------- /Python/Program-24/Program 24.txt: -------------------------------------------------------------------------------- 1 | number = int(input("Enter the number to be converted to decimals: ")) 2 | 3 | 4 | sum = 0 5 | i = 0 6 | while number != 0: 7 | rem = number % 10 8 | sum = sum + rem * pow(2,i) 9 | number = int(number/10) 10 | i = i + 1 11 | print("The decimal number is: ",sum) -------------------------------------------------------------------------------- /Python/Program-24/README.md.txt: -------------------------------------------------------------------------------- 1 | Program to convert binary number to decimal -------------------------------------------------------------------------------- /Python/Program-25/Program 25.py.txt: -------------------------------------------------------------------------------- 1 | command = "" 2 | started = False 3 | while True: 4 | command = input("> ").lower() 5 | if command == "start": 6 | if started: 7 | print("How many times will you start the car") 8 | else: 9 | started = True 10 | print("Car has started") 11 | elif command == "stop": 12 | if not started : 13 | print("Car has already been stopped") 14 | else: 15 | started = False 16 | print("Car has stopped") 17 | 18 | elif command == "help": 19 | for item in ['Start - To Start the car','Stop - To Stop the car', 'Quit - to Quit']: 20 | print(item) 21 | elif command =="quit": 22 | break 23 | 24 | else : 25 | print("Sorry I dont understand") -------------------------------------------------------------------------------- /Python/Program-25/README.md.txt: -------------------------------------------------------------------------------- 1 | A program of a car game which shows if the car has started or stopped -------------------------------------------------------------------------------- /Python/Program-26/Program 26.py.txt: -------------------------------------------------------------------------------- 1 | secret_number = 9 2 | guess_count = 0 3 | guess_limit = 3 4 | while guess_count < guess_limit : 5 | guess = int(input('Guess: ')) 6 | guess_count += 1 7 | if guess == secret_number : 8 | print('You Won!') 9 | break 10 | else : 11 | print("Sorry u failed!") -------------------------------------------------------------------------------- /Python/Program-26/README.md.txt: -------------------------------------------------------------------------------- 1 | a program of a guessing game in which u guess the secret number with a guessing limit of 3 attempts -------------------------------------------------------------------------------- /Python/Program-27/Program 27.txt: -------------------------------------------------------------------------------- 1 | price = input("What is the price of your house? ") 2 | has_good_credit = False 3 | if has_good_credit: 4 | print("The downpayment is 10%") 5 | down_payment = int(price) * 10/100 6 | print("The downpayment is %s"% down_payment) 7 | else : 8 | print("The downpayment is 20%") 9 | down_payment = int(price) * 20/100 10 | print("The downpayment is %s"% down_payment) -------------------------------------------------------------------------------- /Python/Program-27/README.md.txt: -------------------------------------------------------------------------------- 1 | A program which tells you the of downpayment of the house is 10% or 20% 2 | depending if the owner has a good credit or not.The price of the house is to be entered in the output -------------------------------------------------------------------------------- /Python/Program-28/Program 28.txt: -------------------------------------------------------------------------------- 1 | import math 2 | a = int(input("Enter the first number: ")) 3 | b = int(input("Enter the second number: ")) 4 | print("The GCD of the 2 numbers is: ", math.gcd(a,b)) -------------------------------------------------------------------------------- /Python/Program-28/README.md.txt: -------------------------------------------------------------------------------- 1 | The program to find out the GCD of any 2 given numbers 2 | -------------------------------------------------------------------------------- /Python/Program-29/Program 29.py: -------------------------------------------------------------------------------- 1 | n = int(input("Enter how many numbers you want in the series: ")) 2 | first = 0 3 | second = 1 4 | for i in range(n): 5 | print(first) 6 | temp = first 7 | first = second 8 | second = temp + second -------------------------------------------------------------------------------- /Python/Program-29/README.md: -------------------------------------------------------------------------------- 1 | A program which will display the fibonacci series 2 | -------------------------------------------------------------------------------- /Python/Program-3/program.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | a=input() 4 | b=a[::-1] #String is reversed and stored in b 5 | if (a==b): # If a and b both are equal string is Palindrome 6 | print("String is Palindrome") 7 | else: 8 | print("String is not Palindrome") 9 | -------------------------------------------------------------------------------- /Python/Program-30/README.md: -------------------------------------------------------------------------------- 1 | Program 30 2 | 3 | Program to make a simple calculator 4 | -------------------------------------------------------------------------------- /Python/Program-30/program.py: -------------------------------------------------------------------------------- 1 | # Program make a simple calculator 2 | 3 | # This function adds two numbers 4 | def add(x, y): 5 | return x + y 6 | 7 | # This function subtracts two numbers 8 | def subtract(x, y): 9 | return x - y 10 | 11 | # This function multiplies two numbers 12 | def multiply(x, y): 13 | return x * y 14 | 15 | # This function divides two numbers 16 | def divide(x, y): 17 | return x / y 18 | 19 | 20 | print("Select operation.") 21 | print("1.Add") 22 | print("2.Subtract") 23 | print("3.Multiply") 24 | print("4.Divide") 25 | 26 | while True: 27 | # Take input from the user 28 | choice = input("Enter choice(1/2/3/4): ") 29 | 30 | # Check if choice is one of the four options 31 | if choice in ('1', '2', '3', '4'): 32 | num1 = float(input("Enter first number: ")) 33 | num2 = float(input("Enter second number: ")) 34 | 35 | if choice == '1': 36 | print(num1, "+", num2, "=", add(num1, num2)) 37 | 38 | elif choice == '2': 39 | print(num1, "-", num2, "=", subtract(num1, num2)) 40 | 41 | elif choice == '3': 42 | print(num1, "*", num2, "=", multiply(num1, num2)) 43 | 44 | elif choice == '4': 45 | print(num1, "/", num2, "=", divide(num1, num2)) 46 | break 47 | else: 48 | print("Invalid Input") -------------------------------------------------------------------------------- /Python/Program-31/Program 31.py: -------------------------------------------------------------------------------- 1 | for i in range (1001): 2 | num = i 3 | result = 0 4 | n = len(str(i)) 5 | while (i != 0) : 6 | digit = i%10 7 | result = result + digit**n 8 | i = i//10 9 | if num == result: 10 | print(num) -------------------------------------------------------------------------------- /Python/Program-31/README.md: -------------------------------------------------------------------------------- 1 | A program for printing Amstrong numbers 2 | -------------------------------------------------------------------------------- /Python/Program-33/Program33.py: -------------------------------------------------------------------------------- 1 | # defining a function to calculate HCF 2 | def calculate_hcf(x, y): 3 | # selecting the smaller number 4 | if x > y: 5 | smaller = y 6 | else: 7 | smaller = x 8 | for i in range(1,smaller + 1): 9 | if((x % i == 0) and (y % i == 0)): 10 | hcf = i 11 | return hcf 12 | 13 | # taking input from users 14 | num1 = int(input("Enter first number: ")) 15 | num2 = int(input("Enter second number: ")) 16 | # printing the result for the users 17 | print("The H.C.F. of", num1,"and", num2,"is", calculate_hcf(num1, num2)) -------------------------------------------------------------------------------- /Python/Program-33/Readme.md: -------------------------------------------------------------------------------- 1 | Program to find HCF -------------------------------------------------------------------------------- /Python/Program-36/Program-36.py: -------------------------------------------------------------------------------- 1 | #WAP TO REVERSING A LIST IN PYTHON 2 | 3 | #METHOD-01: 4 | 5 | # Reversing a list using reversed() 6 | def Reverse(lst): 7 | return [ele for ele in reversed(lst)] 8 | 9 | # Driver Code 10 | lst = [10, 11, 12, 13, 14, 15] 11 | print(Reverse(lst)) 12 | 13 | 14 | #METHOD-02: 15 | 16 | # Reversing a list using reverse() 17 | def Reverse(lst): 18 | lst.reverse() 19 | return lst 20 | 21 | lst = [10, 11, 12, 13, 14, 15] 22 | print(Reverse(lst)) 23 | 24 | 25 | METHOD-03: 26 | 27 | # Reversing a list using slicing technique 28 | def Reverse(lst): 29 | new_lst = lst[::-1] 30 | return new_lst 31 | 32 | lst = [10, 11, 12, 13, 14, 15] 33 | print(Reverse(lst)) 34 | 35 | 36 | #END 37 | -------------------------------------------------------------------------------- /Python/Program-36/README.md: -------------------------------------------------------------------------------- 1 | THIS IS THE PYTHON BASED CODES WHICH HELPS YOU TO REVERSE A LIST FROM 3 DIFFERENT METHODS 2 | -------------------------------------------------------------------------------- /Python/Program-48/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/.DS_Store -------------------------------------------------------------------------------- /Python/Program-48/Find_area _of_triangle.py: -------------------------------------------------------------------------------- 1 | a = float(input('Enter first side: ')) 2 | b = float(input('Enter second side: ')) 3 | c = float(input('Enter third side: ')) 4 | 5 | s = (a + b + c) / 2 6 | 7 | area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 8 | print('The area of the triangle is:', area) 9 | 10 | -------------------------------------------------------------------------------- /Python/Program-48/README.md: -------------------------------------------------------------------------------- 1 | # Lane_Detection 2 | """ 3 | basic images have been added to use as templates for this open CV project, which has a fun interface as well 4 | """ -------------------------------------------------------------------------------- /Python/Program-48/media/averagedLines.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/media/averagedLines.jpg -------------------------------------------------------------------------------- /Python/Program-48/media/carDashCam.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/media/carDashCam.mp4 -------------------------------------------------------------------------------- /Python/Program-48/media/edgeFrame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/media/edgeFrame.png -------------------------------------------------------------------------------- /Python/Program-48/media/final.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/media/final.gif -------------------------------------------------------------------------------- /Python/Program-48/media/gaussianFrame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/media/gaussianFrame.png -------------------------------------------------------------------------------- /Python/Program-48/media/grayFrame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/media/grayFrame.png -------------------------------------------------------------------------------- /Python/Program-48/media/houghLinesFrame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/media/houghLinesFrame.png -------------------------------------------------------------------------------- /Python/Program-48/media/originalFrame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/media/originalFrame.png -------------------------------------------------------------------------------- /Python/Program-48/media/output.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/media/output.mp4 -------------------------------------------------------------------------------- /Python/Program-48/media/roiFrame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/media/roiFrame.png -------------------------------------------------------------------------------- /Python/Program-48/media/roiMask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/Python/Program-48/media/roiMask.png -------------------------------------------------------------------------------- /Python/Program34/Program34.py: -------------------------------------------------------------------------------- 1 | # First import the calendar module 2 | import calendar 3 | # ask of month and year 4 | yy = int(input("Enter year: ")) 5 | mm = int(input("Enter month: ")) 6 | # display the calendar 7 | print(calendar.month(yy,mm)) -------------------------------------------------------------------------------- /Python/Program34/Readme.md: -------------------------------------------------------------------------------- 1 | Program to display calender -------------------------------------------------------------------------------- /Python/Program43/Program43.py: -------------------------------------------------------------------------------- 1 | terms = 10 2 | 3 | # Uncomment code below to take input from the user 4 | # terms = int(input("How many terms? ")) 5 | 6 | # use anonymous function 7 | result = list(map(lambda x: 2 ** x, range(terms))) 8 | 9 | print("The total terms are:",terms) 10 | for i in range(terms): 11 | print("2 raised to power",i,"is",result[i]) -------------------------------------------------------------------------------- /Python/Program43/Readme.md: -------------------------------------------------------------------------------- 1 | # Display the powers of 2 using anonymous function -------------------------------------------------------------------------------- /Python/Program44/Program44.py: -------------------------------------------------------------------------------- 1 | dec = 344 2 | 3 | print("The decimal value of", dec, "is:") 4 | print(bin(dec), "in binary.") 5 | print(oct(dec), "in octal.") 6 | print(hex(dec), "in hexadecimal.") -------------------------------------------------------------------------------- /Python/Program44/Readme.md: -------------------------------------------------------------------------------- 1 | # Python program to convert decimal into other number systems -------------------------------------------------------------------------------- /Python/Program45/Program45.py: -------------------------------------------------------------------------------- 1 | def recur_fibo(n): 2 | if n <= 1: 3 | return n 4 | else: 5 | return(recur_fibo(n-1) + recur_fibo(n-2)) 6 | 7 | nterms = 10 8 | 9 | # check if the number of terms is valid 10 | if nterms <= 0: 11 | print("Plese enter a positive integer") 12 | else: 13 | print("Fibonacci sequence:") 14 | for i in range(nterms): 15 | print(recur_fibo(i)) -------------------------------------------------------------------------------- /Python/Program45/Readme.md: -------------------------------------------------------------------------------- 1 | # Python program to display the Fibonacci sequence -------------------------------------------------------------------------------- /Python/Program46/Program46.py: -------------------------------------------------------------------------------- 1 | # Program make a simple calculator 2 | 3 | # This function adds two numbers 4 | def add(x, y): 5 | return x + y 6 | 7 | # This function subtracts two numbers 8 | def subtract(x, y): 9 | return x - y 10 | 11 | # This function multiplies two numbers 12 | def multiply(x, y): 13 | return x * y 14 | 15 | # This function divides two numbers 16 | def divide(x, y): 17 | return x / y 18 | 19 | 20 | print("Select operation.") 21 | print("1.Add") 22 | print("2.Subtract") 23 | print("3.Multiply") 24 | print("4.Divide") 25 | 26 | while True: 27 | # take input from the user 28 | choice = input("Enter choice(1/2/3/4): ") 29 | 30 | # check if choice is one of the four options 31 | if choice in ('1', '2', '3', '4'): 32 | num1 = float(input("Enter first number: ")) 33 | num2 = float(input("Enter second number: ")) 34 | 35 | if choice == '1': 36 | print(num1, "+", num2, "=", add(num1, num2)) 37 | 38 | elif choice == '2': 39 | print(num1, "-", num2, "=", subtract(num1, num2)) 40 | 41 | elif choice == '3': 42 | print(num1, "*", num2, "=", multiply(num1, num2)) 43 | 44 | elif choice == '4': 45 | print(num1, "/", num2, "=", divide(num1, num2)) 46 | 47 | # check if user wants another calculation 48 | # break the while loop if answer is no 49 | next_calculation = input("Let's do next calculation? (yes/no): ") 50 | if next_calculation == "no": 51 | break 52 | 53 | else: 54 | print("Invalid Input") -------------------------------------------------------------------------------- /Python/Program46/Readme.md: -------------------------------------------------------------------------------- 1 | # Simple Calculator by Using Functions -------------------------------------------------------------------------------- /Python/Program47/Program47.py: -------------------------------------------------------------------------------- 1 | # Python program to shuffle a deck of card 2 | 3 | # importing modules 4 | import itertools, random 5 | 6 | # make a deck of cards 7 | deck = list(itertools.product(range(1,14),['Spade','Heart','Diamond','Club'])) 8 | 9 | # shuffle the cards 10 | random.shuffle(deck) 11 | 12 | # draw five cards 13 | print("You got:") 14 | for i in range(5): 15 | print(deck[i][0], "of", deck[i][1]) 16 | -------------------------------------------------------------------------------- /Python/Program47/Readme.md: -------------------------------------------------------------------------------- 1 | # Python program to shuffle a deck of card 2 | -------------------------------------------------------------------------------- /Python/program-1/program.py: -------------------------------------------------------------------------------- 1 | print("Hello, World!") -------------------------------------------------------------------------------- /Python/program-10/program.py: -------------------------------------------------------------------------------- 1 | # Python program to shuffle a deck of card 2 | 3 | import itertools, random 4 | 5 | deck = list(itertools.product(range(1,14),['Spade','Heart','Diamond','Club'])) 6 | 7 | random.shuffle(deck) 8 | 9 | print("woohh here you got:") 10 | for i in range(5): 11 | print(deck[i][0], "of", deck[i][1]) 12 | -------------------------------------------------------------------------------- /Python/program-11/program.py: -------------------------------------------------------------------------------- 1 | #fibonacci series 2 | nterms = int(input("How many terms? ")) 3 | 4 | # first two terms 5 | n1, n2 = 0, 1 6 | count = 0 7 | 8 | if nterms <= 0: 9 | print("Please enter a positive integer") 10 | elif nterms == 1: 11 | print("Fibonacci sequence upto",nterms,":") 12 | print(n1) 13 | else: 14 | print("Fibonacci sequence:") 15 | while count < nterms: 16 | print(n1) 17 | nth = n1 + n2 18 | # update values 19 | n1 = n2 20 | n2 = nth 21 | count += 1 -------------------------------------------------------------------------------- /Python/program-12/program.py: -------------------------------------------------------------------------------- 1 | # Program to check if a number is prime or not 2 | 3 | num = 407 4 | 5 | # To take input from the user 6 | #num = int(input("Enter a number: ")) 7 | 8 | # prime numbers are greater than 1 9 | if num > 1: 10 | # check for factors 11 | for i in range(2,num): 12 | if (num % i) == 0: 13 | print(num,"is not a prime number") 14 | print(i,"times",num//i,"is",num) 15 | break 16 | else: 17 | print(num,"is a prime number") 18 | 19 | # if input number is less than 20 | # or equal to 1, it is not prime 21 | else: 22 | print(num,"is not a prime number") -------------------------------------------------------------------------------- /Python/program-13/program.py: -------------------------------------------------------------------------------- 1 | # Returns index of x in arr if present, else -1 2 | def binary_search(arr, low, high, x): 3 | 4 | # Check base case 5 | if high >= low: 6 | 7 | mid = (high + low) // 2 8 | 9 | # If element is present at the middle itself 10 | if arr[mid] == x: 11 | return mid 12 | 13 | # If element is smaller than mid, then it can only 14 | # be present in left subarray 15 | elif arr[mid] > x: 16 | return binary_search(arr, low, mid - 1, x) 17 | 18 | # Else the element can only be present in right subarray 19 | else: 20 | return binary_search(arr, mid + 1, high, x) 21 | 22 | else: 23 | # Element is not present in the array 24 | return -1 25 | 26 | # Test array 27 | arr = [ 2, 3, 4, 10, 40 ] 28 | x = 10 29 | 30 | # Function call 31 | result = binary_search(arr, 0, len(arr)-1, x) 32 | 33 | if result != -1: 34 | print("Element is present at index", str(result)) 35 | else: 36 | print("Element is not present in array") -------------------------------------------------------------------------------- /Python/program-13/readme.md: -------------------------------------------------------------------------------- 1 | python program for binary search -------------------------------------------------------------------------------- /Python/program-14/program.py: -------------------------------------------------------------------------------- 1 | # Python3 program to find simple interest 2 | # for given principal amount, time and 3 | # rate of interest. 4 | 5 | def simple_interest(p,t,r): 6 | print('The principal is', p) 7 | print('The time period is', t) 8 | print('The rate of interest is',r) 9 | 10 | si = (p * t * r)/100 11 | 12 | print('The Simple Interest is', si) 13 | return si 14 | 15 | # Driver code 16 | simple_interest(8, 6, 8) -------------------------------------------------------------------------------- /Python/program-15/program.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | start = datetime.datetime.now() 3 | arr = [5, 8, 1, 3, 3, 0, 7, 4,5,8, 9, 10, 84, 34, 22] 4 | arr_size = len(arr) 5 | new_arr = [None]*(arr_size) 6 | n = 0 7 | 8 | for i in range(arr_size): 9 | n=0 10 | for j in range(arr_size): 11 | if arr[i] > arr[j]: 12 | n+=1 13 | while new_arr[n] == arr[i]: 14 | n+=1 15 | new_arr[n] = arr[i] 16 | 17 | arr = new_arr 18 | 19 | for i in range(arr_size): 20 | print ("%d" %arr[i]), 21 | 22 | finish = datetime.datetime.now() 23 | print (finish-start) 24 | -------------------------------------------------------------------------------- /Python/program-16/program.py: -------------------------------------------------------------------------------- 1 | for i in range(5): 2 | for j in range(i): 3 | print('*', end=' ') 4 | print() -------------------------------------------------------------------------------- /Python/program-17/program.py: -------------------------------------------------------------------------------- 1 | #Python Program to Convert Decimal to Binary 2 | 3 | def decimalToBinary(num): 4 | """This function converts decimal number 5 | to binary and prints it""" 6 | if num > 1: 7 | decimalToBinary(num // 2) 8 | print(num % 2, end='') 9 | 10 | 11 | # decimal number 12 | number = int(input("Enter any decimal number: ")) 13 | 14 | decimalToBinary(number) 15 | -------------------------------------------------------------------------------- /Python/program-18/program.py: -------------------------------------------------------------------------------- 1 | 2 | year = int( input('Enter Year: ')) 3 | 4 | if (year%4) and (year%100) and (year%400) == 0: 5 | print('Leap year') 6 | else: 7 | print('Not leap year') 8 | -------------------------------------------------------------------------------- /Python/program-19/program.py: -------------------------------------------------------------------------------- 1 | a = int(input()) 2 | count = 0 3 | list_1 = [i for i in range(1, 51)] 4 | 5 | for i in list_1: 6 | if i != a: 7 | if i%a == 0: 8 | count+=1 9 | 10 | print(count,end='') -------------------------------------------------------------------------------- /Python/program-2/program.py: -------------------------------------------------------------------------------- 1 | fact=int(input("input any number")) 2 | # input any number 3 | factorial = 1 4 | #predefined factorial of 0 5 | if fact < 0: 6 | print("factorial is not possible") 7 | elif fact == 0: 8 | print("factorial of "+str(fact) +" is "+str(factorial)) 9 | else: 10 | fact1=fact 11 | while(fact>2): 12 | fact-=1 13 | fact1=fact1*(fact) 14 | print("factorial is "+ str(fact1)) -------------------------------------------------------------------------------- /Python/program-20/program.py: -------------------------------------------------------------------------------- 1 | a,b = input().split() 2 | 3 | a = int(a) 4 | b = int(b) 5 | 6 | list_1 = list(x for x in range(a+1,b+1)) 7 | 8 | for i in list_1[a:b]: 9 | print(i) -------------------------------------------------------------------------------- /Python/program-32/Program32.py: -------------------------------------------------------------------------------- 1 | # defining a function to calculate LCM 2 | def calculate_lcm(x, y): 3 | # selecting the greater number 4 | if x > y: 5 | greater = x 6 | else: 7 | greater = y 8 | while(True): 9 | if((greater % x == 0) and (greater % y == 0)): 10 | lcm = greater 11 | break 12 | greater += 1 13 | return lcm 14 | 15 | # taking input from users 16 | num1 = int(input("Enter first number: ")) 17 | num2 = int(input("Enter second number: ")) 18 | # printing the result for the users 19 | print("The L.C.M. of", num1,"and", num2,"is", calculate_lcm(num1, num2)) -------------------------------------------------------------------------------- /Python/program-32/Readme (2).md: -------------------------------------------------------------------------------- 1 | Program to Calculate LCM of two number -------------------------------------------------------------------------------- /Python/program-32/readme.md: -------------------------------------------------------------------------------- 1 | Returns the human-readable format of the given number of seconds. -------------------------------------------------------------------------------- /Python/program-4/program.py: -------------------------------------------------------------------------------- 1 | # Store input numbers 2 | num1 = input('Enter first number: ') 3 | num2 = input('Enter second number: ') 4 | 5 | # Add two numbers 6 | sum = float(num1) + float(num2) 7 | 8 | # Display the sum 9 | print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) 10 | -------------------------------------------------------------------------------- /Python/program-41/README.md: -------------------------------------------------------------------------------- 1 | Program 41 2 | 3 | Tic-Tac-Toe Game in python. 4 | -------------------------------------------------------------------------------- /Python/program-5/README.md: -------------------------------------------------------------------------------- 1 | Program 5 2 | 3 | This program gives the following pattern: 4 | 5 | 1 6 | 1 2 1 2 7 | 1 2 3 1 2 3 8 | 1 2 3 4 1 2 3 4 9 | 1 2 3 4 5 1 2 3 4 5 10 | 11 | -------------------------------------------------------------------------------- /Python/program-5/pragram.py: -------------------------------------------------------------------------------- 1 | for i in range(1,6): 2 | for j in range(1,6-i): 3 | print(" ",end=" ") 4 | for k in range(1,i+1): 5 | print(k,end=" ") 6 | if i>1: 7 | for l in range(1,i+1): 8 | print(l,end=" ") 9 | print() 10 | -------------------------------------------------------------------------------- /Python/program-5/program.py: -------------------------------------------------------------------------------- 1 | rows = int(input("Enter Same Number Rows & Columns Square Pattern Rows = ")) 2 | 3 | print("===Printing Same Number in Rows and Columns of a Square Pattern===") 4 | 5 | for i in range(1, rows + 1): 6 | for j in range(i, rows + 1): 7 | print(j, end = ' ') 8 | for k in range(1, i): 9 | print(k, end = ' ') 10 | print() -------------------------------------------------------------------------------- /Python/program-6/README.md: -------------------------------------------------------------------------------- 1 | Program 6 2 | 3 | The code gives the following pattern : 4 | 5 | 1 6 | 2 2 7 | 3 3 3 8 | 4 4 4 4 9 | 5 5 5 5 5 10 | 11 | -------------------------------------------------------------------------------- /Python/program-6/program.py: -------------------------------------------------------------------------------- 1 | for i in range(1,6): 2 | for j in range(1,i+1): 3 | print(i,end=' ') 4 | print() 5 | -------------------------------------------------------------------------------- /Python/program-7/program.py: -------------------------------------------------------------------------------- 1 | #pattern 2 | for i in range(1,6): 3 | for j in range (1,6-i): 4 | print(" ",end=" ") 5 | for k in range(1,i+1): 6 | print(k,end=" ") 7 | print() 8 | -------------------------------------------------------------------------------- /Python/program-7/readme.md: -------------------------------------------------------------------------------- 1 | Program to print the following pattern 2 | 1 3 | 1 2 4 | 1 2 3 5 | 1 2 3 4 6 | 1 2 3 4 5 -------------------------------------------------------------------------------- /Python/program-8/program.py: -------------------------------------------------------------------------------- 1 | c=0 2 | for i in range(0,4): 3 | for j in range(i+1): 4 | print(c,end=" ") 5 | c=c+1 6 | print() -------------------------------------------------------------------------------- /Python/program-8/readme.md: -------------------------------------------------------------------------------- 1 | program to print the given pattern 2 | 0 3 | 1 2 4 | 3 4 5 5 | 6 7 8 9 -------------------------------------------------------------------------------- /Python/program-9/program.py: -------------------------------------------------------------------------------- 1 | #Python Program to Find Armstrong Number in an Interval 2 | 3 | 4 | lower = 100 5 | upper = 2000 6 | 7 | for num in range(lower, upper + 1): 8 | 9 | # order of number 10 | order = len(str(num)) 11 | 12 | # initialize sum 13 | sum = 0 14 | 15 | temp = num 16 | while temp > 0: 17 | digit = temp % 10 18 | sum += digit ** order 19 | temp //= 10 20 | 21 | if num == sum: 22 | print(num) 23 | -------------------------------------------------------------------------------- /flask app/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask,session,flash,render_template,redirect,session,url_for,request 2 | 3 | app = Flask(__name__) 4 | # UPLOAD_FOLDER = r'.\uploads' 5 | # DOWNLOAD_FOLDER = r'.\downloads' 6 | # TEMP_FOLDER = './temps' 7 | app.secret_key = 'awedfrtyyyrwwe' 8 | # app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER 9 | # app.config['DOWNLOAD_FOLDER'] = DOWNLOAD_FOLDER 10 | # app.config['TEMP_FOLDER'] = TEMP_FOLDER 11 | 12 | @app.route('/') 13 | def main(): 14 | return render_template('index.html') 15 | 16 | 17 | if __name__ == "__main__": 18 | app.run() -------------------------------------------------------------------------------- /flask app/static/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/flask app/static/1.jpg -------------------------------------------------------------------------------- /flask app/static/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/flask app/static/1.png -------------------------------------------------------------------------------- /flask app/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Basic Programs 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 |

Basic Programs

14 |

Basic programs in C and Python

15 |
16 |
17 | 18 |
19 | 20 | -------------------------------------------------------------------------------- /gif/giphy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/gif/giphy.gif -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Basic Programs 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 |

Basic Programs

13 |

Basic programs in C and Python

14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /kotlin/Program1/README.md: -------------------------------------------------------------------------------- 1 | Q1. Write a program to print half pyramid using ' * ' 2 | 3 | Ask no. of rows from the user in variable "rows" 4 | -------------------------------------------------------------------------------- /kotlin/Program1/pattern.kt: -------------------------------------------------------------------------------- 1 | 2 | fun main(args: Array) { 3 | print("Enter no. of rows : ") 4 | val rows = readLine() 5 | if (rows != null) { 6 | for (i in 1..rows.toInt()) { 7 | for (j in 1..i) { 8 | print("* ") 9 | } 10 | println() 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /kotlin/Program2/README.md: -------------------------------------------------------------------------------- 1 | Q2. Write a program to plus and minus with sample of extension function from kotlin 2 | -------------------------------------------------------------------------------- /kotlin/Program2/extension.kt: -------------------------------------------------------------------------------- 1 | fun main(args: Array) { 2 | println("Basic Extension Function") 3 | val plus = 2.plusNumber(2) 4 | val minus = 2.minusNumber(2) 5 | println("2 + 2 : $plus") 6 | println("2 - 2 : $minus") 7 | } 8 | 9 | fun Int.plusNumber(number: Int): Int { 10 | return this + number 11 | } 12 | 13 | fun Int.minusNumber(number: Int): Int { 14 | return this - number 15 | } -------------------------------------------------------------------------------- /kotlin/Program3/README.md: -------------------------------------------------------------------------------- 1 | Write a program to filter number from list in kotlin 2 | -------------------------------------------------------------------------------- /kotlin/Program3/filterList.kt: -------------------------------------------------------------------------------- 1 | fun main(args: Array) { 2 | println("Basic Filter List Function") 3 | val numbers = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) 4 | val odd = numbers.filter { it % 2 != 0 } 5 | val even = numbers.filter { it % 2 == 0 } 6 | val moreThan10 = numbers.filter { it > 10 } 7 | 8 | println("odd: $odd") 9 | println("even: $even") 10 | println("moreThan10: $moreThan10") 11 | 12 | val listDay= listOf("Senin","Selasa","Senin","Kamis","Jumat","Sabtu","Minggu") 13 | val containsS = listDay.filter { it.contains("s") } 14 | val equal = listDay.filter { it == "Selasa" } 15 | val length = listDay.filter { it.length > 5 } 16 | println("contains S: $containsS") 17 | println("equal: $equal") 18 | println("length: $length") 19 | } -------------------------------------------------------------------------------- /kotlin/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Kotlin 4 | | Program No.| Question | 5 | | ------- | ------ | 6 | | [Program-1](https://github.com/swaaz/basicprograms/blob/814a1e60ae23d81158d8174666f23c9b7419e15e/kotlin/Program1/pattern.kt) | Write a program to print half pyramid using ' * ' 7 | | [Program-2](https://github.com/swaaz/basicprograms/blob/master/kotlin/Program2/extension.kt) | Q2. Write a program to plus and minus with sample of extension function from kotlin 8 | | [Program-3](https://github.com/swaaz/basicprograms/blob/master/kotlin/Program3/filterList.kt) | Write a program to filter number from list in kotlin 9 | 10 |
11 | -------------------------------------------------------------------------------- /pattern.py: -------------------------------------------------------------------------------- 1 | from turtle import* 2 | speed(10) 3 | color('cyan') 4 | bgcolor('black') 5 | b = 200 6 | while b>0: 7 | left(b) 8 | forward(b*3) 9 | b=b-1 10 | -------------------------------------------------------------------------------- /program.py: -------------------------------------------------------------------------------- 1 | celsius_1 = float(input("Temperature value in degree Celsius: " )) 2 | 3 | # For Converting the temperature to degree Fahrenheit by using the above 4 | # given formula 5 | Fahrenheit_1 = (celsius_1 * 1.8) + 32 6 | 7 | # print the result 8 | print('The %.2f degree Celsius is equal to: %.2f Fahrenheit' 9 | %(celsius_1, Fahrenheit_1)) 10 | 11 | print("----OR----") 12 | celsius_2 = float (input("Temperature value in degree Celsius: " )) 13 | Fahrenheit_2 = (celsius_2 * 9/5) + 32 14 | 15 | # print the result 16 | print ('The %.2f degree Celsius is equal to: %.2f Fahrenheit' 17 | %(celsius_2, Fahrenheit_2)) 18 | -------------------------------------------------------------------------------- /src/css/index.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/src/css/index.css -------------------------------------------------------------------------------- /src/images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/src/images/1.jpg -------------------------------------------------------------------------------- /src/js/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swaaz/basicprograms/1da80d646cd23a77c109f0b7fa2cda598c726ba2/src/js/index.js --------------------------------------------------------------------------------