From 74d8503a2028815c9abba7454b2a280b3717f30f Mon Sep 17 00:00:00 2001 From: Michael Reber Date: Mon, 18 Nov 2019 14:50:36 +0100 Subject: [PATCH] remove old stuff --- ...D FFT Inplace Given a Complex 2D Array.cpp | 70 -- ...Check Multiplicability of Two Matrices.cpp | 40 -- ...ram to Check if a Matrix is Invertible.cpp | 76 -- ...gram to Check if it is a Sparse Matrix.cpp | 54 -- ...m to Compute DFT Coefficients Directly.cpp | 65 -- ...ram to Compute Determinant of a Matrix.cpp | 69 -- ...Fourier Transform Using Naive Approach.cpp | 84 --- ...ng the Fast Fourier Transform Approach.cpp | 73 -- .../C++ Program to Emulate N Dice Roller.cpp | 25 - ...o Find Basis and Dimension of a Matrix.cpp | 74 -- ...ind Closest Pair of Points in an Array.cpp | 137 ---- ...gram to Find Factoial of Large Numbers.cpp | 83 --- ... of a Number using Dynamic Programming.cpp | 55 -- ...d Factoial of a Number using Iteration.cpp | 49 -- ... Factorial of a Number using Recursion.cpp | 47 -- ...acci Numbers using Dynamic Programming.cpp | 71 -- ...Find Fibonacci Numbers using Iteration.cpp | 68 -- ...ci Numbers using Matrix Exponentiation.cpp | 92 --- ...Find Fibonacci Numbers using Recursion.cpp | 62 -- ...mbers Using Recursive Euclid Algorithm.cpp | 35 - ...++ Program to Find Inverse of a Matrix.cpp | 565 --------------- ...Find Path Between Two Nodes in a Graph.cpp | 109 --- ...m to Find the GCD and LCM of n Numbers.cpp | 57 -- ...N Number of Passwords of Length M Each.cpp | 179 ----- ...iven Range Using the Sieve of Sundaram.cpp | 72 -- ...m to Generate Random Hexadecimal Bytes.cpp | 18 - ...dom Numbers Using Middle Square Method.cpp | 45 -- ...mbers Using Multiply with Carry Method.cpp | 31 - ...sing Probability Distribution Function.cpp | 34 - ...zed Sequence of Given Range of Numbers.cpp | 26 - ...m for Multiplication of 2 signed Numbers.cpp | 141 ---- ...ement Coppersmith Freivald’s Algorithm.cpp | 129 ---- ...C++ Program to Implement Euler Theorem.cpp | 37 - ...Implement Extended Eucledian Algorithm.cpp | 55 -- ...ram to Implement Fermat Primality Test.cpp | 67 -- ...m to Implement Fermat’s Little Theorem.cpp | 49 -- ...er-Yates Algorithm for Array Shuffling.cpp | 48 -- ...ogram to Implement Gauss Seidel Method.cpp | 80 --- ... Implement Miller Rabin Primality Test.cpp | 98 --- ...ement Modular Exponentiation Algorithm.cpp | 48 -- ...t Naor-Reingold Pseudo Random Function.cpp | 35 - ...ler Random Number Generation Algorithm.cpp | 51 -- ...plement Russian Peasant Multiplication.cpp | 38 - ...+ Program to Implement Segmented Sieve.cpp | 91 --- ...+ Program to Implement Sieve of Atkins.cpp | 92 --- ...ram to Implement Sieve of Eratosthenes.cpp | 30 - ...lement Solovay-Strassen Primality Test.cpp | 110 --- ...gram to Implement Strassen’s Algorithm.cpp | 229 ------- ...to Implement the Bin Packing Algorithm.cpp | 52 -- ...ithm for Multiplication of Two Numbers.cpp | 62 -- ...or for Pseudo Random Number Generation.cpp | 95 --- ...rate Prime Numbers Between Given Range.cpp | 84 --- ...mize Wire Length in Electrical Circuit.cpp | 113 --- ...tion Operation Using Bitwise Operators.cpp | 27 - ... a Message Using Matrix Multiplication.cpp | 77 --- ...Perform LU Decomposition of any Matrix.cpp | 103 --- ...ogram to Perform Matrix Multiplication.cpp | 112 --- ...nthesization Using Dynamic Programming.cpp | 65 -- ...ion of an Integer in All Possible Ways.cpp | 80 --- ...Unique Factorization of a Given Number.cpp | 81 --- ...resent Linear Equations in Matrix Form.cpp | 49 -- ...sack Problem Using Dynamic Programming.cpp | 65 -- ...ve any Linear Equation in One Variable.cpp | 647 ------------------ ...gram to Solve the 0-1 Knapsack Problem.cpp | 61 -- ... Solve the Fractional Knapsack Problem.cpp | 78 --- ...rogram to Use rand and srand Functions.cpp | 20 - ...nt Gauss Jordan Elimination algorithm..cpp | 82 --- .../C++ Program to Construct DFA from NFA.cpp | 189 ----- ... Message Encoded Using Playfair Cipher.cpp | 121 ---- ...Encode a Message Using Playfair Cipher.cpp | 158 ----- ...ind Length of Longest Common Substring.cpp | 48 -- ...easing Subsequence of a Given Sequence.cpp | 59 -- ...C++ Program to Implement Affine Cipher.cpp | 57 -- ...Corasick Algorithm for String Matching.cpp | 146 ---- ...nt Bitap Algorithm for String Matching.cpp | 64 -- ...er-Moore Algorithm for String Matching.cpp | 61 -- ...C++ Program to Implement Caesar Cypher.cpp | 40 -- ...rogram to Implement Kadane’s Algorithm.cpp | 39 -- ...ent Knuth–Morris–Pratt Algorithm (KMP).cpp | 72 -- ...venshtein Distance Computing Algorithm.cpp | 42 -- ...m to Implement Longest Prefix Matching.cpp | 120 ---- ...gram to Implement Rabin-Karp Algorithm.cpp | 63 -- ...mplement String Matching Using Vectors.cpp | 97 --- ...r Algorithm for online String Matching.cpp | 41 -- .../C++ Program to Implement Z-Algorithm.cpp | 62 -- ...+ Program to Implement the Hill Cypher.cpp | 110 --- ...to Implement the Monoalphabetic Cypher.cpp | 88 --- ...o Implement the One Time Pad Algorithm.cpp | 92 --- ...Program to Implement the RSA Algorithm.cpp | 183 ----- ... Search Algorithm for Short Text Sizes.cpp | 52 -- ...ogram to Implement the Vigenere Cypher.cpp | 71 -- ...tography Using Transposition Technique.cpp | 163 ----- ...rm Finite State Automaton based Search.cpp | 74 -- ...ogram to Perform Naive String Matching.cpp | 38 - ...m String Matching Using String Library.cpp | 32 - ...as Bible by building a Data Structure).cpp | 49 -- ... to Compare Two Strings Using Pointers.cpp | 31 - ...C++ program to add two complex numbers.cpp | 31 - ...C++ program to generate random numbers.cpp | 20 - .../C++ program to reverse a number.cpp | 38 - ...ram to swap two numbers using pointers.cpp | 0 ...cessing Member Function Through Object.cpp | 49 -- .../CPP Program For Call By Reference.cpp | 31 - .../CPP Program For Call By Value.cpp | 23 - ...P Program For Constructor Over Loading.cpp | 76 -- ...For Declaring Pointers as Class Member.cpp | 34 - ...claring Static Members as Class Member.cpp | 49 -- .../CPP Program For Matrix Addition.cpp | 48 -- ... Program For Parameterized Constructor.cpp | 68 -- ...Program For Unary Operator Overloading.cpp | 83 --- ... Outside Classes Using Friend Function.cpp | 46 -- ...o Implement Constructor and Destructor.cpp | 77 --- ...CPP Program To Implement Encapsulation.cpp | 42 -- ...gram To Implement Function Overloading.cpp | 39 -- .../CPP Program To Implement Inheritance.cpp | 142 ---- ... Parameters To Base Class Constructors.cpp | 71 -- ...ram To Implement Pure Virtual Function.cpp | 67 -- ... Implement Random Access File Handling.cpp | 34 - ...lement Sequential Access File Handling.cpp | 32 - ...gram To Implement Virtual Base Classes.cpp | 43 -- ...Program To Implement Virtual Functions.cpp | 149 ---- ...rogram To Overriding Template Function.cpp | 49 -- ...or delete and new Operator Overloading.cpp | 134 ---- ...g Including Unary and Binary Operators.cpp | 44 -- ...tanding Protected Qualifier Activities.cpp | 74 -- c++/_Basic/2D Array.cpp | 43 -- c++/_Basic/Add n numbers.cpp | 17 - c++/_Basic/Add subtract multiply divide.cpp | 19 - c++/_Basic/Addition of digits.cpp | 17 - c++/_Basic/Addition of matrices.cpp | 28 - c++/_Basic/Area of a triangle.cpp | 12 - c++/_Basic/BellmanFord.cpp | 82 --- c++/_Basic/Binary Operator Overloading.cpp | 73 -- .../Binary Searching using recursion.cpp | 50 -- c++/_Basic/Binary to Decimal.cpp | 19 - c++/_Basic/Binary to Hexadecimal.cpp | 17 - c++/_Basic/Binary to Octal.cpp | 17 - c++/_Basic/BinaryPow.cpp | 20 - c++/_Basic/Check Positive or Negative.cpp | 20 - c++/_Basic/Comparator.cpp | 37 - c++/_Basic/ConvexHull.cpp | 39 -- c++/_Basic/Current Date.cpp | 14 - c++/_Basic/Decimal to Binary.cpp | 19 - c++/_Basic/Decimal to Octal.cpp | 18 - c++/_Basic/Delete Vowels.cpp | 47 -- c++/_Basic/Diameter.cpp | 67 -- c++/_Basic/Dijkstra.cpp | 73 -- c++/_Basic/DijkstraHeap.cpp | 123 ---- c++/_Basic/DisjointSets.cpp | 36 - c++/_Basic/FFT.cpp | 137 ---- c++/_Basic/FenwickTree.cpp | 47 -- c++/_Basic/FenwickTreeOnMap.cpp | 31 - .../Find ASCII value of a character.cpp | 12 - c++/_Basic/FindIntersection.cpp | 103 --- c++/_Basic/Get IP Address.cpp | 8 - c++/_Basic/Hcf & Lcm.cpp | 36 - c++/_Basic/KdTree.cpp | 103 --- c++/_Basic/Manacher.cpp | 65 -- c++/_Basic/Matrix.cpp | 62 -- c++/_Basic/MaxFlowDinic.cpp | 87 --- c++/_Basic/MaxMatching.cpp | 86 --- c++/_Basic/MinCostFlow.cpp | 121 ---- c++/_Basic/MinCostFlowBF.cpp | 92 --- c++/_Basic/Odd or Even.cpp | 19 - c++/_Basic/Pattern 1.cpp | 18 - c++/_Basic/Pattern 10.cpp | 31 - c++/_Basic/Pattern 2.cpp | 27 - c++/_Basic/Pattern 3.cpp | 27 - c++/_Basic/Pattern 4.cpp | 27 - c++/_Basic/Pattern 5.cpp | 27 - c++/_Basic/Pattern 6.cpp | 27 - c++/_Basic/Pattern 7.cpp | 27 - c++/_Basic/Pattern 8.cpp | 34 - c++/_Basic/Pattern 9.cpp | 44 -- c++/_Basic/Prim.cpp | 55 -- c++/_Basic/PrimesGenerator.cpp | 43 -- c++/_Basic/Scanner.cpp | 53 -- c++/_Basic/Shutdown Computer.cpp | 14 - c++/_Basic/SuffixArrayLcp.cpp | 162 ----- c++/_Basic/TreeIsomorphism.cpp | 164 ----- c++/_Basic/bigint-full.cpp | 506 -------------- c++/_Basic/bigint.cpp | 446 ------------ c++/_Basic/nCr & nPr.cpp | 41 -- c++/_Basic/polynom-roots.cpp | 88 --- ...e user and Display it if it is Positive.cs | 30 - ... & Categorize as Tall, Dwarf or Average.cs | 27 - .../C# Program to Calculate Acceleration.cs | 23 - ... the Entered Year is a Leap Year or Not.cs | 42 -- ...ether the Entered Number is Even or Odd.cs | 34 - ... given Integer has an Alternate Pattern.cs | 45 -- .../_Basic/C# Program to Compare Two Dates.cs | 26 - ...o Compute Average for the Set of Values.cs | 35 - ...the Number of 1’s in the Entered Number.cs | 46 -- .../C# Program to Create Sealed Class.cs | 24 - ... All the Prime Numbers Between 1 to 100.cs | 41 -- ...Display Numbers in the form of Triangle.cs | 42 -- ...rogram to Display Squarefeet of a House.cs | 23 - ... Program to Display the ATM Transaction.cs | 77 --- ... to Display the Date in Various Formats.cs | 36 - ...rogram to Find Greatest among 2 numbers.cs | 29 - ...C# Program to Find Magnitude of Integer.cs | 26 - ... Find a Number using Pythagoras Theorem.cs | 28 - .../C# Program to Generate Random Numbers.cs | 34 - ...and Display the Number with its Reverse.cs | 31 - ...umber and Display the Sum of the Digits.cs | 31 - ...gram to Illustrate LeftShift Operations.cs | 28 - ...Illustrate the Use of Access Specifiers.cs | 48 -- .../C# Program to Implement PhoneBook.cs | 52 -- ...ogram to Implement for-each in Inteface.cs | 85 --- ...form Division of Exponents of Same Base.cs | 29 - ...# Program to Perform Unboxing Operation.cs | 29 - .../C# Program to Print a BinaryTriangle.cs | 46 -- ...am to Print a Diamond Using Nested Loop.cs | 43 -- ...de & Display the Equivalent Description.cs | 41 -- .../_Basic/C# Program to Swap 2 Numbers.cs | 35 - ...two Numbers using Bitwise XOR Operation.cs | 27 - ...nput and print its multiplication table.cs | 31 - ...le 20) as input and prints something as.cs | 13 - ...nput to calculate and print the average.cs | 19 - ...elsius degrees to Kelvin and Fahrenheit.cs | 11 - ... Hello and your name in a separate line.cs | 12 - ...mbers which will be entered by the user.cs | 16 - ...mbers which will be entered by the user.cs | 17 - ...rint the result of dividing two numbers.cs | 7 - ... the result of the specified operations.cs | 32 - ...program to print the sum of two numbers.cs | 7 - .../C# Sharp program to swap two numbers.cs | 19 - ...int the output of (x+y)úz and xúy + yúz.cs | 16 - ...s wide and 5 rows tall using that digit.cs | 15 - ...mes in the next row, with no separation.cs | 29 - c/_Basic/Accessing an array using pointers.c | 17 - ... & Categorize as Taller, Dwarf & Average.c | 21 - ...two Integers and Check if they are Equal.c | 14 - .../C Program to Add two Complex Numbers.c | 31 - ... Calculate the Sum of Odd & Even Numbers.c | 20 - ... Check if a given Integer is Odd or Even.c | 16 - ... a given Integer is Positive or Negative.c | 16 - ...heck whether a given Number is Armstrong.c | 24 - ...whether a given Number is Perfect Number.c | 24 - ...Palindrome or not using Bitwise Operator.c | 70 -- ...cci Numbers using Command Line Arguments.c | 34 - ...ute the Sum of Digits in a given Integer.c | 20 - ...s Equivalent Gray’s Code using Recursion.c | 40 -- ...lent Gray’s Code without using Recursion.c | 35 - ...Program to Convert Binary to Hexadecimal.c | 20 - .../C Program to Convert Binary to Octal.c | 20 - ...Program to Convert Hexadecimal to Binary.c | 91 --- ...ram to Convert Numbers to Roman Numerals.c | 125 ---- .../C Program to Convert Octal to Binary.c | 49 -- .../C Program to Convert Octal to Decimal.c | 20 - ...o Convert Roman Number to Decimal Number.c | 66 -- ...umber to Binary & Count the Number of 1s.c | 28 - ... of Days in terms of Years, Weeks & Days.c | 19 - ... System to Binary System using Recursion.c | 28 - ...ert the given Binary Number into Decimal.c | 21 - ...ber of Words in a given Text Or Sentence.c | 27 - ...ing the Case of Alphabets & Display them.c | 86 --- ...gram to Count the Number of Unique Words.c | 65 -- ... of each C Keyword using Array Structure.c | 104 --- ...Function without using the Main Function.c | 11 - ...isplay its own Source Code as its Output.c | 19 - ...C Program to Display the ATM Transaction.c | 72 -- ... to Display the IP Address of the System.c | 29 - ...isplay the Inventory of Items in a Store.c | 62 -- ... Extract Last two Digits of a given Year.c | 14 - ...ind Multiplication of two Binary Numbers.c | 50 -- ...uct of 2 Numbers without using Recursion.c | 28 - ...um of Digits of a Number using Recursion.c | 28 - ...m to Find if a given Year is a Leap Year.c | 17 - ...Program to Find the Biggest of 3 Numbers.c | 27 - ...f String2 in string1 & also its Position.c | 51 -- ...nd the Number of Integers Divisible by 5.c | 29 - .../C Program to Find the Size of a Union.c | 23 - ... first 50 Natural Numbers using For Loop.c | 15 - ...am to Find the Sum of two Binary Numbers.c | 28 - ...a Number is Prime or Not using Recursion.c | 42 -- .../C Program to Generate Fibonacci Series.c | 24 - ... Program to Illustrate Pass by Reference.c | 19 - .../C Program to Illustrate Pass by Value.c | 21 - ...lustrate how User Authentication is Done.c | 29 - ...gram to Illustrate the Concept of Unions.c | 20 - ...o Implements Regular Expression Matching.c | 295 -------- ...inary Strings and Print their Binary Sum.c | 117 ---- ...and Operate Appropriately on the Numbers.c | 35 - ...in an Inventory of items in Online Store.c | 47 -- ...iven Number by 4 using Bitwise Operators.c | 15 - ...to Print Armstrong Number from 1 to 1000.c | 23 - ...Equivalent of an Integer using Recursion.c | 28 - ...two given Strings without any Repetition.c | 48 -- c/_Basic/C Program to Print Diamond Pattern.c | 42 -- ...t using a Semicolon anywhere in the Code.c | 14 - ... Print Statement without using Semicolon.c | 11 - ...t the Program Name and All its Arguments.c | 14 - ... to Print the Words Ending with Letter S.c | 38 - ...Two Integers M and N & Swap their Values.c | 25 - ...ade & Display the Equivalent Description.c | 43 -- .../C Program to Reverse a Given Number.c | 20 - ...e a Number & Check if it is a Palindrome.c | 27 - ...ord & Replace it with the Specified Word.c | 72 -- ...utdown or Turn Off the Computer in Linux.c | 10 - ... two Numbers using Bitwise XOR Operation.c | 18 - ...e Number of Leading Zero's in a Number x.c | 114 --- ...te the total execution time of a program.c | 19 - ...ind Product of 2 Numbers using Recursion.c | 32 - ...find Reverse of a Number using Recursion.c | 36 - ...to find Sum of N Numbers using Recursion.c | 31 - ... to next higher value of n with same 1's.c | 63 -- ...ace first letter of every word with caps.c | 61 -- ...paces and repeating characters only once.c | 64 -- ...program for Binary to decimal conversion.c | 16 - ...C program for decimal to octal converter.c | 17 - ...ram for hexadecimal to binary conversion.c | 85 --- ...rogram to Convert Decimal to Hexadecimal.c | 27 - .../C program to Convert Decimal to Octal.c | 22 - ...ease 1 to all of the given Integer Digit.c | 19 - ... for a given number using binary search..c | 121 ---- ... using pointers and display the results..c | 47 -- ...on also check whether it is a palindrome.c | 47 -- ...f occurences of a given number in a list.c | 50 -- ...rint hello world without using semicolon.c | 5 - ... characters by uppercase and vice-versa..c | 41 -- ...m to sort n given numbers using pointers.c | 37 - ... size of an array be declared at runtime.c | 44 -- ...se Your Own Header File in C Programming.c | 8 - ...ss of an array using Arrays and Pointers.c | 14 - c/_Basic/Print mark-sheet of students.c | 43 -- c/_Basic/Reverse a string using pointers.c | 15 - ...f each word of the string using pointers.c | 28 - c/_Basic/Show the ticking of Clock.c | 104 --- c/_Basic/Time functions in c.c | 36 - ...verage of n given numbers using pointers.c | 26 - ...ute the seconds from a given age using C.c | 12 - ...er within n given numbers using pointers.c | 28 - ...e address of two variables using pointer.c | 20 - ...What happens if you free a pointer twice.c | 21 - ...given string is palindrome number or not.c | 18 - c/_Basic/indirection in pointer.c | 40 -- c/_Basic/null pointer in c.c | 15 - perl/_Basics/! $v1 &&$v2.pl | 13 - ... that uses the pre-increment operation..pl | 8 - perl/_Basics/Adding a number and a string.pl | 8 - perl/_Basics/After incrementing.pl | 8 - perl/_Basics/After pre-decrement.pl | 8 - .../_Basics/Arithmetic Operators in action.pl | 7 - .../_Basics/Assign value to four variables.pl | 10 - perl/_Basics/Assignment Operators.pl | 15 - perl/_Basics/Assignment Statements.pl | 14 - ... Autodecrement Operators and Assignment.pl | 15 - ...sic Math Compound Assignment Statements.pl | 24 - perl/_Basics/Basic Numeric Operations.pl | 17 - .../Bitwise And Operators in action.pl | 7 - perl/_Basics/Bitwise Logical Operators.pl | 7 - .../_Basics/Bitwise Or Operators in action.pl | 7 - perl/_Basics/Bitwise operator.pl | 17 - perl/_Basics/Boolean and &&.pl | 11 - perl/_Basics/Boolean operator.pl | 15 - .../Built-in Perl Arithmetic Functions.pl | 27 - perl/_Basics/Complex Assignment.pl | 16 - perl/_Basics/Compound Assignment Operators.pl | 31 - perl/_Basics/Compound operator.pl | 13 - ...fference between pre- and postincrement.pl | 11 - perl/_Basics/Getting Input in Perl Scripts.pl | 14 - .../Increment and Decrement Operations.pl | 14 - perl/_Basics/Logical Word Operators.pl | 11 - perl/_Basics/Logical operators are defined.pl | 12 - ...TOR PURPOSENumeric operators.pl | 51 -- .../Operating and Assigning at Once.pl | 14 - perl/_Basics/Post-increment operation..pl | 7 - perl/_Basics/Precedence and Associativity.pl | 22 - ...d operators and short-circuit operators.pl | 12 - ... input and use if statement to check it.pl | 24 - perl/_Basics/Remainder and power.pl | 26 - perl/_Basics/Short-circuit operators.pl | 15 - perl/_Basics/Square $var.pl | 6 - perl/_Basics/Subtract 1 from$var.pl | 7 - perl/_Basics/The assignment operators.pl | 11 - perl/_Basics/The autoincrement operator.pl | 9 - .../To set a variable, use the = operator.pl | 6 - ...s wherever possible to force precedence.pl | 22 - ...ssignment Operators on Scalar Variables.pl | 16 - ...ement operator for a string with digits.pl | 6 - ...ng auto-increment operator for a string.pl | 5 - .../Add two numbers Program in PHP.php | 11 - .../Armstrong number Program in PHP.php | 26 - .../Even Odd number program in PHP.php | 14 - php/_Basics/Factorial of a number in PHP.php | 16 - .../Fibonacci Series Program in PHP.php | 30 - .../Number Pattern Problems in PHP.php | 59 -- .../PHP Program for Bubble sorting in PHP.php | 24 - ...rray without using any array functions.php | 15 - ...inding the smallest number in an array.php | 16 - ...ind whether a year is LEAP year or not.php | 14 - ...y until the result has a single digit..php | 16 - ...ers is a geometric progression or not..php | 28 - ...s is an arithmetic progression or not..php | 20 - ...n positive integer is a power of four..php | 22 - ... positive integer is a power of three..php | 22 - ...en positive integer is a power of two..php | 16 - ...is an anagram of another given string..php | 15 - ...teger is the power of another integer..php | 23 - ...ther a given number is an ugly number..php | 31 - ...urn the square root of a given number..php | 15 - ... and display the sum in reversed form..php | 21 - ...PHP program to find HCF of two numbers.php | 37 - ...find a missing number(s) from an array.php | 14 - ...nt appears three times except for one..php | 24 - ... in an array that doesn't occur twice..php | 20 - ...P program to find factor of any number.php | 17 - ... to find majority element in an array..php | 29 - .../PHP program to find table of a number.php | 16 - ...e length of the last word in a string..php | 23 - ...y element appears twice except for one.php | 15 - ...s and other numbers occur even number..php | 19 - ...utive numbers equal to a given number..php | 17 - ...hree consecutive numbers equal to zero.php | 20 - ...d whether a number is Armstrong or not.php | 26 - ...er a given number is a Hamming number..php | 41 -- ...program to print Reverse of any number.php | 14 - ...push all zeros to the end of an array..php | 28 - ...bits of an integer (32 bits unsigned)..php | 15 - ...m to reverse the digits of an integer..php | 15 - ... even, divide it by 2 to get n (by) 2..php | 26 - .../Palindrome number Program in PHP.php | 24 - php/_Basics/Pattern Problems in PHP.php | 406 ----------- ...int Table of aby number Program in PHP.php | 23 - php/_Basics/Print an array in PHP.php | 16 - .../Print an array using foreach in php.php | 11 - ...ts into a string with given delimiter..php | 7 - ...Program to create a Simple Calculator..php | 33 - ...ogin and Logout example using sessions.php | 56 -- ...o find number of elements in an array..php | 7 - ... find prime numbers in between a Range.php | 33 - ...d the product of elements in an array..php | 6 - ... find the sum of elements in an array..php | 6 - ...join the array elements into a string..php | 7 - ... to merge two arrays into a new array..php | 9 - ...ve the duplicate values from an array..php | 6 - ...ements in an array in ascending order..php | 7 - ...ments in an array in descending order..php | 7 - ... an array elements based on delimiter..php | 7 - php/_Basics/Reverse String Program in PHP.php | 25 - ...er using third variable program in PHP.php | 23 - ...ut using third variable program in PHP.php | 24 - ...ight of a triangle and compute the area.py | 6 - ...nd print a URL's content to the console.py | 7 - .../_Basics/Access environment variables.py | 10 - .../_Basics/Calculate midpoints of a line.py | 15 - ...culate number of days between two dates.py | 6 - ...e hypotenuse of a right angled triangle.py | 7 - ...ate the sum of the digits in an integer.py | 6 - ...e equal then return thrice of their sum.py | 10 - ... executing in 32bit or 64bit mode on OS.py | 3 - ...Compute the distance between two points.py | 7 - ...te all elements in a list into a string.py | 7 - .../Convert all units of time into seconds.py | 8 - ...ght (in feet and inches) to centimeters.py | 8 - ...nvert pressure in kilopascals to pounds.py | 7 - ...nce in feet to inches, yards, and miles.py | 8 - ...histogram from a given list of integers.py | 10 - .../Determine profiling of Python programs.py | 4 - .../Find out the number of CPUs using.py | 2 - ... and tuple with comma-separated numbers.py | 5 - ... name, platform and release information.py | 5 - ...ative integer) copies of a given string.py | 8 - ...7 return double the absolute difference.py | 8 - ...of the file that is currently executing.py | 2 - ...ilename and print the extension of that.py | 3 - ... (n) and computes the value of n+nn+nnn.py | 5 - ...radius of a circle and compute the area.py | 3 - ...List all files in a directory in Python.py | 4 - python/_Basics/Measure execution time.py | 11 - ...reverse order with a space between them.py | 3 - python/_Basics/Program to add two numbers.py | 10 - .../Program to calculate the square root.py | 9 - ...enerate a random number between 0 and 9.py | 6 - ...ay Powers of 2 Using Anonymous Function.py | 29 - .../Python Program to Add Two Matrices.py | 22 - ...ython Program to Check Armstrong Number.py | 20 - .../Python Program to Check Leap Year.py | 17 - .../Python Program to Check Prime Number.py | 22 - ...k Whether a String is Palindrome or Not.py | 17 - ...ram to Check if a Number is Odd or Even.py | 5 - ...rogram to Convert Celsius To Fahrenheit.py | 8 - ...nvert Decimal to Binary Using Recursion.py | 11 - ...ecimal to Binary, Octal and Hexadecimal.py | 9 - ... Program to Convert Kilometers to Miles.py | 11 - ...ogram to Count the Number of Each Vowel.py | 23 - .../Python Program to Display Calendar.py | 14 - ...play Fibonacci Sequence Using Recursion.py | 23 - ...ram to Display the multiplication Table.py | 11 - ...rogram to Find ASCII Value of Character.py | 9 - ...to Find Armstrong Number in an Interval.py | 26 - ...ind Factorial of Number Using Recursion.py | 23 - ...ython Program to Find Factors of Number.py | 18 - .../Python Program to Find HCF or GCD.py | 26 - .../Python Program to Find Hash of File.py | 27 - python/_Basics/Python Program to Find LCM.py | 30 - ...ind Numbers Divisible by Another Number.py | 10 - ... Sum of Natural Numbers Using Recursion.py | 20 - ...ogram to Find the Factorial of a Number.py | 19 - ...to Find the Largest Among Three Numbers.py | 21 - ... to Find the Size (Resolution) of Image.py | 26 - ...o Find the Size (Resolution) of a Image.py | 24 - ...gram to Find the Sum of Natural Numbers.py | 17 - ... to Illustrate Different Set Operations.py | 17 - ...hon Program to Make a Simple Calculator.py | 44 -- .../_Basics/Python Program to Merge Mails.py | 20 - ...Python Program to Multiply Two Matrices.py | 25 - ... Print all Prime Numbers in an Interval.py | 20 - ...Program to Print the Fibonacci sequence.py | 29 - ...am to Remove Punctuations From a String.py | 16 - ...Python Program to Shuffle Deck of Cards.py | 15 - ...Program to Solve the quadratic equation.py | 22 - ...ogram to Sort Words in Alphabetic Order.py | 19 - .../Python Program to Transpose a Matrix.py | 17 - ...on Program to find the area of triangle.py | 17 - ...words in sorted form (alphanumerically).py | 3 - ...cters (character frequency) in a string.py | 10 - ...rences of each word in a given sentence.py | 13 - ...ed to '$', except the first char itself.py | 9 - ... the last 2 chars from a given a string.py | 9 - ...he the volume of a sphere with radius 6.py | 4 - .../Python program to swap two variables.py | 16 - ...hat input back in upper and lower cases.py | 3 - ...e equal or their sum or difference is 5.py | 9 - python/_Basics/Sort files by date.py | 6 - .../Sum of the first n positive integers.py | 3 - ... a number is within 100 of 1000 or 2000.py | 6 - ...ether a passed letter is a vowel or not.py | 5 - ruby/_Basics/CheckForPowerOfTwo.rb | 13 - ruby/_Basics/CheckIFEvenOrOdd.rb | 12 - ruby/_Basics/CountSetBits.rb | 12 - ruby/_Basics/UnsetRightmostSetBit.rb | 8 - ruby/_Basics/auth.rb | 45 -- ruby/_Basics/basic_game.rb | 19 - ruby/_Basics/card_deck.rb | 14 - ruby/_Basics/dependency_inversion.rb | 48 -- ruby/_Basics/family.rb | 8 - ruby/_Basics/fibers.rb | 22 - ruby/_Basics/fibonacci.rb | 4 - ruby/_Basics/fighter.rb | 23 - ruby/_Basics/game_rankings.rb | 17 - ruby/_Basics/gil.rb | 25 - ruby/_Basics/inheritance robots.rb | 15 - ruby/_Basics/interface_segregation.rb | 96 --- ruby/_Basics/liskov_substitution.rb | 82 --- ruby/_Basics/mixins.rb | 15 - ruby/_Basics/mutex.rb | 46 -- ruby/_Basics/names.rb | 8 - ruby/_Basics/netflix.rb | 41 -- ruby/_Basics/open_close.rb | 84 --- ruby/_Basics/order.rb | 59 -- ruby/_Basics/phones.rb | 30 - ruby/_Basics/rails.rb | 56 -- ruby/_Basics/single_responsibility.rb | 92 --- ruby/_Basics/sites.rb | 10 - ruby/_Basics/towers.rb | 16 - 557 files changed, 23552 deletions(-) delete mode 100644 c++/11_Numerical_Problems/C++ Perform to a 2D FFT Inplace Given a Complex 2D Array.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Check Multiplicability of Two Matrices.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Check if a Matrix is Invertible.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Check if it is a Sparse Matrix.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Compute DFT Coefficients Directly.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Compute Determinant of a Matrix.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using Naive Approach.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using the Fast Fourier Transform Approach.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Emulate N Dice Roller.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Basis and Dimension of a Matrix.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Closest Pair of Points in an Array.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Factoial of Large Numbers.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Factoial of a Number using Dynamic Programming.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Factoial of a Number using Iteration.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Factorial of a Number using Recursion.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Dynamic Programming.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Iteration.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Matrix Exponentiation.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Fibonacci Numbers using Recursion.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find GCD of Two Numbers Using Recursive Euclid Algorithm.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Inverse of a Matrix.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find Path Between Two Nodes in a Graph.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Find the GCD and LCM of n Numbers.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Generate N Number of Passwords of Length M Each.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Generate Prime Numbers Between a Given Range Using the Sieve of Sundaram.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Generate Random Hexadecimal Bytes.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Middle Square Method.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Multiply with Carry Method.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Probability Distribution Function.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Generate Randomized Sequence of Given Range of Numbers.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Booth’s Multiplication Algorithm for Multiplication of 2 signed Numbers.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Coppersmith Freivald’s Algorithm.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Euler Theorem.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Extended Eucledian Algorithm.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Fermat Primality Test.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Fermat’s Little Theorem.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Fisher-Yates Algorithm for Array Shuffling.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Gauss Seidel Method.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Miller Rabin Primality Test.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Modular Exponentiation Algorithm.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Naor-Reingold Pseudo Random Function.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Park-Miller Random Number Generation Algorithm.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Russian Peasant Multiplication.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Segmented Sieve.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Sieve of Atkins.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Sieve of Eratosthenes.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Solovay-Strassen Primality Test.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement Strassen’s Algorithm.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement the Bin Packing Algorithm.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement the Schonhage-Strassen Algorithm for Multiplication of Two Numbers.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement the linear congruential generator for Pseudo Random Number Generation.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Implement wheel Sieve to Generate Prime Numbers Between Given Range.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Optimize Wire Length in Electrical Circuit.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Perform Addition Operation Using Bitwise Operators.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Perform Encoding of a Message Using Matrix Multiplication.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Perform LU Decomposition of any Matrix.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Perform Matrix Multiplication.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Perform Optimal Paranthesization Using Dynamic Programming.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Perform Partition of an Integer in All Possible Ways.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Perform the Unique Factorization of a Given Number.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Represent Linear Equations in Matrix Form.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Solve Knapsack Problem Using Dynamic Programming.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Solve any Linear Equation in One Variable.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Solve the 0-1 Knapsack Problem.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Solve the Fractional Knapsack Problem.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to Use rand and srand Functions.cpp delete mode 100644 c++/11_Numerical_Problems/C++ Program to implement Gauss Jordan Elimination algorithm..cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Construct DFA from NFA.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Decode a Message Encoded Using Playfair Cipher.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Encode a Message Using Playfair Cipher.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Find Length of Longest Common Substring.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Find the Longest Increasing Subsequence of a Given Sequence.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Affine Cipher.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Aho-Corasick Algorithm for String Matching.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Bitap Algorithm for String Matching.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Boyer-Moore Algorithm for String Matching.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Caesar Cypher.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Kadane’s Algorithm.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Knuth–Morris–Pratt Algorithm (KMP).cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Levenshtein Distance Computing Algorithm.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Longest Prefix Matching.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Rabin-Karp Algorithm.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement String Matching Using Vectors.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Wagner and Fisher Algorithm for online String Matching.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement Z-Algorithm.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement the Hill Cypher.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement the Monoalphabetic Cypher.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement the One Time Pad Algorithm.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement the RSA Algorithm.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement the String Search Algorithm for Short Text Sizes.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Implement the Vigenere Cypher.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Perform Cryptography Using Transposition Technique.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Perform Finite State Automaton based Search.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Perform Naive String Matching.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Perform String Matching Using String Library.cpp delete mode 100644 c++/11_Sets_&_Strings/C++ Program to Repeatedly Search the Same Text (such as Bible by building a Data Structure).cpp delete mode 100644 c++/1_Overview/C++ Program to Compare Two Strings Using Pointers.cpp delete mode 100644 c++/1_Overview/C++ program to add two complex numbers.cpp delete mode 100644 c++/1_Overview/C++ program to generate random numbers.cpp delete mode 100644 c++/1_Overview/C++ program to reverse a number.cpp delete mode 100644 c++/1_Overview/C++ program to swap two numbers using pointers.cpp delete mode 100644 c++/1_Overview/CPP Program For Accessing Member Function Through Object.cpp delete mode 100644 c++/1_Overview/CPP Program For Call By Reference.cpp delete mode 100644 c++/1_Overview/CPP Program For Call By Value.cpp delete mode 100644 c++/1_Overview/CPP Program For Constructor Over Loading.cpp delete mode 100644 c++/1_Overview/CPP Program For Declaring Pointers as Class Member.cpp delete mode 100644 c++/1_Overview/CPP Program For Declaring Static Members as Class Member.cpp delete mode 100644 c++/1_Overview/CPP Program For Matrix Addition.cpp delete mode 100644 c++/1_Overview/CPP Program For Parameterized Constructor.cpp delete mode 100644 c++/1_Overview/CPP Program For Unary Operator Overloading.cpp delete mode 100644 c++/1_Overview/CPP Program To Access Private and Protected Members Outside Classes Using Friend Function.cpp delete mode 100644 c++/1_Overview/CPP Program To Implement Constructor and Destructor.cpp delete mode 100644 c++/1_Overview/CPP Program To Implement Encapsulation.cpp delete mode 100644 c++/1_Overview/CPP Program To Implement Function Overloading.cpp delete mode 100644 c++/1_Overview/CPP Program To Implement Inheritance.cpp delete mode 100644 c++/1_Overview/CPP Program To Implement Multiple Inheritance and also Passing Parameters To Base Class Constructors.cpp delete mode 100644 c++/1_Overview/CPP Program To Implement Pure Virtual Function.cpp delete mode 100644 c++/1_Overview/CPP Program To Implement Random Access File Handling.cpp delete mode 100644 c++/1_Overview/CPP Program To Implement Sequential Access File Handling.cpp delete mode 100644 c++/1_Overview/CPP Program To Implement Virtual Base Classes.cpp delete mode 100644 c++/1_Overview/CPP Program To Implement Virtual Functions.cpp delete mode 100644 c++/1_Overview/CPP Program To Overriding Template Function.cpp delete mode 100644 c++/1_Overview/CPP Program for delete and new Operator Overloading.cpp delete mode 100644 c++/1_Overview/CPP Program to Implement Operator Overloading Including Unary and Binary Operators.cpp delete mode 100644 c++/1_Overview/CPP Program to Understanding Protected Qualifier Activities.cpp delete mode 100644 c++/_Basic/2D Array.cpp delete mode 100644 c++/_Basic/Add n numbers.cpp delete mode 100644 c++/_Basic/Add subtract multiply divide.cpp delete mode 100644 c++/_Basic/Addition of digits.cpp delete mode 100644 c++/_Basic/Addition of matrices.cpp delete mode 100644 c++/_Basic/Area of a triangle.cpp delete mode 100644 c++/_Basic/BellmanFord.cpp delete mode 100644 c++/_Basic/Binary Operator Overloading.cpp delete mode 100644 c++/_Basic/Binary Searching using recursion.cpp delete mode 100644 c++/_Basic/Binary to Decimal.cpp delete mode 100644 c++/_Basic/Binary to Hexadecimal.cpp delete mode 100644 c++/_Basic/Binary to Octal.cpp delete mode 100644 c++/_Basic/BinaryPow.cpp delete mode 100644 c++/_Basic/Check Positive or Negative.cpp delete mode 100644 c++/_Basic/Comparator.cpp delete mode 100644 c++/_Basic/ConvexHull.cpp delete mode 100644 c++/_Basic/Current Date.cpp delete mode 100644 c++/_Basic/Decimal to Binary.cpp delete mode 100644 c++/_Basic/Decimal to Octal.cpp delete mode 100644 c++/_Basic/Delete Vowels.cpp delete mode 100644 c++/_Basic/Diameter.cpp delete mode 100644 c++/_Basic/Dijkstra.cpp delete mode 100644 c++/_Basic/DijkstraHeap.cpp delete mode 100644 c++/_Basic/DisjointSets.cpp delete mode 100644 c++/_Basic/FFT.cpp delete mode 100644 c++/_Basic/FenwickTree.cpp delete mode 100644 c++/_Basic/FenwickTreeOnMap.cpp delete mode 100644 c++/_Basic/Find ASCII value of a character.cpp delete mode 100644 c++/_Basic/FindIntersection.cpp delete mode 100644 c++/_Basic/Get IP Address.cpp delete mode 100644 c++/_Basic/Hcf & Lcm.cpp delete mode 100644 c++/_Basic/KdTree.cpp delete mode 100644 c++/_Basic/Manacher.cpp delete mode 100644 c++/_Basic/Matrix.cpp delete mode 100644 c++/_Basic/MaxFlowDinic.cpp delete mode 100644 c++/_Basic/MaxMatching.cpp delete mode 100644 c++/_Basic/MinCostFlow.cpp delete mode 100644 c++/_Basic/MinCostFlowBF.cpp delete mode 100644 c++/_Basic/Odd or Even.cpp delete mode 100644 c++/_Basic/Pattern 1.cpp delete mode 100644 c++/_Basic/Pattern 10.cpp delete mode 100644 c++/_Basic/Pattern 2.cpp delete mode 100644 c++/_Basic/Pattern 3.cpp delete mode 100644 c++/_Basic/Pattern 4.cpp delete mode 100644 c++/_Basic/Pattern 5.cpp delete mode 100644 c++/_Basic/Pattern 6.cpp delete mode 100644 c++/_Basic/Pattern 7.cpp delete mode 100644 c++/_Basic/Pattern 8.cpp delete mode 100644 c++/_Basic/Pattern 9.cpp delete mode 100644 c++/_Basic/Prim.cpp delete mode 100644 c++/_Basic/PrimesGenerator.cpp delete mode 100644 c++/_Basic/Scanner.cpp delete mode 100644 c++/_Basic/Shutdown Computer.cpp delete mode 100644 c++/_Basic/SuffixArrayLcp.cpp delete mode 100644 c++/_Basic/TreeIsomorphism.cpp delete mode 100644 c++/_Basic/bigint-full.cpp delete mode 100644 c++/_Basic/bigint.cpp delete mode 100644 c++/_Basic/nCr & nPr.cpp delete mode 100644 c++/_Basic/polynom-roots.cpp delete mode 100644 c-sharp/_Basic/C# Program to Accept a Number from the user and Display it if it is Positive.cs delete mode 100644 c-sharp/_Basic/C# Program to Accept the Height of a Person & Categorize as Tall, Dwarf or Average.cs delete mode 100644 c-sharp/_Basic/C# Program to Calculate Acceleration.cs delete mode 100644 c-sharp/_Basic/C# Program to Check Whether the Entered Year is a Leap Year or Not.cs delete mode 100644 c-sharp/_Basic/C# Program to Check whether the Entered Number is Even or Odd.cs delete mode 100644 c-sharp/_Basic/C# Program to Check whether the given Integer has an Alternate Pattern.cs delete mode 100644 c-sharp/_Basic/C# Program to Compare Two Dates.cs delete mode 100644 c-sharp/_Basic/C# Program to Compute Average for the Set of Values.cs delete mode 100644 c-sharp/_Basic/C# Program to Count the Number of 1’s in the Entered Number.cs delete mode 100644 c-sharp/_Basic/C# Program to Create Sealed Class.cs delete mode 100644 c-sharp/_Basic/C# Program to Display All the Prime Numbers Between 1 to 100.cs delete mode 100644 c-sharp/_Basic/C# Program to Display Numbers in the form of Triangle.cs delete mode 100644 c-sharp/_Basic/C# Program to Display Squarefeet of a House.cs delete mode 100644 c-sharp/_Basic/C# Program to Display the ATM Transaction.cs delete mode 100644 c-sharp/_Basic/C# Program to Display the Date in Various Formats.cs delete mode 100644 c-sharp/_Basic/C# Program to Find Greatest among 2 numbers.cs delete mode 100644 c-sharp/_Basic/C# Program to Find Magnitude of Integer.cs delete mode 100644 c-sharp/_Basic/C# Program to Find a Number using Pythagoras Theorem.cs delete mode 100644 c-sharp/_Basic/C# Program to Generate Random Numbers.cs delete mode 100644 c-sharp/_Basic/C# Program to Get a Number and Display the Number with its Reverse.cs delete mode 100644 c-sharp/_Basic/C# Program to Get a Number and Display the Sum of the Digits.cs delete mode 100644 c-sharp/_Basic/C# Program to Illustrate LeftShift Operations.cs delete mode 100644 c-sharp/_Basic/C# Program to Illustrate the Use of Access Specifiers.cs delete mode 100644 c-sharp/_Basic/C# Program to Implement PhoneBook.cs delete mode 100644 c-sharp/_Basic/C# Program to Implement for-each in Inteface.cs delete mode 100644 c-sharp/_Basic/C# Program to Perform Division of Exponents of Same Base.cs delete mode 100644 c-sharp/_Basic/C# Program to Perform Unboxing Operation.cs delete mode 100644 c-sharp/_Basic/C# Program to Print a BinaryTriangle.cs delete mode 100644 c-sharp/_Basic/C# Program to Print a Diamond Using Nested Loop.cs delete mode 100644 c-sharp/_Basic/C# Program to Read a Grade & Display the Equivalent Description.cs delete mode 100644 c-sharp/_Basic/C# Program to Swap 2 Numbers.cs delete mode 100644 c-sharp/_Basic/C# Program to Swap the Contents of two Numbers using Bitwise XOR Operation.cs delete mode 100644 c-sharp/_Basic/C# Sharp program that takes a number as input and print its multiplication table.cs delete mode 100644 c-sharp/_Basic/C# Sharp program that takes an age (for example 20) as input and prints something as.cs delete mode 100644 c-sharp/_Basic/C# Sharp program that takes four numbers as input to calculate and print the average.cs delete mode 100644 c-sharp/_Basic/C# Sharp program to convert from celsius degrees to Kelvin and Fahrenheit.cs delete mode 100644 c-sharp/_Basic/C# Sharp program to print Hello and your name in a separate line.cs delete mode 100644 c-sharp/_Basic/C# Sharp program to print on screen the output of adding, subtracting, multiplying and dividing of two numbers which will be entered by the user.cs delete mode 100644 c-sharp/_Basic/C# Sharp program to print the output of multiplication of three numbers which will be entered by the user.cs delete mode 100644 c-sharp/_Basic/C# Sharp program to print the result of dividing two numbers.cs delete mode 100644 c-sharp/_Basic/C# Sharp program to print the result of the specified operations.cs delete mode 100644 c-sharp/_Basic/C# Sharp program to print the sum of two numbers.cs delete mode 100644 c-sharp/_Basic/C# Sharp program to swap two numbers.cs delete mode 100644 c-sharp/_Basic/C# Sharp program to that takes three numbers(x,y,z) as input and print the output of (x+y)úz and xúy + yúz.cs delete mode 100644 c-sharp/_Basic/C# program that takes a number as input and then displays a rectangle of 3 columns wide and 5 rows tall using that digit.cs delete mode 100644 c-sharp/_Basic/C# program to that takes a number as input and display it four times in a row (separated by blank spaces), and then four times in the next row, with no separation.cs delete mode 100644 c/_Basic/Accessing an array using pointers.c delete mode 100644 c/_Basic/C Program to Accept the Height of a Person & Categorize as Taller, Dwarf & Average.c delete mode 100644 c/_Basic/C Program to Accept two Integers and Check if they are Equal.c delete mode 100644 c/_Basic/C Program to Add two Complex Numbers.c delete mode 100644 c/_Basic/C Program to Calculate the Sum of Odd & Even Numbers.c delete mode 100644 c/_Basic/C Program to Check if a given Integer is Odd or Even.c delete mode 100644 c/_Basic/C Program to Check if a given Integer is Positive or Negative.c delete mode 100644 c/_Basic/C Program to Check whether a given Number is Armstrong.c delete mode 100644 c/_Basic/C Program to Check whether a given Number is Perfect Number.c delete mode 100644 c/_Basic/C Program to Check whether the given Number is Palindrome or not using Bitwise Operator.c delete mode 100644 c/_Basic/C Program to Compute First N Fibonacci Numbers using Command Line Arguments.c delete mode 100644 c/_Basic/C Program to Compute the Sum of Digits in a given Integer.c delete mode 100644 c/_Basic/C Program to Convert Binary Code of a Number into its Equivalent Gray’s Code using Recursion.c delete mode 100644 c/_Basic/C Program to Convert Binary Code of a Number into its Equivalent Gray’s Code without using Recursion.c delete mode 100644 c/_Basic/C Program to Convert Binary to Hexadecimal.c delete mode 100644 c/_Basic/C Program to Convert Binary to Octal.c delete mode 100644 c/_Basic/C Program to Convert Hexadecimal to Binary.c delete mode 100644 c/_Basic/C Program to Convert Numbers to Roman Numerals.c delete mode 100644 c/_Basic/C Program to Convert Octal to Binary.c delete mode 100644 c/_Basic/C Program to Convert Octal to Decimal.c delete mode 100644 c/_Basic/C Program to Convert Roman Number to Decimal Number.c delete mode 100644 c/_Basic/C Program to Convert a Decimal Number to Binary & Count the Number of 1s.c delete mode 100644 c/_Basic/C Program to Convert a Given Number of Days in terms of Years, Weeks & Days.c delete mode 100644 c/_Basic/C Program to Convert a Number Decimal System to Binary System using Recursion.c delete mode 100644 c/_Basic/C Program to Convert the given Binary Number into Decimal.c delete mode 100644 c/_Basic/C Program to Count Number of Words in a given Text Or Sentence.c delete mode 100644 c/_Basic/C Program to Count the Number of Occurrence of each Character Ignoring the Case of Alphabets & Display them.c delete mode 100644 c/_Basic/C Program to Count the Number of Unique Words.c delete mode 100644 c/_Basic/C Program to Count the Occurrences of each C Keyword using Array Structure.c delete mode 100644 c/_Basic/C Program to Display Function without using the Main Function.c delete mode 100644 c/_Basic/C Program to Display its own Source Code as its Output.c delete mode 100644 c/_Basic/C Program to Display the ATM Transaction.c delete mode 100644 c/_Basic/C Program to Display the IP Address of the System.c delete mode 100644 c/_Basic/C Program to Display the Inventory of Items in a Store.c delete mode 100644 c/_Basic/C Program to Extract Last two Digits of a given Year.c delete mode 100644 c/_Basic/C Program to Find Multiplication of two Binary Numbers.c delete mode 100644 c/_Basic/C Program to Find Product of 2 Numbers without using Recursion.c delete mode 100644 c/_Basic/C Program to Find Sum of Digits of a Number using Recursion.c delete mode 100644 c/_Basic/C Program to Find if a given Year is a Leap Year.c delete mode 100644 c/_Basic/C Program to Find the Biggest of 3 Numbers.c delete mode 100644 c/_Basic/C Program to Find the First Occurence of the any Character of String2 in string1 & also its Position.c delete mode 100644 c/_Basic/C Program to Find the Number of Integers Divisible by 5.c delete mode 100644 c/_Basic/C Program to Find the Size of a Union.c delete mode 100644 c/_Basic/C Program to Find the Sum of first 50 Natural Numbers using For Loop.c delete mode 100644 c/_Basic/C Program to Find the Sum of two Binary Numbers.c delete mode 100644 c/_Basic/C Program to Find whether a Number is Prime or Not using Recursion.c delete mode 100644 c/_Basic/C Program to Generate Fibonacci Series.c delete mode 100644 c/_Basic/C Program to Illustrate Pass by Reference.c delete mode 100644 c/_Basic/C Program to Illustrate Pass by Value.c delete mode 100644 c/_Basic/C Program to Illustrate how User Authentication is Done.c delete mode 100644 c/_Basic/C Program to Illustrate the Concept of Unions.c delete mode 100644 c/_Basic/C Program to Implements Regular Expression Matching.c delete mode 100644 c/_Basic/C Program to Input 2 Binary Strings and Print their Binary Sum.c delete mode 100644 c/_Basic/C Program to Input 3 Arguments and Operate Appropriately on the Numbers.c delete mode 100644 c/_Basic/C Program to Maintain an Inventory of items in Online Store.c delete mode 100644 c/_Basic/C Program to Multiply given Number by 4 using Bitwise Operators.c delete mode 100644 c/_Basic/C Program to Print Armstrong Number from 1 to 1000.c delete mode 100644 c/_Basic/C Program to Print Binary Equivalent of an Integer using Recursion.c delete mode 100644 c/_Basic/C Program to Print Combination of two Words of two given Strings without any Repetition.c delete mode 100644 c/_Basic/C Program to Print Diamond Pattern.c delete mode 100644 c/_Basic/C Program to Print a Semicolon without using a Semicolon anywhere in the Code.c delete mode 100644 c/_Basic/C Program to Print any Print Statement without using Semicolon.c delete mode 100644 c/_Basic/C Program to Print the Program Name and All its Arguments.c delete mode 100644 c/_Basic/C Program to Print the Words Ending with Letter S.c delete mode 100644 c/_Basic/C Program to Read Two Integers M and N & Swap their Values.c delete mode 100644 c/_Basic/C Program to Read a Grade & Display the Equivalent Description.c delete mode 100644 c/_Basic/C Program to Reverse a Given Number.c delete mode 100644 c/_Basic/C Program to Reverse a Number & Check if it is a Palindrome.c delete mode 100644 c/_Basic/C Program to Search a Word & Replace it with the Specified Word.c delete mode 100644 c/_Basic/C Program to Shutdown or Turn Off the Computer in Linux.c delete mode 100644 c/_Basic/C Program to Swap the Contents of two Numbers using Bitwise XOR Operation.c delete mode 100644 c/_Basic/C Program to Use Bitwise Operations to Count the Number of Leading Zero's in a Number x.c delete mode 100644 c/_Basic/C Program to calculate the total execution time of a program.c delete mode 100644 c/_Basic/C Program to find Product of 2 Numbers using Recursion.c delete mode 100644 c/_Basic/C Program to find Reverse of a Number using Recursion.c delete mode 100644 c/_Basic/C Program to find Sum of N Numbers using Recursion.c delete mode 100644 c/_Basic/C Program to next higher value of n with same 1's.c delete mode 100644 c/_Basic/C Program to replace first letter of every word with caps.c delete mode 100644 c/_Basic/C Program to sort string ignoring whitespaces and repeating characters only once.c delete mode 100644 c/_Basic/C program for Binary to decimal conversion.c delete mode 100644 c/_Basic/C program for decimal to octal converter.c delete mode 100644 c/_Basic/C program for hexadecimal to binary conversion.c delete mode 100644 c/_Basic/C program to Convert Decimal to Hexadecimal.c delete mode 100644 c/_Basic/C program to Convert Decimal to Octal.c delete mode 100644 c/_Basic/C program to Increase 1 to all of the given Integer Digit.c delete mode 100644 c/_Basic/C program to accept N numbers sorted in ascending order and to search for a given number using binary search..c delete mode 100644 c/_Basic/C program to accept an array of 10 elements and swap 3rd element with 4th element using pointers and display the results..c delete mode 100644 c/_Basic/C program to find the length of a string without using the built-in function also check whether it is a palindrome.c delete mode 100644 c/_Basic/C program to find the number of occurences of a given number in a list.c delete mode 100644 c/_Basic/C program to print hello world without using semicolon.c delete mode 100644 c/_Basic/C program to read an English sentence and replace lowercase characters by uppercase and vice-versa..c delete mode 100644 c/_Basic/C program to sort n given numbers using pointers.c delete mode 100644 c/_Basic/Can the size of an array be declared at runtime.c delete mode 100644 c/_Basic/Create and Use Your Own Header File in C Programming.c delete mode 100644 c/_Basic/Get Address of an array using Arrays and Pointers.c delete mode 100644 c/_Basic/Print mark-sheet of students.c delete mode 100644 c/_Basic/Reverse a string using pointers.c delete mode 100644 c/_Basic/Reverse the order of each word of the string using pointers.c delete mode 100644 c/_Basic/Show the ticking of Clock.c delete mode 100644 c/_Basic/Time functions in c.c delete mode 100644 c/_Basic/To compute the average of n given numbers using pointers.c delete mode 100644 c/_Basic/To compute the seconds from a given age using C.c delete mode 100644 c/_Basic/To find the maximum number within n given numbers using pointers.c delete mode 100644 c/_Basic/To swap the address of two variables using pointer.c delete mode 100644 c/_Basic/What happens if you free a pointer twice.c delete mode 100644 c/_Basic/Write a c program to check given string is palindrome number or not.c delete mode 100644 c/_Basic/indirection in pointer.c delete mode 100644 c/_Basic/null pointer in c.c delete mode 100644 perl/_Basics/!$v1 && $v2.pl delete mode 100644 perl/_Basics/A program that uses the pre-increment operation..pl delete mode 100644 perl/_Basics/Adding a number and a string.pl delete mode 100644 perl/_Basics/After incrementing.pl delete mode 100644 perl/_Basics/After pre-decrement.pl delete mode 100644 perl/_Basics/Arithmetic Operators in action.pl delete mode 100644 perl/_Basics/Assign value to four variables.pl delete mode 100644 perl/_Basics/Assignment Operators.pl delete mode 100644 perl/_Basics/Assignment Statements.pl delete mode 100644 perl/_Basics/Autoincrement and Autodecrement Operators and Assignment.pl delete mode 100644 perl/_Basics/Basic Math Compound Assignment Statements.pl delete mode 100644 perl/_Basics/Basic Numeric Operations.pl delete mode 100644 perl/_Basics/Bitwise And Operators in action.pl delete mode 100644 perl/_Basics/Bitwise Logical Operators.pl delete mode 100644 perl/_Basics/Bitwise Or Operators in action.pl delete mode 100644 perl/_Basics/Bitwise operator.pl delete mode 100644 perl/_Basics/Boolean and &&.pl delete mode 100644 perl/_Basics/Boolean operator.pl delete mode 100644 perl/_Basics/Built-in Perl Arithmetic Functions.pl delete mode 100644 perl/_Basics/Complex Assignment.pl delete mode 100644 perl/_Basics/Compound Assignment Operators.pl delete mode 100644 perl/_Basics/Compound operator.pl delete mode 100644 perl/_Basics/Demonstrates the difference between pre- and postincrement.pl delete mode 100644 perl/_Basics/Getting Input in Perl Scripts.pl delete mode 100644 perl/_Basics/Increment and Decrement Operations.pl delete mode 100644 perl/_Basics/Logical Word Operators.pl delete mode 100644 perl/_Basics/Logical operators are defined.pl delete mode 100644 perl/_Basics/OPERATOR PURPOSENumeric operators.pl delete mode 100644 perl/_Basics/Operating and Assigning at Once.pl delete mode 100644 perl/_Basics/Post-increment operation..pl delete mode 100644 perl/_Basics/Precedence and Associativity.pl delete mode 100644 perl/_Basics/Precedence with word operators and short-circuit operators.pl delete mode 100644 perl/_Basics/Read user input and use if statement to check it.pl delete mode 100644 perl/_Basics/Remainder and power.pl delete mode 100644 perl/_Basics/Short-circuit operators.pl delete mode 100644 perl/_Basics/Square$var.pl delete mode 100644 perl/_Basics/Subtract 1 from $var.pl delete mode 100644 perl/_Basics/The assignment operators.pl delete mode 100644 perl/_Basics/The autoincrement operator.pl delete mode 100644 perl/_Basics/To set a variable, use the = operator.pl delete mode 100644 perl/_Basics/Use parentheses wherever possible to force precedence.pl delete mode 100644 perl/_Basics/Using Assignment Operators on Scalar Variables.pl delete mode 100644 perl/_Basics/Using auto-increment operator for a string with digits.pl delete mode 100644 perl/_Basics/Using auto-increment operator for a string.pl delete mode 100644 php/_Basics/Add two numbers Program in PHP.php delete mode 100644 php/_Basics/Armstrong number Program in PHP.php delete mode 100644 php/_Basics/Even Odd number program in PHP.php delete mode 100644 php/_Basics/Factorial of a number in PHP.php delete mode 100644 php/_Basics/Fibonacci Series Program in PHP.php delete mode 100644 php/_Basics/Number Pattern Problems in PHP.php delete mode 100644 php/_Basics/PHP Program for Bubble sorting in PHP.php delete mode 100644 php/_Basics/PHP Program for finding the biggest number in an array without using any array functions.php delete mode 100644 php/_Basics/PHP Program for finding the smallest number in an array.php delete mode 100644 php/_Basics/PHP Program to find whether a year is LEAP year or not.php delete mode 100644 php/_Basics/PHP program to add the digits of a positive integer repeatedly until the result has a single digit..php delete mode 100644 php/_Basics/PHP program to check a sequence of numbers is a geometric progression or not..php delete mode 100644 php/_Basics/PHP program to check a sequence of numbers is an arithmetic progression or not..php delete mode 100644 php/_Basics/PHP program to check if a given positive integer is a power of four..php delete mode 100644 php/_Basics/PHP program to check if a given positive integer is a power of three..php delete mode 100644 php/_Basics/PHP program to check if a given positive integer is a power of two..php delete mode 100644 php/_Basics/PHP program to check if a given string is an anagram of another given string..php delete mode 100644 php/_Basics/PHP program to check if an integer is the power of another integer..php delete mode 100644 php/_Basics/PHP program to check whether a given number is an ugly number..php delete mode 100644 php/_Basics/PHP program to compute and return the square root of a given number..php delete mode 100644 php/_Basics/PHP program to compute the sum of the two reversed numbers and display the sum in reversed form..php delete mode 100644 php/_Basics/PHP program to find HCF of two numbers.php delete mode 100644 php/_Basics/PHP program to find a missing number(s) from an array.php delete mode 100644 php/_Basics/PHP program to find a single element in an array where every element appears three times except for one..php delete mode 100644 php/_Basics/PHP program to find a single number in an array that doesn't occur twice..php delete mode 100644 php/_Basics/PHP program to find factor of any number.php delete mode 100644 php/_Basics/PHP program to find majority element in an array..php delete mode 100644 php/_Basics/PHP program to find table of a number.php delete mode 100644 php/_Basics/PHP program to find the length of the last word in a string..php delete mode 100644 php/_Basics/PHP program to find the single element appears once in an array where every element appears twice except for one.php delete mode 100644 php/_Basics/PHP program to find the single number which occurs odd numbers and other numbers occur even number..php delete mode 100644 php/_Basics/PHP program to find three numbers from an array such that the sum of three consecutive numbers equal to a given number..php delete mode 100644 php/_Basics/PHP program to find three numbers from an array such that the sum of three consecutive numbers equal to zero.php delete mode 100644 php/_Basics/PHP program to find whether a number is Armstrong or not.php delete mode 100644 php/_Basics/PHP program to get the Hamming numbers upto a given numbers also check whether a given number is a Hamming number..php delete mode 100644 php/_Basics/PHP program to print Reverse of any number.php delete mode 100644 php/_Basics/PHP program to push all zeros to the end of an array..php delete mode 100644 php/_Basics/PHP program to reverse the bits of an integer (32 bits unsigned)..php delete mode 100644 php/_Basics/PHP program to reverse the digits of an integer..php delete mode 100644 php/_Basics/PHP program where you take any positive integer n, if n is even, divide it by 2 to get n (by) 2..php delete mode 100644 php/_Basics/Palindrome number Program in PHP.php delete mode 100644 php/_Basics/Pattern Problems in PHP.php delete mode 100644 php/_Basics/Print Table of aby number Program in PHP.php delete mode 100644 php/_Basics/Print an array in PHP.php delete mode 100644 php/_Basics/Print an array using foreach in php.php delete mode 100644 php/_Basics/Program to combine the array elements into a string with given delimiter..php delete mode 100644 php/_Basics/Program to create a Simple Calculator..php delete mode 100644 php/_Basics/Program to create simple Login and Logout example using sessions.php delete mode 100644 php/_Basics/Program to find number of elements in an array..php delete mode 100644 php/_Basics/Program to find prime numbers in between a Range.php delete mode 100644 php/_Basics/Program to find the product of elements in an array..php delete mode 100644 php/_Basics/Program to find the sum of elements in an array..php delete mode 100644 php/_Basics/Program to join the array elements into a string..php delete mode 100644 php/_Basics/Program to merge two arrays into a new array..php delete mode 100644 php/_Basics/Program to remove the duplicate values from an array..php delete mode 100644 php/_Basics/Program to sort elements in an array in ascending order..php delete mode 100644 php/_Basics/Program to sort elements in an array in descending order..php delete mode 100644 php/_Basics/Program to split a string into an array elements based on delimiter..php delete mode 100644 php/_Basics/Reverse String Program in PHP.php delete mode 100644 php/_Basics/Swap two number using third variable program in PHP.php delete mode 100644 php/_Basics/Swap two number without using third variable program in PHP.php delete mode 100644 python/_Basics/Accept the base and height of a triangle and compute the area.py delete mode 100644 python/_Basics/Access and print a URL's content to the console.py delete mode 100644 python/_Basics/Access environment variables.py delete mode 100644 python/_Basics/Calculate midpoints of a line.py delete mode 100644 python/_Basics/Calculate number of days between two dates.py delete mode 100644 python/_Basics/Calculate the hypotenuse of a right angled triangle.py delete mode 100644 python/_Basics/Calculate the sum of the digits in an integer.py delete mode 100644 python/_Basics/Calculate the sum of three given numbers, if the values are equal then return thrice of their sum.py delete mode 100644 python/_Basics/Check whether Python shell is executing in 32bit or 64bit mode on OS.py delete mode 100644 python/_Basics/Compute the distance between two points.py delete mode 100644 python/_Basics/Concatenate all elements in a list into a string.py delete mode 100644 python/_Basics/Convert all units of time into seconds.py delete mode 100644 python/_Basics/Convert height (in feet and inches) to centimeters.py delete mode 100644 python/_Basics/Convert pressure in kilopascals to pounds.py delete mode 100644 python/_Basics/Convert the distance in feet to inches, yards, and miles.py delete mode 100644 python/_Basics/Create a histogram from a given list of integers.py delete mode 100644 python/_Basics/Determine profiling of Python programs.py delete mode 100644 python/_Basics/Find out the number of CPUs using.py delete mode 100644 python/_Basics/Generate a list and tuple with comma-separated numbers.py delete mode 100644 python/_Basics/Get OS name, platform and release information.py delete mode 100644 python/_Basics/Get a string which is n (non-negative integer) copies of a given string.py delete mode 100644 python/_Basics/Get the difference between a given number and 17, if the number is greater than 17 return double the absolute difference.py delete mode 100644 python/_Basics/Get the path and name of the file that is currently executing.py delete mode 100644 python/_Basics/Input a filename and print the extension of that.py delete mode 100644 python/_Basics/Input an integer (n) and computes the value of n+nn+nnn.py delete mode 100644 python/_Basics/Input the radius of a circle and compute the area.py delete mode 100644 python/_Basics/List all files in a directory in Python.py delete mode 100644 python/_Basics/Measure execution time.py delete mode 100644 python/_Basics/Print first and last name in reverse order with a space between them.py delete mode 100644 python/_Basics/Program to add two numbers.py delete mode 100644 python/_Basics/Program to calculate the square root.py delete mode 100644 python/_Basics/Program to generate a random number between 0 and 9.py delete mode 100644 python/_Basics/Python Program To Display Powers of 2 Using Anonymous Function.py delete mode 100644 python/_Basics/Python Program to Add Two Matrices.py delete mode 100644 python/_Basics/Python Program to Check Armstrong Number.py delete mode 100644 python/_Basics/Python Program to Check Leap Year.py delete mode 100644 python/_Basics/Python Program to Check Prime Number.py delete mode 100644 python/_Basics/Python Program to Check Whether a String is Palindrome or Not.py delete mode 100644 python/_Basics/Python Program to Check if a Number is Odd or Even.py delete mode 100644 python/_Basics/Python Program to Convert Celsius To Fahrenheit.py delete mode 100644 python/_Basics/Python Program to Convert Decimal to Binary Using Recursion.py delete mode 100644 python/_Basics/Python Program to Convert Decimal to Binary, Octal and Hexadecimal.py delete mode 100644 python/_Basics/Python Program to Convert Kilometers to Miles.py delete mode 100644 python/_Basics/Python Program to Count the Number of Each Vowel.py delete mode 100644 python/_Basics/Python Program to Display Calendar.py delete mode 100644 python/_Basics/Python Program to Display Fibonacci Sequence Using Recursion.py delete mode 100644 python/_Basics/Python Program to Display the multiplication Table.py delete mode 100644 python/_Basics/Python Program to Find ASCII Value of Character.py delete mode 100644 python/_Basics/Python Program to Find Armstrong Number in an Interval.py delete mode 100644 python/_Basics/Python Program to Find Factorial of Number Using Recursion.py delete mode 100644 python/_Basics/Python Program to Find Factors of Number.py delete mode 100644 python/_Basics/Python Program to Find HCF or GCD.py delete mode 100644 python/_Basics/Python Program to Find Hash of File.py delete mode 100644 python/_Basics/Python Program to Find LCM.py delete mode 100644 python/_Basics/Python Program to Find Numbers Divisible by Another Number.py delete mode 100644 python/_Basics/Python Program to Find Sum of Natural Numbers Using Recursion.py delete mode 100644 python/_Basics/Python Program to Find the Factorial of a Number.py delete mode 100644 python/_Basics/Python Program to Find the Largest Among Three Numbers.py delete mode 100644 python/_Basics/Python Program to Find the Size (Resolution) of Image.py delete mode 100644 python/_Basics/Python Program to Find the Size (Resolution) of a Image.py delete mode 100644 python/_Basics/Python Program to Find the Sum of Natural Numbers.py delete mode 100644 python/_Basics/Python Program to Illustrate Different Set Operations.py delete mode 100644 python/_Basics/Python Program to Make a Simple Calculator.py delete mode 100644 python/_Basics/Python Program to Merge Mails.py delete mode 100644 python/_Basics/Python Program to Multiply Two Matrices.py delete mode 100644 python/_Basics/Python Program to Print all Prime Numbers in an Interval.py delete mode 100644 python/_Basics/Python Program to Print the Fibonacci sequence.py delete mode 100644 python/_Basics/Python Program to Remove Punctuations From a String.py delete mode 100644 python/_Basics/Python Program to Shuffle Deck of Cards.py delete mode 100644 python/_Basics/Python Program to Solve the quadratic equation.py delete mode 100644 python/_Basics/Python Program to Sort Words in Alphabetic Order.py delete mode 100644 python/_Basics/Python Program to Transpose a Matrix.py delete mode 100644 python/_Basics/Python Program to find the area of triangle.py delete mode 100644 python/_Basics/Python program that accepts a comma separated sequence of words as input and prints the unique words in sorted form (alphanumerically).py delete mode 100644 python/_Basics/Python program to count the number of characters (character frequency) in a string.py delete mode 100644 python/_Basics/Python program to count the occurrences of each word in a given sentence.py delete mode 100644 python/_Basics/Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself.py delete mode 100644 python/_Basics/Python program to get a string made of the first 2 and the last 2 chars from a given a string.py delete mode 100644 python/_Basics/Python program to get the the volume of a sphere with radius 6.py delete mode 100644 python/_Basics/Python program to swap two variables.py delete mode 100644 python/_Basics/Python script that takes input from the user and displays that input back in upper and lower cases.py delete mode 100644 python/_Basics/Return true if the two given int values are equal or their sum or difference is 5.py delete mode 100644 python/_Basics/Sort files by date.py delete mode 100644 python/_Basics/Sum of the first n positive integers.py delete mode 100644 python/_Basics/Test whether a number is within 100 of 1000 or 2000.py delete mode 100644 python/_Basics/Test whether a passed letter is a vowel or not.py delete mode 100644 ruby/_Basics/CheckForPowerOfTwo.rb delete mode 100644 ruby/_Basics/CheckIFEvenOrOdd.rb delete mode 100644 ruby/_Basics/CountSetBits.rb delete mode 100644 ruby/_Basics/UnsetRightmostSetBit.rb delete mode 100644 ruby/_Basics/auth.rb delete mode 100644 ruby/_Basics/basic_game.rb delete mode 100644 ruby/_Basics/card_deck.rb delete mode 100644 ruby/_Basics/dependency_inversion.rb delete mode 100644 ruby/_Basics/family.rb delete mode 100644 ruby/_Basics/fibers.rb delete mode 100644 ruby/_Basics/fibonacci.rb delete mode 100644 ruby/_Basics/fighter.rb delete mode 100644 ruby/_Basics/game_rankings.rb delete mode 100644 ruby/_Basics/gil.rb delete mode 100644 ruby/_Basics/inheritance robots.rb delete mode 100644 ruby/_Basics/interface_segregation.rb delete mode 100644 ruby/_Basics/liskov_substitution.rb delete mode 100644 ruby/_Basics/mixins.rb delete mode 100644 ruby/_Basics/mutex.rb delete mode 100644 ruby/_Basics/names.rb delete mode 100644 ruby/_Basics/netflix.rb delete mode 100644 ruby/_Basics/open_close.rb delete mode 100644 ruby/_Basics/order.rb delete mode 100644 ruby/_Basics/phones.rb delete mode 100644 ruby/_Basics/rails.rb delete mode 100644 ruby/_Basics/single_responsibility.rb delete mode 100644 ruby/_Basics/sites.rb delete mode 100644 ruby/_Basics/towers.rb diff --git a/c++/11_Numerical_Problems/C++ Perform to a 2D FFT Inplace Given a Complex 2D Array.cpp b/c++/11_Numerical_Problems/C++ Perform to a 2D FFT Inplace Given a Complex 2D Array.cpp deleted file mode 100644 index deba0a7..0000000 --- a/c++/11_Numerical_Problems/C++ Perform to a 2D FFT Inplace Given a Complex 2D Array.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/*This is a C++ Program to perform 2D FFT. A fast Fourier transform (FFT) is an algorithm to compute the discrete Fourier transform (DFT) and its inverse. Fourier analysis converts time (or space) to frequency and vice versa; an FFT rapidly computes such transformations by factorizing the DFT matrix into a product of sparse (mostly zero) factors.*/ - -#include -#include - -using namespace std; - -#define PI 3.14159265 -int n; - -int main(int argc, char **argv) -{ - cout << "Enter the size: "; - cin >> n; - double inputData[n][n]; - cout << "Enter the 2D elements "; - for (int i = 0; i < n; i++) - for (int j = 0; j < n; j++) - cin >> inputData[i][j]; - double realOut[n][n]; - double imagOut[n][n]; - double amplitudeOut[n][n]; - int height = n; - int width = n; - // Two outer loops iterate on output data. - for (int yWave = 0; yWave < height; yWave++) - { - for (int xWave = 0; xWave < width; xWave++) - { - // Two inner loops iterate on input data. - for (int ySpace = 0; ySpace < height; ySpace++) - { - for (int xSpace = 0; xSpace < width; xSpace++) - { - // Compute real, imag, and ampltude. - realOut[yWave][xWave] += (inputData[ySpace][xSpace] * cos( - 2 * PI * ((1.0 * xWave * xSpace / width) + (1.0 - * yWave * ySpace / height)))) / sqrt( - width * height); - imagOut[yWave][xWave] -= (inputData[ySpace][xSpace] * sin( - 2 * PI * ((1.0 * xWave * xSpace / width) + (1.0 - * yWave * ySpace / height)))) / sqrt( - width * height); - amplitudeOut[yWave][xWave] = sqrt( - realOut[yWave][xWave] * realOut[yWave][xWave] - + imagOut[yWave][xWave] - * imagOut[yWave][xWave]); - } - cout << realOut[yWave][xWave] << " + " << imagOut[yWave][xWave] - << " i (" << amplitudeOut[yWave][xWave] << ")\n"; - } - } - } -} - -/* -Enter the size: -2 -Enter the 2D elements -2 3 -4 2 - -2.5 + 0.0 i -5.5 + 0.0 i --0.5 + -1.8369701987210297E-16 i -0.5 + -3.0616169978683826E-16 i -2.5 + 0.0 i --0.5 + -3.6739403974420594E-16 i --0.5 + -1.8369701987210297E-16 i --1.5 + -1.8369701987210297E-16 i \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Check Multiplicability of Two Matrices.cpp b/c++/11_Numerical_Problems/C++ Program to Check Multiplicability of Two Matrices.cpp deleted file mode 100644 index e0ca7bf..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Check Multiplicability of Two Matrices.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main(int argc, char **argv) -{ - cout<<"Enter the dimension of the matrix:\n "; - int rowA; - cin>>rowA; - int colA; - cin>>colA; - cout<<"Enter the dimension of the other matrix:\n "; - int rowB; - cin>>rowB; - int colB; - cin>>colB; - if(colA == rowB) - { - cout<<"Matrices are multipilcable"; - } - else - { - cout<<"Matrices are not multipilcable"; - } -} - -/* -Enter the dimension of the matrix: - 2 4 -Enter the dimension of the other matrix: - 2 5 -Matrices are not multipilcable - -Enter the dimension of the matrix: - 4 5 -Enter the dimension of the other matrix: - 5 6 -Matrices are multipilcable \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Check if a Matrix is Invertible.cpp b/c++/11_Numerical_Problems/C++ Program to Check if a Matrix is Invertible.cpp deleted file mode 100644 index 516edbd..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Check if a Matrix is Invertible.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include - -using namespace std; -double d = 0; -double det(int n, double mat[10][10]); -double det(int n, double mat[10][10]) -{ - double submat[10][10]; - if (n == 2) - return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1])); - else - { - for (int c = 0; c < n; c++) - { - int subi = 0; //submatrix's i value - for (int i = 1; i < n; i++) - { - int subj = 0; - for (int j = 0; j < n; j++) - { - if (j == c) - continue; - submat[subi][subj] = mat[i][j]; - subj++; - } - subi++; - } - d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat)); - } - } - return d; -} -int main(int argc, char **argv) -{ - cout << "Enter the dimension of the matrix:\n"; - int n; - cin >> n; - double mat[10][10]; - cout << "Enter the elements of the matrix:\n"; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { - cin >> mat[j][i]; - } - } - if (det(n, mat) != 0) - { - cout << "The given matrix is invertible"; - } - else - { - cout << "The given matrix is not invertible"; - } -} - -/* -Enter the dimension of the matrix: -3 -Enter the elements of the matrix: -1 2 3 -4 5 6 -7 8 9 -The given matrix is not invertible - -Enter the dimension of the matrix: -5 -Enter the elements of the matrix: -1 2 3 4 5 -6 7 8 9 0 -0 9 8 7 6 -5 4 3 2 1 -1 3 5 7 9 -The given matrix is invertible \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Check if it is a Sparse Matrix.cpp b/c++/11_Numerical_Problems/C++ Program to Check if it is a Sparse Matrix.cpp deleted file mode 100644 index 75dada5..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Check if it is a Sparse Matrix.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include - -using namespace std; -int main(int argc, char **argv) -{ - cout<<"Enter the dimensions of the matrix: "; - int m, n; - cin>>m>>n; - double mat[m][n]; - int zeros = 0; - cout<<"Enter the elements of the matrix: "; - for(int i=0; i>mat[i][j]; - if(mat[i][j] == 0) - { - zeros++; - } - } - } - if(zeros > (m*n)/2) - { - cout<<"The matrix is a sparse matrix"; - } - else - { - cout<<"The matrix is not a sparse matrix"; - } -} - -/* -Enter the dimensions of the matrix: -3 3 - -Enter the elements of the matrix: -1 2 3 -4 5 6 -0 0 0 - -The matrix is not a sparse matrix - - -Enter the dimensions of the matrix: -3 3 - -Enter the elements of the matrix: -1 1 0 -0 0 1 -1 0 0 - -The matrix is a sparse matrix \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Compute DFT Coefficients Directly.cpp b/c++/11_Numerical_Problems/C++ Program to Compute DFT Coefficients Directly.cpp deleted file mode 100644 index 97ea26e..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Compute DFT Coefficients Directly.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/*This is a C++ Program to compute the coefficients of the DFT (Discrete Fourier Transform) directly. In mathematics, the discrete Fourier transform (DFT) converts a finite list of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids, ordered by their frequencies, that has those same sample values. It can be said to convert the sampled function from its original domain (often time or position along a line) to the frequency domain.*/ - -#include -#include - -using namespace std; - -#define PI 3.14159265 - -class DFT_Coefficient -{ -public: - double real, img; - DFT_Coefficient() - { - real = 0.0; - img = 0.0; - } -}; -int main(int argc, char **argv) -{ - int N = 10; - cout << "Calculation DFT Coefficients\n"; - cout << "Enter the coefficient of simple linear function:\n"; - cout << "ax + by = c\n"; - double a, b, c; - cin >> a >> b >> c; - double function[N]; - for (int i = 0; i < N; i++) - { - function[i] = (((a * (double) i) + (b * (double) i)) - c); - //System.out.print( " "+function[i] + " "); - } - cout << "Enter the max K value: "; - int k; - cin >> k; - double cosine[N]; - double sine[N]; - for (int i = 0; i < N; i++) - { - cosine[i] = cos((2 * i * k * PI) / N); - sine[i] = sin((2 * i * k * PI) / N); - } - DFT_Coefficient dft_val; - cout << "The coefficients are: "; - for (int i = 0; i < N; i++) - { - dft_val.real += function[i] * cosine[i]; - dft_val.img += function[i] * sine[i]; - } - cout << "(" << dft_val.real << ") - " << "(" << dft_val.img << " i)"; -} - -/* -Calculation DFT Coefficients -Enter the coefficient of simple linear funtion: -ax + by = c -1 2 3 -Enter the max K value: -2 -The coefficients are: (-15) - (-20.6457 i) - ------------------- -(program exited with code: 0) -Press return to continue \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Compute Determinant of a Matrix.cpp b/c++/11_Numerical_Problems/C++ Program to Compute Determinant of a Matrix.cpp deleted file mode 100644 index 9ed3484..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Compute Determinant of a Matrix.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -#include - -using namespace std; -double d = 0; -double det(int n, double mat[10][10]); -double det(int n, double mat[10][10]) -{ - double submat[10][10]; - if (n == 2) - return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1])); - else - { - for (int c = 0; c < n; c++) - { - int subi = 0; //submatrix's i value - for (int i = 1; i < n; i++) - { - int subj = 0; - for (int j = 0; j < n; j++) - { - if (j == c) - continue; - submat[subi][subj] = mat[i][j]; - subj++; - } - subi++; - } - d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat)); - } - } - return d; -} -int main(int argc, char **argv) -{ - cout << "Enter the dimension of the matrix:\n"; - int n; - cin >> n; - double mat[10][10]; - cout << "Enter the elements of the matrix:\n"; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { - cin >> mat[j][i]; - } - } - cout << "The determinant of the given matrix is: " << det(n, mat); - return 0; -} - -/* -Enter the dimension of the matrix: -3 -Enter the elements of the matrix: -3 5 2 -8 4 8 -2 4 7 -The determinant of the given matrix is: -164 - -Enter the dimension of the matrix: -4 -Enter the elements of the matrix: -9 5 2 5 -9 5 3 7 -6 5 4 8 -1 5 3 7 -The determinant of the given matrix is: 0 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using Naive Approach.cpp b/c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using Naive Approach.cpp deleted file mode 100644 index 809a995..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using Naive Approach.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/*This is a C++ Program to perform Discrete Fourier Transform using Naive approach. In mathematics, the discrete Fourier transform (DFT) converts a finite list of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids, ordered by their frequencies, that has those same sample values. It can be said to convert the sampled function from its original domain (often time or position along a line) to the frequency domain.*/ - -#include -#include - -using namespace std; - -#define PI 3.14159265 - -class DFT_Coefficient -{ -public: - double real, img; - DFT_Coefficient() - { - real = 0.0; - img = 0.0; - } -}; -int main(int argc, char **argv) -{ - int N = 10; - cout << "Discrete Fourier Transform using naive method\n"; - cout << "Enter the coefficient of simple linear function:\n"; - cout << "ax + by = c\n"; - double a, b, c; - cin >> a >> b >> c; - double function[N]; - for (int i = 0; i < N; i++) - { - function[i] = (((a * (double) i) + (b * (double) i)) - c); - //System.out.print( " "+function[i] + " "); - } - cout << "Enter the max K value: "; - int k; - cin >> k; - double cosine[N]; - double sine[N]; - for (int i = 0; i < N; i++) - { - cosine[i] = cos((2 * i * k * PI) / N); - sine[i] = sin((2 * i * k * PI) / N); - } - DFT_Coefficient dft_val[k]; - cout << "The coefficients are: "; - for (int j = 0; j < k; j++) - { - for (int i = 0; i < N; i++) - { - dft_val[j].real += function[i] * cosine[i]; - dft_val[j].img += function[i] * sine[i]; - } - cout << "(" << dft_val[j].real << ") - " << "(" << dft_val[j].img << " i)\n"; - } -} - -/* - -Discrete Fourier Transform using naive method -Enter the coefficient of simple linear function: -ax + by = c -1 2 3 -Enter the max K value: 20 -The coefficients are: -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) -(105) - (-1.03386e-005 i) \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using the Fast Fourier Transform Approach.cpp b/c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using the Fast Fourier Transform Approach.cpp deleted file mode 100644 index 49830c2..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Compute Discrete Fourier Transform Using the Fast Fourier Transform Approach.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/*This is a C++ Program to perform Fast Fourier Transform. A fast Fourier transform (FFT) is an algorithm to compute the discrete Fourier transform (DFT) and its inverse. Fourier analysis converts time (or space) to frequency and vice versa; an FFT rapidly computes such transformations by factorizing the DFT matrix into a product of sparse (mostly zero) factors.*/ - -#include -#include -#include -#include -using namespace std; - -unsigned int bitReverse(unsigned int x, int log2n) - -{ - int n = 0; - int mask = 0x1; - for (int i = 0; i < log2n; i++) - { - n <<= 1; - n |= (x & 1); - x >>= 1; - } - return n; -} -const double PI = 3.1415926536; -template -void fft(Iter_T a, Iter_T b, int log2n) -{ - typedef typename iterator_traits::value_type complex; - const complex J(0, 1); - int n = 1 << log2n; - for (unsigned int i = 0; i < n; ++i) - { - b[bitReverse(i, log2n)] = a[i]; - } - for (int s = 1; s <= log2n; ++s) - { - int m = 1 << s; - int m2 = m >> 1; - complex w(1, 0); - complex wm = exp(-J * (PI / m2)); - for (int j = 0; j < m2; ++j) - { - for (int k = j; k < n; k += m) - { - complex t = w * b[k + m2]; - complex u = b[k]; - b[k] = u + t; - b[k + m2] = u - t; - } - w *= wm; - } - } -} -int main(int argc, char **argv) -{ - typedef complex cx; - cx a[] = { cx(0, 0), cx(1, 1), cx(3, 3), cx(4, 4), cx(4, 4), cx(3, 3), cx( - 1, 1), cx(0, 0) - }; - cx b[8]; - fft(a, b, 3); - for (int i = 0; i < 8; ++i) - cout << b[i] << "\n"; -} - -/* - -(16,16) -(-4.82843,-11.6569) -(0,0) -(-0.343146,0.828427) -(0,0) -(0.828427,-0.343146) -(0,0) -(-11.6569,-4.82843) \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Emulate N Dice Roller.cpp b/c++/11_Numerical_Problems/C++ Program to Emulate N Dice Roller.cpp deleted file mode 100644 index bbbb506..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Emulate N Dice Roller.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -using namespace std; - -int main(int argc, char **argv) -{ - cout << "Enter the number of dice: "; - int n; - cin >> n; - cout << "The values on dice are: ( "; - for (int i = 0; i < n; i++) - cout << (rand() % 6) + 1<<" "; - cout<<")"; -} - -/* -Enter the number of dice: 5 -The values on dice are: ( 6 6 5 5 6 ) - -Enter the number of dice: 1 -The values on dice are: ( 6 ) - -Enter the number of dice: 3 -The values on dice are: ( 6 6 5 ) \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Find Basis and Dimension of a Matrix.cpp b/c++/11_Numerical_Problems/C++ Program to Find Basis and Dimension of a Matrix.cpp deleted file mode 100644 index 183fa0c..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Find Basis and Dimension of a Matrix.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include - -using namespace std; -double d = 0; -double det(int n, double mat[10][10]); -double det(int n, double mat[10][10]) -{ - double submat[10][10]; - if (n == 2) - return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1])); - else - { - for (int c = 0; c < n; c++) - { - int subi = 0; //submatrix's i value - for (int i = 1; i < n; i++) - { - int subj = 0; - for (int j = 0; j < n; j++) - { - if (j == c) - continue; - submat[subi][subj] = mat[i][j]; - subj++; - } - subi++; - } - d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat)); - } - } - return d; -} -int main(int argc, char **argv) -{ - cout << "Enter the number of vectors:\n"; - int n; - cin >> n; - double mat[10][10]; - cout << "Enter the vectors one by one:\n"; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { - cin >> mat[j][i]; - } - } - d = det(n, mat); - if (d != 0) - cout << "The vectors forms the basis of R" << n - << " as the determinant is non-zero"; - else - cout << "The vectors doesn't form the basis of R" << n - << " as the determinant is zero"; -} - -/* -Enter the number of vectors: -3 -Enter the vectors one by one: -1 2 3 -2 3 4 -3 4 5 -The vectors doesn't form the basis of R3 as the determinant is zero - -Enter the number of vectors: -4 -Enter the vectors one by one: -2 3 5 8 -1 6 2 9 -3 4 2 7 -2 5 3 9 -The vectors forms the basis of R4 as the determinant is non-zero \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Find Closest Pair of Points in an Array.cpp b/c++/11_Numerical_Problems/C++ Program to Find Closest Pair of Points in an Array.cpp deleted file mode 100644 index 5f7a36a..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Find Closest Pair of Points in an Array.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * C++ Program to Find Closest Pair of Points in an Array - */ -#include -#include -#include -#include -using namespace std; - -/* - * Point Declaration - */ -struct Point -{ - int x, y; -}; - -/* - * sort array of points according to X coordinate - */ -int compareX(const void* a, const void* b) -{ - Point *p1 = (Point *)a, *p2 = (Point *)b; - return (p1->x - p2->x); -} -/* - * sort array of points according to Y coordinate - */ -int compareY(const void* a, const void* b) -{ - Point *p1 = (Point *)a, *p2 = (Point *)b; - return (p1->y - p2->y); -} -/* - * find the distance between two points - */ -float dist(Point p1, Point p2) -{ - return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); -} -/* - * return the smallest distance between two points - */ -float small_dist(Point P[], int n) -{ - float min = FLT_MAX; - for (int i = 0; i < n; ++i) - { - for (int j = i + 1; j < n; ++j) - { - if (dist(P[i], P[j]) < min) - min = dist(P[i], P[j]); - } - } - return min; -} -/* - * find the distance beween the closest points of strip of given size - */ -float stripClosest(Point strip[], int size, float d) -{ - float min = d; - for (int i = 0; i < size; ++i) - { - for (int j = i + 1; j < size && (strip[j].y - strip[i].y) < min; ++j) - { - if (dist(strip[i],strip[j]) < min) - min = dist(strip[i], strip[j]); - } - } - return min; -} -/* - * find the smallest distance. - */ -float closestUtil(Point Px[], Point Py[], int n) -{ - if (n <= 3) - return small_dist(Px, n); - int mid = n / 2; - Point midPoint = Px[mid]; - Point Pyl[mid + 1]; - Point Pyr[n - mid - 1]; - int li = 0, ri = 0; - for (int i = 0; i < n; i++) - { - if (Py[i].x <= midPoint.x) - Pyl[li++] = Py[i]; - else - Pyr[ri++] = Py[i]; - } - float dl = closestUtil(Px, Pyl, mid); - float dr = closestUtil(Px + mid, Pyr, n-mid); - float d = min(dl, dr); - Point strip[n]; - int j = 0; - for (int i = 0; i < n; i++) - { - if (abs(Py[i].x - midPoint.x) < d) - strip[j] = Py[i], j++; - } - return min(d, stripClosest(strip, j, d)); -} -/* - * finds the smallest distance - */ -float closest(Point P[], int n) -{ - Point Px[n]; - Point Py[n]; - for (int i = 0; i < n; i++) - { - Px[i] = P[i]; - Py[i] = P[i]; - } - qsort(Px, n, sizeof(Point), compareX); - qsort(Py, n, sizeof(Point), compareY); - return closestUtil(Px, Py, n); -} - -/* - * Main - */ -int main() -{ - Point P[] = {{2, 3}, {12, 30}, {40, 50}, {5, 1}, {12, 10}, {3, 4}}; - int n = sizeof(P) / sizeof(P[0]); - cout << "The smallest distance is " << closest(P, n); - return 0; -} - -/* -The smallest distance is 1.41421 - ------------------- -(program exited with code: 1) -Press return to continue \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Find Factoial of Large Numbers.cpp b/c++/11_Numerical_Problems/C++ Program to Find Factoial of Large Numbers.cpp deleted file mode 100644 index 1eb4c2f..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Find Factoial of Large Numbers.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * C++ Program to Find Factorial of Large Numbers - */ -#include -#include -#include -#define ll long long -using namespace std; - -int fact[101][200] = {0}; - -/* - * Find Factorial of Large Numbers - * fact[i][0] is used to store the number of digits - */ -void fact_large(int n) -{ - int i; - fact[1][0] = 1; - fact[1][1] = 1; - if (fact[n][0] == 0) - { - for (i = n - 1; i > 0 ; i--) - { - if (fact[i][0] != 0) - break; - } - for ( ; i < n; i++) - { - int j = 1; - int carry = 0; - int len = fact[i][0]; - while (len--) - { - int temp = (i + 1) * fact[i][j] + carry; - fact[i + 1][j] = temp % 10; - carry = temp / 10; - j++; - } - while (carry > 0) - { - fact[i + 1][j] = carry % 10; - carry /= 10; - j++; - } - fact[i + 1][0] = j - 1; - } - } - for (i = fact[n][0]; i > 0; i--) - { - cout << fact[n][i]; - } - cout<>n; - if (n == 0) - break; - fact_large(n); - } - return 0; -} - -/* -Enter interger to compute factorial(0 to exit): 100 -93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 -Enter interger to compute factorial(0 to exit): 50 -30414093201713378043612608166064768844377641568960512000000000000 -Enter interger to compute factorial(0 to exit): 72 -61234458376886086861524070385274672740778091784697328983823014963978384987221689274204160000000000000000 -Enter interger to compute factorial(0 to exit): 0 - ------------------- -(program exited with code: 1) -Press return to continue \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Find Factoial of a Number using Dynamic Programming.cpp b/c++/11_Numerical_Problems/C++ Program to Find Factoial of a Number using Dynamic Programming.cpp deleted file mode 100644 index 546adb9..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Find Factoial of a Number using Dynamic Programming.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * C++ Program to Find Factorial of a Number using Dynamic Programming - */ -#include -#include -#include -#define ll long long -using namespace std; - -int result[1000] = {0}; -/* - * Find Factorial of a Number using Dynamic Programming - */ -ll fact_dp(int n) -{ - if (n >= 0) - { - result[0] = 1; - for (int i = 1; i <= n; ++i) - { - result[i] = i * result[i - 1]; - } - return result[n]; - } -} -/* - * Main - */ -int main() -{ - int n; - while (1) - { - cout<<"Enter interger to compute factorial(0 to exit): "; - cin>>n; - if (n == 0) - break; - cout< -#include -#include -#define ll long long -using namespace std; -/* - * Find Factorial of a Number using Iteration - */ -ll fact_iter(int n) -{ - ll result = 1; - for (int i = 1; i <= n; i++) - { - result *= i; - } - return result; -} -/* - * Main - */ -int main() -{ - int n; - while (1) - { - cout<<"Enter interger to compute factorial(0 to exit): "; - cin>>n; - if (n == 0) - break; - cout< -#include -#include -#define ll long long -using namespace std; -/* - * Find Factorial of a Number using Recursion - */ -ll fact_recur(int n) -{ - if (n == 0 || n == 1) - return 1; - else - return n * fact_recur(n - 1); -} -/* - * Main - */ -int main() -{ - int n; - while (1) - { - cout<<"Enter interger to compute factorial(0 to exit): "; - cin>>n; - if (n == 0) - break; - cout< -#include -#include -#define ll long long -using namespace std; - -ll fib[1000] = {0}; -/* - * Fibonacci Numbers using Dp - */ -ll fibo_dp(int n) -{ - fib[1] = 1; - fib[2] = 1; - if (fib[n] == 0) - { - for (int j = 3; j <= n; ++j) - { - if (fib[n] == 0) - fib[j] = fib[j - 1] + fib[j - 2]; - else - continue; - } - } - return fib[n]; -} - -/* - * Main - */ -int main() -{ - int n; - while (1) - { - cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): "; - cin>>n; - if (n == 0) - break; - cout< -#include -#include -#define ll long long -using namespace std; - -/* - * Iterative function to find Fibonacci Numbers - */ -ll fibo_iter(int n) -{ - int previous = 1; - int current = 1; - int next = 1; - for (int i = 3; i <= n; ++i) - { - next = current + previous; - previous = current; - current = next; - } - return next; -} -/* - * Main - */ -int main() -{ - int n; - while (1) - { - cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): "; - cin>>n; - if (n == 0) - break; - cout< -#include -#include -#define ll long long -using namespace std; - -/* - * function to multiply two matrices - */ -void multiply(ll F[2][2], ll M[2][2]) -{ - ll x = F[0][0] * M[0][0] + F[0][1] * M[1][0]; - ll y = F[0][0] * M[0][1] + F[0][1] * M[1][1]; - ll z = F[1][0] * M[0][0] + F[1][1] * M[1][0]; - ll w = F[1][0] * M[0][1] + F[1][1] * M[1][1]; - F[0][0] = x; - F[0][1] = y; - F[1][0] = z; - F[1][1] = w; -} - -/* - * function to calculate power of a matrix - */ -void power(ll F[2][2], int n) -{ - if (n == 0 || n == 1) - return; - ll M[2][2] = {{1,1},{1,0}}; - power(F, n / 2); - multiply(F, F); - if (n % 2 != 0) - multiply(F, M); -} - -/* - * function that returns nth Fibonacci number - */ -ll fibo_matrix(ll n) -{ - ll F[2][2] = {{1,1},{1,0}}; - if (n == 0) - return 0; - power(F, n - 1); - return F[0][0]; -} -/* - * Main - */ -int main() -{ - int n; - while (1) - { - cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): "; - cin>>n; - if (n == 0) - break; - cout< -#include -#include -#define ll long long -using namespace std; - -/* - * Recursive function to find Fibonnaci Numbers - */ -ll fibo_recur(int n) -{ - if (n == 1 || n == 2) - return 1; - else - return fibo_recur(n - 1) + fibo_recur(n - 2);; -} -/* - * Main - */ -int main() -{ - int n; - while (1) - { - cout<<"Enter the integer n to find nth fibonnaci no.(0 to exit): "; - cin>>n; - if (n == 0) - break; - cout< -#include -#include - -using namespace std; -int gcd(int u, int v) -{ - return (v != 0) ? gcd(v, u % v) : u; -} - -int main(void) -{ - int num1, num2, result; - cout << "Enter two numbers to find GCD using Euclidean algorithm: "; - cin >> num1 >> num2; - result = gcd(num1, num2); - if (gcd) - cout << "\nThe GCD of " << num1 << " and " << num2 << " is: " << result - << endl; - else - cout << "\nInvalid input!!!\n"; - return 0; -} - -/* -Enter two numbers to find GCD using Euclidean algorithm: 12 30 -The GCD of 12 and 30 is: 6 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Find Inverse of a Matrix.cpp b/c++/11_Numerical_Problems/C++ Program to Find Inverse of a Matrix.cpp deleted file mode 100644 index 35a02c6..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Find Inverse of a Matrix.cpp +++ /dev/null @@ -1,565 +0,0 @@ -#if !defined(MATRIX_H) -#define MATRIX_H -#include -#include -#include -#include -#include -class CMatrix -{ -private: - int m_rows; - int m_cols; - char m_name[128]; - CMatrix(); -public: - double **m_pData; - CMatrix(const char *name, int rows, int cols) : - m_rows(rows), m_cols(cols) - { - strcpy(m_name, name); - m_pData = new double*[m_rows]; - for (int i = 0; i < m_rows; i++) - m_pData[i] = new double[m_cols]; - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - m_pData[i][j] = 0.0; - } - } - } - CMatrix(const CMatrix &other) - { - strcpy(m_name, other.m_name); - m_rows = other.m_rows; - m_cols = other.m_cols; - m_pData = new double*[m_rows]; - for (int i = 0; i < m_rows; i++) - m_pData[i] = new double[m_cols]; - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - m_pData[i][j] = other.m_pData[i][j]; - } - } - } - ~CMatrix() - { - for (int i = 0; i < m_rows; i++) - delete[] m_pData[i]; - delete[] m_pData; - m_rows = m_cols = 0; - } - void SetName(const char *name) - { - strcpy(m_name, name); - } - const char* GetName() const - { - return m_name; - } - void GetInput() - { - std::cin >> *this; - } - void FillSimulatedInput() - { - static int factor1 = 1, factor2 = 2; - std::cout << "\n\nEnter Input For Matrix : " << m_name << " Rows: " - << m_rows << " Cols: " << m_cols << "\n"; - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - std::cout << "Input For Row: " << i + 1 << " Col: " << j - + 1 << " = "; - int data = ((i + 1) * factor1) + (j + 1) * factor2; - m_pData[i][j] = data / 10.2; - std::cout << m_pData[i][j] << "\n"; - factor1 += (rand() % 4); - factor2 += (rand() % 3); - } - std::cout << "\n"; - } - std::cout << "\n"; - } - double Determinant() - { - double det = 0; - double **pd = m_pData; - switch (m_rows) - { - case 2: - { - det = pd[0][0] * pd[1][1] - pd[0][1] * pd[1][0]; - return det; - } - break; - case 3: - { - /*** - a b c - d e f - g h i - - a b c a b c - d e f d e f - g h i g h i - - // det (A) = aei + bfg + cdh - afh - bdi - ceg. - ***/ - double a = pd[0][0]; - double b = pd[0][1]; - double c = pd[0][2]; - double d = pd[1][0]; - double e = pd[1][1]; - double f = pd[1][2]; - double g = pd[2][0]; - double h = pd[2][1]; - double i = pd[2][2]; - double det = (a * e * i + b * f * g + c * d * h); - det = det - a * f * h; - det = det - b * d * i; - det = det - c * e * g; - return det; - } - break; - case 4: - { - CMatrix *temp[4]; - for (int i = 0; i < 4; i++) - temp[i] = new CMatrix("", 3, 3); - for (int k = 0; k < 4; k++) - { - for (int i = 1; i < 4; i++) - { - int j1 = 0; - for (int j = 0; j < 4; j++) - { - if (k == j) - continue; - temp[k]->m_pData[i - 1][j1++] - = this->m_pData[i][j]; - } - } - } - double det = this->m_pData[0][0] * temp[0]->Determinant() - - this->m_pData[0][1] * temp[1]->Determinant() - + this->m_pData[0][2] * temp[2]->Determinant() - - this->m_pData[0][3] * temp[3]->Determinant(); - return det; - } - break; - case 5: - { - CMatrix *temp[5]; - for (int i = 0; i < 5; i++) - temp[i] = new CMatrix("", 4, 4); - for (int k = 0; k < 5; k++) - { - for (int i = 1; i < 5; i++) - { - int j1 = 0; - for (int j = 0; j < 5; j++) - { - if (k == j) - continue; - temp[k]->m_pData[i - 1][j1++] - = this->m_pData[i][j]; - } - } - } - double det = this->m_pData[0][0] * temp[0]->Determinant() - - this->m_pData[0][1] * temp[1]->Determinant() - + this->m_pData[0][2] * temp[2]->Determinant() - - this->m_pData[0][3] * temp[3]->Determinant() - + this->m_pData[0][4] * temp[4]->Determinant(); - return det; - } - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - default: - { - int DIM = m_rows; - CMatrix **temp = new CMatrix*[DIM]; - for (int i = 0; i < DIM; i++) - temp[i] = new CMatrix("", DIM - 1, DIM - 1); - for (int k = 0; k < DIM; k++) - { - for (int i = 1; i < DIM; i++) - { - int j1 = 0; - for (int j = 0; j < DIM; j++) - { - if (k == j) - continue; - temp[k]->m_pData[i - 1][j1++] - = this->m_pData[i][j]; - } - } - } - double det = 0; - for (int k = 0; k < DIM; k++) - { - if ((k % 2) == 0) - det = det + (this->m_pData[0][k] - * temp[k]->Determinant()); - else - det = det - (this->m_pData[0][k] - * temp[k]->Determinant()); - } - for (int i = 0; i < DIM; i++) - delete temp[i]; - delete[] temp; - return det; - } - break; - } - } - CMatrix& operator =(const CMatrix &other) - { - if (this->m_rows != other.m_rows || this->m_cols != other.m_cols) - { - std::cout - << "WARNING: Assignment is taking place with by changing the number of rows and columns of the matrix"; - } - for (int i = 0; i < m_rows; i++) - delete[] m_pData[i]; - delete[] m_pData; - m_rows = m_cols = 0; - strcpy(m_name, other.m_name); - m_rows = other.m_rows; - m_cols = other.m_cols; - m_pData = new double*[m_rows]; - for (int i = 0; i < m_rows; i++) - m_pData[i] = new double[m_cols]; - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - m_pData[i][j] = other.m_pData[i][j]; - } - } - return *this; - } - CMatrix CoFactor() - { - CMatrix cofactor("COF", m_rows, m_cols); - if (m_rows != m_cols) - return cofactor; - if (m_rows < 2) - return cofactor; - else if (m_rows == 2) - { - cofactor.m_pData[0][0] = m_pData[1][1]; - cofactor.m_pData[0][1] = -m_pData[1][0]; - cofactor.m_pData[1][0] = -m_pData[0][1]; - cofactor.m_pData[1][1] = m_pData[0][0]; - return cofactor; - } - else if (m_rows >= 3) - { - int DIM = m_rows; - CMatrix ***temp = new CMatrix**[DIM]; - for (int i = 0; i < DIM; i++) - temp[i] = new CMatrix*[DIM]; - for (int i = 0; i < DIM; i++) - for (int j = 0; j < DIM; j++) - temp[i][j] = new CMatrix("", DIM - 1, DIM - 1); - for (int k1 = 0; k1 < DIM; k1++) - { - for (int k2 = 0; k2 < DIM; k2++) - { - int i1 = 0; - for (int i = 0; i < DIM; i++) - { - int j1 = 0; - for (int j = 0; j < DIM; j++) - { - if (k1 == i || k2 == j) - continue; - temp[k1][k2]->m_pData[i1][j1++] - = this->m_pData[i][j]; - } - if (k1 != i) - i1++; - } - } - } - bool flagPositive = true; - for (int k1 = 0; k1 < DIM; k1++) - { - flagPositive = ((k1 % 2) == 0); - for (int k2 = 0; k2 < DIM; k2++) - { - if (flagPositive == true) - { - cofactor.m_pData[k1][k2] - = temp[k1][k2]->Determinant(); - flagPositive = false; - } - else - { - cofactor.m_pData[k1][k2] - = -temp[k1][k2]->Determinant(); - flagPositive = true; - } - } - } - for (int i = 0; i < DIM; i++) - for (int j = 0; j < DIM; j++) - delete temp[i][j]; - for (int i = 0; i < DIM; i++) - delete[] temp[i]; - delete[] temp; - } - return cofactor; - } - CMatrix Adjoint() - { - CMatrix cofactor("COF", m_rows, m_cols); - CMatrix adj("ADJ", m_rows, m_cols); - if (m_rows != m_cols) - return adj; - cofactor = this->CoFactor(); - // adjoint is transpose of a cofactor of a matrix - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - adj.m_pData[j][i] = cofactor.m_pData[i][j]; - } - } - return adj; - } - CMatrix Transpose() - { - CMatrix trans("TR", m_cols, m_rows); - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - trans.m_pData[j][i] = m_pData[i][j]; - } - } - return trans; - } - CMatrix Inverse() - { - CMatrix cofactor("COF", m_rows, m_cols); - CMatrix inv("INV", m_rows, m_cols); - if (m_rows != m_cols) - return inv; - // to find out Determinant - double det = Determinant(); - cofactor = this->CoFactor(); - // inv = transpose of cofactor / Determinant - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - inv.m_pData[j][i] = cofactor.m_pData[i][j] / det; - } - } - return inv; - } - CMatrix operator +(const CMatrix &other) - { - if (this->m_rows != other.m_rows || this->m_cols != other.m_cols) - { - std::cout - << "Addition could not take place because number of rows and columns are different between the two matrices"; - return *this; - } - CMatrix result("", m_rows, m_cols); - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - result.m_pData[i][j] = this->m_pData[i][j] - + other.m_pData[i][j]; - } - } - return result; - } - CMatrix operator -(const CMatrix &other) - { - if (this->m_rows != other.m_rows || this->m_cols != other.m_cols) - { - std::cout - << "Subtraction could not take place because number of rows and columns are different between the two matrices"; - return *this; - } - CMatrix result("", m_rows, m_cols); - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - result.m_pData[i][j] = this->m_pData[i][j] - - other.m_pData[i][j]; - } - } - return result; - } - CMatrix operator *(const CMatrix &other) - { - if (this->m_cols != other.m_rows) - { - std::cout - << "Multiplication could not take place because number of columns of 1st Matrix and number of rows in 2nd Matrix are different"; - return *this; - } - CMatrix result("", this->m_rows, other.m_cols); - for (int i = 0; i < this->m_rows; i++) - { - for (int j = 0; j < other.m_cols; j++) - { - for (int k = 0; k < this->m_cols; k++) - { - result.m_pData[i][j] += this->m_pData[i][k] - * other.m_pData[k][j]; - } - } - } - return result; - } - bool operator ==(const CMatrix &other) - { - if (this->m_rows != other.m_rows || this->m_cols != other.m_cols) - { - std::cout - << "Comparision could not take place because number of rows and columns are different between the two matrices"; - return false; - } - CMatrix result("", m_rows, m_cols); - bool bEqual = true; - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - if (this->m_pData[i][j] != other.m_pData[i][j]) - bEqual = false; - } - } - return bEqual; - } - friend std::istream& operator >>(std::istream &is, CMatrix &m); - friend std::ostream& operator <<(std::ostream &os, const CMatrix &m); -}; -std::istream& operator >>(std::istream &is, CMatrix &m) -{ - std::cout << "\n\nEnter Input For Matrix : " << m.m_name << " Rows: " - << m.m_rows << " Cols: " << m.m_cols << "\n"; - for (int i = 0; i < m.m_rows; i++) - { - for (int j = 0; j < m.m_cols; j++) - { - std::cout << "Input For Row: " << i + 1 << " Col: " << j + 1 - << " = "; - is >> m.m_pData[i][j]; - } - std::cout << "\n"; - } - std::cout << "\n"; - return is; -} -std::ostream& operator <<(std::ostream &os, const CMatrix &m) -{ - os << "\n\nMatrix : " << m.m_name << " Rows: " << m.m_rows << " Cols: " - << m.m_cols << "\n\n"; - for (int i = 0; i < m.m_rows; i++) - { - os << " | "; - for (int j = 0; j < m.m_cols; j++) - { - char buf[32]; - double data = m.m_pData[i][j]; - if (m.m_pData[i][j] > -0.00001 && m.m_pData[i][j] < 0.00001) - data = 0; - sprintf(buf, "%10.2lf ", data); - os << buf; - } - os << "|\n"; - } - os << "\n\n"; - return os; -} -#endif -int main() -{ - CMatrix a("A", 5, 5); - //std::cin >> a; - a.FillSimulatedInput(); - CMatrix aadj = a.Inverse(); - std::cout << a; - std::cout << aadj; - CMatrix unit = (a * aadj); - unit.SetName("A * A-Inv"); - std::cout << unit; -} - -/* - -Enter Input For Matrix : -A Rows: 5 -Cols: 5 -Input For Row: 1 Col: 1 = 0.294118 -Input For Row: 1 Col: 2 = 0.980392 -Input For Row: 1 Col: 3 = 1.86275 -Input For Row: 1 Col: 4 = 2.84314 -Input For Row: 1 Col: 5 = 3.62745 - -Input For Row: 2 Col: 1 = 2.54902 -Input For Row: 2 Col: 2 = 3.92157 -Input For Row: 2 Col: 3 = 5.09804 -Input For Row: 2 Col: 4 = 7.05882 -Input For Row: 2 Col: 5 = 9.80392 - -Input For Row: 3 Col: 1 = 6.66667 -Input For Row: 3 Col: 2 = 8.92157 -Input For Row: 3 Col: 3 = 10.8824 -Input For Row: 3 Col: 4 = 12.6471 -Input For Row: 3 Col: 5 = 15.3922 - -Input For Row: 4 Col: 1 = 12.0588 -Input For Row: 4 Col: 2 = 15.098 -Input For Row: 4 Col: 3 = 18.1373 -Input For Row: 4 Col: 4 = 20.7843 -Input For Row: 4 Col: 5 = 24.4118 - -Input For Row: 5 Col: 1 = 21.1765 -Input For Row: 5 Col: 2 = 24.7059 -Input For Row: 5 Col: 3 = 27.7451 -Input For Row: 5 Col: 4 = 31.0784 -Input For Row: 5 Col: 5 = 34.3137 - -Matrix : A Rows: 5 Cols: 5 - - | 0.29 0.98 1.86 2.84 3.63 | - | 2.55 3.92 5.10 7.06 9.80 | - | 6.67 8.92 10.88 12.65 15.39 | - | 12.06 15.10 18.14 20.78 24.41 | - | 21.18 24.71 27.75 31.08 34.31 | - -Matrix : INV Rows: 5 Cols: 5 - - | -0.93 0.80 -3.74 2.86 -0.49 | - | 0.37 -0.32 5.35 -4.91 1.14 | - | -0.78 -0.93 -1.46 2.96 -1.10 | - | 2.37 -0.10 0.25 -1.65 0.84 | - | -1.21 0.57 -0.58 0.87 -0.36 | - -Matrix : A * A-Inv Rows: 5 Cols: 5 - - | 1.00 0.00 0.00 0.00 0.00 | - | 0.00 1.00 0.00 0.00 0.00 | - | 0.00 0.00 1.00 0.00 0.00 | - | 0.00 0.00 0.00 1.00 0.00 | - | 0.00 0.00 0.00 0.00 1.00 | \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Find Path Between Two Nodes in a Graph.cpp b/c++/11_Numerical_Problems/C++ Program to Find Path Between Two Nodes in a Graph.cpp deleted file mode 100644 index 9808b2a..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Find Path Between Two Nodes in a Graph.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include - -using namespace std; - -// This class represents a directed graph using adjacency list representation -class Graph -{ - int V; // No. of vertices - list *adj; // Pointer to an array containing adjacency lists -public: - Graph(int V); // Constructor - void addEdge(int v, int w); // function to add an edge to graph - bool isReachable(int s, int d); // returns true if there is a path from s to d -}; - -Graph::Graph(int V) -{ - this->V = V; - adj = new list [V]; -} - -void Graph::addEdge(int v, int w) -{ - adj[v].push_back(w); // Add w to v’s list. -} - -// A BFS based function to check whether d is reachable from s. -bool Graph::isReachable(int s, int d) -{ - // Base case - if (s == d) - return true; - // Mark all the vertices as not visited - bool *visited = new bool[V]; - for (int i = 0; i < V; i++) - visited[i] = false; - // Create a queue for BFS - list queue; - // Mark the current node as visited and enqueue it - visited[s] = true; - queue.push_back(s); - // it will be used to get all adjacent vertices of a vertex - list::iterator i; - while (!queue.empty()) - { - // Dequeue a vertex from queue and print it - s = queue.front(); - queue.pop_front(); - // Get all adjacent vertices of the dequeued vertex s - // If a adjacent has not been visited, then mark it visited - // and enqueue it - for (i = adj[s].begin(); i != adj[s].end(); ++i) - { - // If this adjacent node is the destination node, then return true - if (*i == d) - return true; - // Else, continue to do BFS - if (!visited[*i]) - { - visited[*i] = true; - queue.push_back(*i); - } - } - } - return false; -} - -// Driver program to test methods of graph class -int main() -{ - // Create a graph given in the above diagram - Graph g(4); - g.addEdge(0, 1); - g.addEdge(0, 2); - g.addEdge(1, 2); - g.addEdge(2, 0); - g.addEdge(2, 3); - g.addEdge(3, 3); - cout << "Enter the source and destination vertices: (0-3)"; - int u, v; - cin >> u >> v; - if (g.isReachable(u, v)) - cout << "\nThere is a path from " << u << " to " << v; - else - cout << "\nThere is no path from " << u << " to " << v; - int temp; - temp = u; - u = v; - v = temp; - if (g.isReachable(u, v)) - cout << "\nThere is a path from " << u << " to " << v; - else - cout << "\nThere is no path from " << u << " to " << v; - return 0; -} - -/* -Enter the source and destination vertices: (0-3) -1 3 - -There is a path from 1 to 3 -There is no path from 3 to 1 - -Enter the source and destination vertices: (0-3) -2 3 - -There is a path from 2 to 3 -There is no path from 3 to 2 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Find the GCD and LCM of n Numbers.cpp b/c++/11_Numerical_Problems/C++ Program to Find the GCD and LCM of n Numbers.cpp deleted file mode 100644 index 6d40571..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Find the GCD and LCM of n Numbers.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include - -using namespace std; - -int gcd(int x, int y) -{ - int r = 0, a, b; - a = (x > y) ? x : y; // a is greater number - b = (x < y) ? x : y; // b is smaller number - r = b; - while (a % b != 0) - { - r = a % b; - a = b; - b = r; - } - return r; -} - -int lcm(int x, int y) -{ - int a; - a = (x > y) ? x : y; // a is greater number - while (true) - { - if (a % x == 0 && a % y == 0) - return a; - ++a; - } -} - -int main(int argc, char **argv) -{ - cout << "Enter the two numbers: "; - int x, y; - cin >> x >> y; - cout << "The GCD of two numbers is: " << gcd(x, y) << endl; - ; - cout << "The LCM of two numbers is: " << lcm(x, y) << endl; - ; - return 0; -} - -/* -Enter the two numbers: -5 -8 -The GCD of two numbers is: 1 -The LCM of two numbers is: 40 - -Enter the two numbers: -100 -50 -The GCD of two numbers is: 50 -The LCM of two numbers is: 100 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Generate N Number of Passwords of Length M Each.cpp b/c++/11_Numerical_Problems/C++ Program to Generate N Number of Passwords of Length M Each.cpp deleted file mode 100644 index 7dafe6f..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Generate N Number of Passwords of Length M Each.cpp +++ /dev/null @@ -1,179 +0,0 @@ -#include -#include -#include - -using namespace std; - -void permute(int *a, int k, int size) -{ - if (k == size) - { - for (int i = 0; i < size; i++) - { - cout << *(a + i); - } - cout << endl; - } - else - { - for (int i = k; i < size; i++) - { - int temp = a[k]; - a[k] = a[i]; - a[i] = temp; - permute(a, k + 1, size); - temp = a[k]; - a[k] = a[i]; - a[i] = temp; - } - } -} -int main(int argc, char **argv) -{ - cout << "Enter the length of the password: "; - int m; - cin >> m; - int a[m]; - for (int i = 0; i < m; i++) - { - /*generates random number between 1 and 10*/ - a[i] = rand() % 10; - } - for (int i = 0; i < m; i++) - { - cout << a[i] << ", "; - } - cout << "The Passwords are: "; - permute(a, 0, m); -} - -/* -Enter the length of the password: 3 -1, 7, 4, The Passwords are: 174 -147 -714 -741 -471 -417 - -Enter the length of the password: 5 -1, 7, 4, 0, 9, The Passwords are: 17409 -17490 -17049 -17094 -17904 -17940 -14709 -14790 -14079 -14097 -14907 -14970 -10479 -10497 -10749 -10794 -10974 -10947 -19407 -19470 -19047 -19074 -19704 -19740 -71409 -71490 -71049 -71094 -71904 -71940 -74109 -74190 -74019 -74091 -74901 -74910 -70419 -70491 -70149 -70194 -70914 -70941 -79401 -79410 -79041 -79014 -79104 -79140 -47109 -47190 -47019 -47091 -47901 -47910 -41709 -41790 -41079 -41097 -41907 -41970 -40179 -40197 -40719 -40791 -40971 -40917 -49107 -49170 -49017 -49071 -49701 -49710 -07419 -07491 -07149 -07194 -07914 -07941 -04719 -04791 -04179 -04197 -04917 -04971 -01479 -01497 -01749 -01794 -01974 -01947 -09417 -09471 -09147 -09174 -09714 -09741 -97401 -97410 -97041 -97014 -97104 -97140 -94701 -94710 -94071 -94017 -94107 -94170 -90471 -90417 -90741 -90714 -90174 -90147 -91407 -91470 -91047 -91074 -91704 -91740 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Generate Prime Numbers Between a Given Range Using the Sieve of Sundaram.cpp b/c++/11_Numerical_Problems/C++ Program to Generate Prime Numbers Between a Given Range Using the Sieve of Sundaram.cpp deleted file mode 100644 index b1658ac..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Generate Prime Numbers Between a Given Range Using the Sieve of Sundaram.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include - -using namespace std; - -int main() -{ - cout << "Welcome to the Sieve of Sundaram\n" << endl; - int arraySize; - int numberPrimes = 0; - cout << "Input a positive integer to find all the prime numbers up to and " - << "\nincluding that number: "; - cin >> arraySize; - int n = arraySize / 2; - /* array to start off with that will eventually get - all the composite numbers removed and the remaining - ones output to the screen */ - int isPrime[arraySize + 1]; - for (int i = 0; i < n; ++i) - { - isPrime[i] = i; - } - for (int i = 1; i < n; i++) - { - for (int j = i; j <= (n - i) / (2 * i + 1); j++) - { - isPrime[i + j + 2 * i * j] = 0;/*From this list, remove all - numbers of the form i + j + 2ij */ - } - } - int TheseArePrime = 0; - if (arraySize > 2) - { - isPrime[TheseArePrime++] = 2;/*this IF statement adds 2 to the output */ - } - for (int i = 1; i < n; i++) - { - if (isPrime[i] != 0) - { - isPrime[TheseArePrime++] = i * 2 + 1; - } - } - int size = sizeof isPrime / sizeof(int);//total size of array/size of array data type - for (int x = 0; x <= size; x++) - { - if (isPrime[x] != 0) - { - cout << isPrime[x] << "\t";//outputs all prime numbers found - numberPrimes++;// the counter of the number of primes found - } - else - { - break; - } - } - cout << "\nNumber of Primes: " << numberPrimes << endl; - return 0; -} - -/* -Welcome to the Sieve of Sundaram - -Input a positive integer to find all the prime numbers up to and -including that number: 10 -2 3 5 7 -Number of Primes: 4 - -Welcome to the Sieve of Sundaram - -Input a positive integer to find all the prime numbers up to and -including that number: 100 -2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 -Number of Primes: 25 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Generate Random Hexadecimal Bytes.cpp b/c++/11_Numerical_Problems/C++ Program to Generate Random Hexadecimal Bytes.cpp deleted file mode 100644 index 3e5d8fe..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Generate Random Hexadecimal Bytes.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main(int argc, char **argv) -{ - int val = rand(); - char Hex[33]; - itoa(val, Hex, 16); - cout<< "Random Decimal Byte:" << val; - cout << "\nEquivalent Hex Byte: " << Hex; -} - -/* -Random Decimal Byte:41 -Equivalent Hex Byte: 29 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Middle Square Method.cpp b/c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Middle Square Method.cpp deleted file mode 100644 index 7c86fb8..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Middle Square Method.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/*This is a C++ Program to generate random numbers using Middle Square method. In mathematics, the middle-square method is a method of generating pseudorandom numbers. In practice it is not a good method, since its period is usually very short and it has some severe weaknesses, such as the output sequence almost always converging to zero.*/ - -#include -#include -#include - -using namespace std; - -int a[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 }; -int middleSquareNumber(int numb, int dig) -{ - int sqn = numb * numb, next_num = 0; - int trim = (dig / 2); - sqn = sqn / a[trim]; - for (int i = 0; i < dig; i++) - { - next_num += (sqn % (a[trim])) * (a[i]); - sqn = sqn / 10; - } - return next_num; -} - -int main(int argc, char **argv) -{ - cout << "Enter the #-digit random numbers you want: "; - int n; - cin >> n; - int start = 1, end = 1; - start = a[n - 1]; - end = a[n]; - int number = ((rand()) % (end - start)) + start; - cout << "The random numbers are:\n" << number << ", "; - for (int i = 1; i < n; i++) - { - number = middleSquareNumber(number, n); - cout << number << ", "; - } - cout << "..."; -} - -/* - -Enter the #-digit random numbers you want: 5 -The random numbers are: -10041, 16426, 796264, -276041, -115546, ... \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Multiply with Carry Method.cpp b/c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Multiply with Carry Method.cpp deleted file mode 100644 index e343a7f..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Multiply with Carry Method.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/*This is a C++ Program to generate random numbers using Multiply with Carry method. In computer science, multiply-with-carry (MWC) is a method invented by George Marsaglia for generating sequences of random integers based on an initial set from two to many thousands of randomly chosen seed values. The main advantages of the MWC method are that it invokes simple computer integer arithmetic and leads to very fast generation of sequences of random numbers with immense periods, ranging from around 260 to 22000000.*/ - -#include -#include -#include - -using namespace std; - -int main(int argc, char **argv) -{ - int max_Sequence_Elements = 10; - int base_b = 2000; - int multiplier_a = rand() % base_b; - int r = 1; - int c[max_Sequence_Elements]; - int x[max_Sequence_Elements]; - c[0] = rand() % multiplier_a; - x[0] = rand() % base_b; - cout << "The random number sequence is: " << x[0]; - //generating sequence - for (int i = 1; i < max_Sequence_Elements; i++) - { - x[i] = (multiplier_a * x[i - r] + c[i - 1]) % base_b; - c[i] = (multiplier_a * x[i - r] + c[i - 1]) / base_b; - cout << " " << x[i]; - } - cout << "..."; -} - -/* -The random number sequence is: 334 1711 157 472 1355 1564 151 223 1146 990... \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Probability Distribution Function.cpp b/c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Probability Distribution Function.cpp deleted file mode 100644 index c26e7ba..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Generate Random Numbers Using Probability Distribution Function.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*This is a C++ Program to generate random numbers using Probability Distribution Function. Probability distribution is based on probability density function. a probability density function (pdf), or density of a continuous random variable, is a function that describes the relative likelihood for this random variable to take on a given value. The probability of the random variable falling within a particular range of values is given by the integral of this variable’s density over that range—that is, it is given by the area under the density function but above the horizontal axis and between the lowest and greatest values of the range.*/ - -//pdf(x) = 1 if x>360 -// = 0 if x<0 -// = x/360 otherwise -#include -#include -#include - -using namespace std; - -//This is a sample program to generate a random numbers based on probability desity function of spiner -//pdf(x) = 1 if x>360 -// = 0 if x<0 -// = x/360 otherwise -int N = 10; -int main(int argc, char **argv) -{ - int p = 0; - for (int i = 0; i < N; i++) - { - p = rand() % 400; - if (p > 360) - cout << 0 << " "; - else if (p < 0) - cout << 0 << " "; - else - cout << p * 0.1 / 360 << " "; - } - cout << "..."; -} - -/* -0.0113889 0.0186111 0.0927778 0.0277778 0 0.0344444 0.0772222 0.0438889 0.045 0.0177778 ... \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Generate Randomized Sequence of Given Range of Numbers.cpp b/c++/11_Numerical_Problems/C++ Program to Generate Randomized Sequence of Given Range of Numbers.cpp deleted file mode 100644 index 8d9a98c..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Generate Randomized Sequence of Given Range of Numbers.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include - -const int LOW = 1; -const int HIGH = 32000; - -using namespace std; - -int main() -{ - int randomNumber; - time_t seconds; - time(&seconds); - srand((unsigned int) seconds); - for (int i = 0; i < 10; i++) - { - randomNumber = rand() % (HIGH - LOW + 1) + LOW; - cout << randomNumber << " "; - } - cout << "..."; - return 0; -} - -/* -312 7423 23444 16008 31816 1823 29315 17424 11753 18384 ... \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement Booth’s Multiplication Algorithm for Multiplication of 2 signed Numbers.cpp b/c++/11_Numerical_Problems/C++ Program to Implement Booth’s Multiplication Algorithm for Multiplication of 2 signed Numbers.cpp deleted file mode 100644 index a80bf8a..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement Booth’s Multiplication Algorithm for Multiplication of 2 signed Numbers.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/*This is a C++ Program to multiply two signed numbers using booth’s algorithm. Booth’s multiplication algorithm is a multiplication algorithm that multiplies two signed binary numbers in two’s complement notation. Booth used desk calculators that were faster at shifting than adding and created the algorithm to increase their speed. Booth’s algorithm is of interest in the study of computer architecture.*/ - -#include -#include - -using namespace std; - -void add(int a[], int x[], int qrn); -void complement(int a[], int n) -{ - int i; - int x[8] = { NULL }; - x[0] = 1; - for (i = 0; i < n; i++) - { - a[i] = (a[i] + 1) % 2; - } - add(a, x, n); -} - -void add(int ac[], int x[], int qrn) -{ - int i, c = 0; - for (i = 0; i < qrn; i++) - { - ac[i] = ac[i] + x[i] + c; - if (ac[i] > 1) - { - ac[i] = ac[i] % 2; - c = 1; - } - else - c = 0; - } -} - -void ashr(int ac[], int qr[], int &qn, int qrn) -{ - int temp, i; - temp = ac[0]; - qn = qr[0]; - cout << "\t\tashr\t\t"; - for (i = 0; i < qrn - 1; i++) - { - ac[i] = ac[i + 1]; - qr[i] = qr[i + 1]; - } - qr[qrn - 1] = temp; -} - -void display(int ac[], int qr[], int qrn) -{ - int i; - for (i = qrn - 1; i >= 0; i--) - cout << ac[i]; - cout << " "; - for (i = qrn - 1; i >= 0; i--) - cout << qr[i]; -} - -int main(int argc, char **argv) -{ - int mt[10], br[10], qr[10], sc, ac[10] = { 0 }; - int brn, qrn, i, qn, temp; - cout - << "\n--Enter the multiplicand and multipier in signed 2's complement form if negative--"; - cout << "\n Number of multiplicand bit="; - cin >> brn; - cout << "\nmultiplicand="; - for (i = brn - 1; i >= 0; i--) - cin >> br[i]; //multiplicand - for (i = brn - 1; i >= 0; i--) - mt[i] = br[i]; // copy multipier to temp array mt[] - complement(mt, brn); - cout << "\nNo. of multiplier bit="; - cin >> qrn; - sc = qrn; //sequence counter - cout << "Multiplier="; - for (i = qrn - 1; i >= 0; i--) - cin >> qr[i]; //multiplier - qn = 0; - temp = 0; - cout << "qn\tq[n+1]\t\tBR\t\tAC\tQR\t\tsc\n"; - cout << "\t\t\tinitial\t\t"; - display(ac, qr, qrn); - cout << "\t\t" << sc << "\n"; - while (sc != 0) - { - cout << qr[0] << "\t" << qn; - if ((qn + qr[0]) == 1) - { - if (temp == 0) - { - add(ac, mt, qrn); - cout << "\t\tsubtracting BR\t"; - for (i = qrn - 1; i >= 0; i--) - cout << ac[i]; - temp = 1; - } - else if (temp == 1) - { - add(ac, br, qrn); - cout << "\t\tadding BR\t"; - for (i = qrn - 1; i >= 0; i--) - cout << ac[i]; - temp = 0; - } - cout << "\n\t"; - ashr(ac, qr, qn, qrn); - } - else if (qn - qr[0] == 0) - ashr(ac, qr, qn, qrn); - display(ac, qr, qrn); - cout << "\t"; - sc--; - cout << "\t" << sc << "\n"; - } - cout << "Result="; - display(ac, qr, qrn); -} - -/* ---Enter the multiplicand and multipier in signed 2's complement form if negative-- -Number of multiplicand bit=5 -Multiplicand=1 0 1 1 1 - -Number of multiplier bit=5 -Multiplier=1 0 0 1 1 - -qn q[n+1] BR AC QR sc - initial 00000 10011 5 -1 0 subtracting BR 01001 - ashr 00100 11001 4 -1 1 ashr 00010 01100 3 -0 1 adding BR 11001 - ashr 11100 10110 2 -0 0 ashr 11110 01011 1 -1 0 subtracting BR 00111 - ashr 00011 10101 0 - -Result=00011 10101 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement Coppersmith Freivald’s Algorithm.cpp b/c++/11_Numerical_Problems/C++ Program to Implement Coppersmith Freivald’s Algorithm.cpp deleted file mode 100644 index b5fe347..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement Coppersmith Freivald’s Algorithm.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main(int argc, char **argv) -{ - cout << "Enter the dimension of the matrices: "; - int n; - cin >> n; - cout << "Enter the 1st matrix: "; - double a[n][n]; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { - cin >> a[i][j]; - } - } - cout << "Enter the 2nd matrix: "; - double b[n][n]; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { - cin >> b[i][j]; - } - } - cout << "Enter the result matrix: "; - double c[n][n]; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { - cin >> c[i][j]; - } - } - //random generation of the r vector containing only 0/1 as its elements - double r[n][1]; - for (int i = 0; i < n; i++) - { - r[i][0] = rand() % 2; - cout << r[i][0] << " "; - } - //test A * (b*r) - (C*) = 0 - double br[n][1]; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < 1; j++) - { - for (int k = 0; k < n; k++) - { - br[i][j] = br[i][j] + b[i][k] * r[k][j]; - } - } - } - double cr[n][1]; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < 1; j++) - { - for (int k = 0; k < n; k++) - { - cr[i][j] = cr[i][j] + c[i][k] * r[k][j]; - } - } - } - double abr[n][1]; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < 1; j++) - { - for (int k = 0; k < n; k++) - { - abr[i][j] = abr[i][j] + a[i][k] * br[k][j]; - } - } - } - // br = multiplyVector(b, r, n); - // cr = multiplyVector(c, r, n); - // abr = multiplyVector(a, br, n); - //abr-cr - for (int i = 0; i < n; i++) - { - abr[i][0] -= cr[i][0]; - } - bool flag = true; - for (int i = 0; i < n; i++) - { - if (abr[i][0] == 0) - continue; - else - flag = false; - } - if (flag == true) - cout << "Yes"; - else - cout << "No"; -} - -/* - -Enter the dimension of the matrices: 2 -Enter the 1st matrix: -1 2 -2 3 -Enter the 2nd matrix: -1 3 -3 4 -Enter the result matrix: -9 9 -14 15 - -Yes - -Enter the dimesion of the matrices: -2 -Enter the 1st matrix: -2 3 -3 4 -Enter the 2st matrix: -1 0 -1 2 -Enter the result matrix: -6 5 -8 7 - -Yes \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement Euler Theorem.cpp b/c++/11_Numerical_Problems/C++ Program to Implement Euler Theorem.cpp deleted file mode 100644 index a9d5d16..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement Euler Theorem.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * C++ Program to Implement Euler Theorem - */ -#include -#include -using namespace std; - -vector inverseArray(int n, int m) -{ - vector modInverse(n + 1, 0); - modInverse[1] = 1; - for (int i = 2; i <= n; i++) - { - modInverse[i] = (-(m / i) * modInverse[m % i]) % m + m; - } - return modInverse; -} -//Main -int main() -{ - vector::iterator it; - int a, m; - cout<<"Enter number to find modular multiplicative inverse: "; - cin>>a; - cout<<"Enter Modular Value: "; - cin>>m; - cout< -#include - -using namespace std; -/* return the gcd of a and b followed by the pair x and y of - equation ax + by = gcd(a,b) -*/ -pair > extendedEuclid(int a, int b) -{ - int x = 1, y = 0; - int xLast = 0, yLast = 1; - int q, r, m, n; - while (a != 0) - { - q = b / a; - r = b % a; - m = xLast - q * x; - n = yLast - q * y; - xLast = x; - yLast = y; - x = m; - y = n; - b = a; - a = r; - } - return make_pair(b, make_pair(xLast, yLast)); -} - -int modInverse(int a, int m) -{ - return (extendedEuclid(a, m).second.first + m) % m; -} - -//Main -int main() -{ - int a, m; - cout<<"Enter number to find modular multiplicative inverse: "; - cin>>a; - cout<<"Enter Modular Value: "; - cin>>m; - cout< -#include -#include -#define ll long long -using namespace std; -/* - * modular exponentiation - */ -ll modulo(ll base, ll exponent, ll mod) -{ - ll x = 1; - ll y = base; - while (exponent > 0) - { - if (exponent % 2 == 1) - x = (x * y) % mod; - y = (y * y) % mod; - exponent = exponent / 2; - } - return x % mod; -} - -/* - * Fermat's test for checking primality - */ -bool Fermat(ll p, int iterations) -{ - if (p == 1) - { - return false; - } - for (int i = 0; i < iterations; i++) - { - ll a = rand() % (p - 1) + 1; - if (modulo(a, p - 1, p) != 1) - { - return false; - } - } - return true; -} -/* - * Main - */ -int main() -{ - int iteration = 50; - ll num; - cout<<"Enter integer to test primality: "; - cin>>num; - if (Fermat(num, iteration)) - cout< -using namespace std; - -/* calculates (a^b)%MOD */ -int pow(int a, int b, int MOD) -{ - int x = 1, y = a; - while (b > 0) - { - if (b % 2 == 1) - { - x = (x * y); - if (x > MOD) - x %= MOD; - } - y = (y * y); - if (y > MOD) - y %= MOD; - b /= 2; - } - return x; -} - -int modInverse(int a, int m) -{ - return pow(a, m - 2, m); -} -//Main -int main() -{ - int a, m; - cout<<"Enter number to find modular multiplicative inverse: "; - cin>>a; - cout<<"Enter Modular Value: "; - cin>>m; - cout< -#include - -using namespace std; - -void fisherYatesShuffling(int *arr, int n) -{ - int a[n]; - int ind[n]; - for (int i = 0; i < n; i++) - ind[i] = 0; - int index; - for (int i = 0; i < n; i++) - { - do - { - index = rand() % n; - } - while (ind[index] != 0); - ind[index] = 1; - a[i] = *(arr + index); - } - for (int i = 0; i < n; i++) - { - cout << a[i] << " "; - } -} - -int main(int argc, char **argv) -{ - cout << "Enter the array size: "; - int n; - cin >> n; - cout << "Enter the array elements: "; - int a[n]; - for (int i = 0; i < n; i++) - { - cin >> a[i]; - } - fisherYatesShuffling(a, n); -} - -/* -Enter the array size: 7 -Enter the array elements: 12 23 34 45 56 67 78 -78 23 67 45 34 12 56 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement Gauss Seidel Method.cpp b/c++/11_Numerical_Problems/C++ Program to Implement Gauss Seidel Method.cpp deleted file mode 100644 index 8ca7766..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement Gauss Seidel Method.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include - -using namespace std; - -int main(void) -{ - float a[10][10], b[10], x[10], y[10]; - int n = 0, m = 0, i = 0, j = 0; - cout << "Enter size of 2d array(Square matrix) : "; - cin >> n; - for (i = 0; i < n; i++) - { - for (j = 0; j < n; j++) - { - cout << "Enter values no :(" << i << ", " << j << ") "; - cin >> a[i][j]; - } - } - cout << "\nEnter Values to the right side of equation\n"; - for (i = 0; i < n; i++) - { - cout << "Enter values no :(" << i << ", " << j << ") "; - cin >> b[i]; - } - cout << "Enter initial values of x\n"; - for (i = 0; i < n; i++) - { - cout << "Enter values no. :(" << i<<"):"; - cin >> x[i]; - } - cout << "\nEnter the no. of iteration : "; - cin >> m; - while (m > 0) - { - for (i = 0; i < n; i++) - { - y[i] = (b[i] / a[i][i]); - for (j = 0; j < n; j++) - { - if (j == i) - continue; - y[i] = y[i] - ((a[i][j] / a[i][i]) * x[j]); - x[i] = y[i]; - } - printf("x%d = %f ", i + 1, y[i]); - } - cout << "\n"; - m--; - } - return 0; -} - -/* -Enter size of 2d array(Square matrix) : 3 -Enter values no :(0, 0) 2 -Enter values no :(0, 1) 3 -Enter values no :(0, 2) 1 -Enter values no :(1, 0) 5 -Enter values no :(1, 1) 4 -Enter values no :(1, 2) 6 -Enter values no :(2, 0) 8 -Enter values no :(2, 1) 7 -Enter values no :(2, 2) 9 - -Enter Values to the right side of equation -Enter values no :(0, 3) 2 -Enter values no :(1, 3) 3 -Enter values no :(2, 3) 4 - -Enter initial values of x -Enter values no. :(0): 0 -Enter values no. :(1): 0 -Enter values no. :(2): 0 - -Enter the no. of iteration : 4 -x1 = 1.000000 x2 = -0.500000 x3 = -0.055556 -x1 = 1.777778 x2 = -1.388889 x3 = -0.055556 -x1 = 3.111111 x2 = -3.055555 x3 = 0.055555 -x1 = 5.555555 x2 = -6.277777 x3 = 0.388889 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement Miller Rabin Primality Test.cpp b/c++/11_Numerical_Problems/C++ Program to Implement Miller Rabin Primality Test.cpp deleted file mode 100644 index c361a53..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement Miller Rabin Primality Test.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * C++ Program to Implement Miller Rabin Primality Test - */ -#include -#include -#include -#define ll long long -using namespace std; - -/* - * calculates (a * b) % c taking into account that a * b might overflow - */ -ll mulmod(ll a, ll b, ll mod) -{ - ll x = 0,y = a % mod; - while (b > 0) - { - if (b % 2 == 1) - { - x = (x + y) % mod; - } - y = (y * 2) % mod; - b /= 2; - } - return x % mod; -} -/* - * modular exponentiation - */ -ll modulo(ll base, ll exponent, ll mod) -{ - ll x = 1; - ll y = base; - while (exponent > 0) - { - if (exponent % 2 == 1) - x = (x * y) % mod; - y = (y * y) % mod; - exponent = exponent / 2; - } - return x % mod; -} - -/* - * Miller-Rabin primality test, iteration signifies the accuracy - */ -bool Miller(ll p,int iteration) -{ - if (p < 2) - { - return false; - } - if (p != 2 && p % 2==0) - { - return false; - } - ll s = p - 1; - while (s % 2 == 0) - { - s /= 2; - } - for (int i = 0; i < iteration; i++) - { - ll a = rand() % (p - 1) + 1, temp = s; - ll mod = modulo(a, temp, p); - while (temp != p - 1 && mod != 1 && mod != p - 1) - { - mod = mulmod(mod, mod, p); - temp *= 2; - } - if (mod != p - 1 && temp % 2 == 0) - { - return false; - } - } - return true; -} -//Main -int main() -{ - int iteration = 5; - ll num; - cout<<"Enter integer to test primality: "; - cin>>num; - if (Miller(num, iteration)) - cout< -#define ll long long -using namespace std; - -/* - * Function to calculate modulus of x raised to the power y - */ -ll modular_pow(ll base, ll exponent, int modulus) -{ - ll result = 1; - while (exponent > 0) - { - if (exponent % 2 == 1) - result = (result * base) % modulus; - exponent = exponent >> 1; - base = (base * base) % modulus; - } - return result; -} -/* - * Main - */ -int main() -{ - ll x, y; - int mod; - cout<<"Enter Base Value: "; - cin>>x; - cout<<"Enter Exponent: "; - cin>>y; - cout<<"Enter Modular Value: "; - cin>>mod; - cout< -#include -#include - -using namespace std; - -int main(int argc, char **argv) -{ - int p = 7, l = 3, g = 2, n = 4, x; - int a[] = { 1, 2, 2, 1 }; - int bin[4]; - cout << "The Random numbers are: "; - for (int i = 0; i < 10; i++) - { - x = rand() % 16; - for (int j = 3; j >= 0; j--) - { - bin[j] = x % 2; - x /= 2; - } - int mul = 1; - for (int k = 0; k < 4; k++) - mul *= pow(a[k], bin[k]); - cout << pow(g, mul)<<" "; - } -} - -/* -The Random numbers are: -2 4 16 4 2 4 16 16 4 2 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement Park-Miller Random Number Generation Algorithm.cpp b/c++/11_Numerical_Problems/C++ Program to Implement Park-Miller Random Number Generation Algorithm.cpp deleted file mode 100644 index ba16b82..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement Park-Miller Random Number Generation Algorithm.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/*This is a C++ Program to generate random numbers using Park-Miller algorithm. A general formula of a random number generator (RNG) of this type is: -X_{k+1} = g X(k) mod n -where the modulus n is a prime number or a power of a prime number, the multiplier g is an element of high multiplicative order modulo n (e.g., a primitive root modulo n), and the seed X0 is co-prime to n.*/ - -#include -#include -#include - -using namespace std; - -const long m = 2147483647L; -const long a = 48271L; -const long q = 44488L; -const long r = 3399L; - -static long r_seed = 12345678L; - -double uniform() -{ - long hi = r_seed / q; - long lo = r_seed - q * hi; - long t = a * lo - r * hi; - if (t > 0) - r_seed = t; - else - r_seed = t + m; - return r_seed; -} - -int main(int argc, char **argv) -{ - double A[10]; - for (int i = 0; i < 10; i++) - A[i] = uniform(); - cout<<"Random numbers are:\n"; - for (int i = 0; i < 10; i++) - cout << A[i]< -using namespace std; -/* - * multiply two numbers using Russian Peasant method - */ -unsigned int russianPeasant(unsigned int a, unsigned int b) -{ - int res = 0; - while (b > 0) - { - if (b & 1) - res = res + a; - a = a << 1; - b = b >> 1; - } - return res; -} - -/* - * Main - */ -int main() -{ - cout << russianPeasant(15, 5) << endl; - cout << russianPeasant(13, 6) << endl; - return 0; -} - -/* -75 -78 - ------------------- -(program exited with code: 1) -Press return to continue \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement Segmented Sieve.cpp b/c++/11_Numerical_Problems/C++ Program to Implement Segmented Sieve.cpp deleted file mode 100644 index 8b7d84c..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement Segmented Sieve.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * C++ Program to Implement Segmented Sieve - */ -#include -#include -#define MAX 46656 -#define LMT 216 -#define LEN 4830 -#define RNG 100032 -#define sq(x) ((x)*(x)) -#define mset(x,v) memset(x, v , sizeof(x)) -#define chkC(x,n) (x[n >> 6] & (1 << ((n >> 1) & 31))) -#define setC(x,n) (x[n >> 6] |= (1 << ((n >> 1) & 31))) -using namespace std; -unsigned base[MAX/64], segment[RNG/64], primes[LEN]; - -/* - * Generates all the necessary prime numbers and marks them in base[] - */ -void sieve() -{ - unsigned i, j, k; - for (i = 3; i < LMT; i += 2) - { - if (!chkC(base, i)) - { - for (j = i * i, k = i << 1; j < MAX; j += k) - setC(base, j); - } - } - for (i = 3, j = 0; i < MAX; i += 2) - { - if (!chkC(base, i)) - primes[j++] = i; - } -} - -/* - * Returns the prime-count within range [a,b] and marks them in segment[] - */ -int segmented_sieve(int a, int b) -{ - unsigned i, j, k, cnt = (a <= 2 && 2 <=b )? 1 : 0; - if (b < 2) - return 0; - if (a < 3) - a = 3; - if (a % 2 == 0) - a++; - mset (segment, 0); - for (i = 0; sq(primes[i]) <= b; i++) - { - j = primes[i] * ((a + primes[i] - 1) / primes[i]); - if (j % 2 == 0) j += primes[i]; - for (k = primes[i] << 1; j <= b; j += k) - { - if (j != primes[i]) - setC(segment, (j - a)); - } - } - for (i = 0; i <= b - a; i += 2) - { - if (!chkC(segment, i)) - cnt++; - } - return cnt; -} -/* - * Main - */ -int main() -{ - sieve(); - int a, b; - cout<<"Enter Lower Bound: "; - cin>>a; - cout<<"Enter Upper Bound: "; - cin>>b; - cout<<"Number of primes between "< -#include -#include -#define ll long long - -using namespace std; - -/* - * Sieve of Atkins - */ -void sieve_atkins(ll int n) -{ - vector is_prime(n + 1); - is_prime[2] = true; - is_prime[3] = true; - for (ll int i = 5; i <= n; i++) - { - is_prime[i] = false; - } - ll int lim = ceil(sqrt(n)); - for (ll int x = 1; x <= lim; x++) - { - for (ll int y = 1; y <= lim; y++) - { - ll int num = (4 * x * x + y * y); - if (num <= n && (num % 12 == 1 || num % 12 == 5)) - { - is_prime[num] = true; - } - num = (3 * x * x + y * y); - if (num <= n && (num % 12 == 7)) - { - is_prime[num] = true; - } - if (x > y) - { - num = (3 * x * x - y * y); - if (num <= n && (num % 12 == 11)) - { - is_prime[num] = true; - } - } - } - } - for (ll int i = 5; i <= lim; i++) - { - if (is_prime[i]) - { - for (ll int j = i * i; j <= n; j += i) - { - is_prime[j] = false; - } - } - } - for (ll int i = 2; i <= n; i++) - { - if (is_prime[i]) - { - cout< -const int len = 100; - -int main() -{ - int arr[100] = {0}; - for (int i = 2; i < 100; i++) - { - for (int j = i * i; j < 100; j+=i) - { - arr[j - 1] = 1; - } - } - for (int i = 1; i < 100; i++) - { - if (arr[i - 1] == 0) - std::cout << i << "\t"; - } -} - -/* -1 2 3 5 7 11 13 17 19 23 -29 31 37 41 43 47 53 59 61 67 -71 73 79 83 89 97 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement Solovay-Strassen Primality Test.cpp b/c++/11_Numerical_Problems/C++ Program to Implement Solovay-Strassen Primality Test.cpp deleted file mode 100644 index bbcefb2..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement Solovay-Strassen Primality Test.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * C++ Program to Implement Solovay-Strassen Primality Test - */ -#include -#include -#include -#define ll long long -using namespace std; -/* - * modular exponentiation - */ -ll modulo(ll base, ll exponent, ll mod) -{ - ll x = 1; - ll y = base; - while (exponent > 0) - { - if (exponent % 2 == 1) - x = (x * y) % mod; - y = (y * y) % mod; - exponent = exponent / 2; - } - return x % mod; -} -/* - * calculates Jacobian(a/n) n>0 and n is odd - */ -int calculateJacobian(ll a,ll n) -{ - if (!a) - return 0; - int ans = 1; - ll temp; - if (a < 0) - { - a = -a; - if (n % 4 == 3) - ans=-ans; - } - if (a == 1) - return ans; - while (a) - { - if (a < 0) - { - a = -a; - if (n % 4 == 3) - ans = -ans; - } - while (a % 2 == 0) - { - a = a / 2; - if (n % 8 == 3 || n % 8 == 5) - ans = -ans; - } - swap(a, n); - if (a % 4 == 3 && n % 4 == 3) - ans = -ans; - a = a % n; - if (a > n / 2) - a = a - n; - } - if (n == 1) - return ans; - return 0; -} - -/* - * Solovay-Strassen Primality Test - * Iterations determine the accuracy of the test - */ -bool Solovoy(ll p, int iteration) -{ - if (p < 2) - return false; - if (p != 2 && p % 2 == 0) - return false; - for (int i = 0; i < iteration; i++) - { - ll a = rand() % (p - 1) + 1; - ll jacobian = (p + calculateJacobian(a, p)) % p; - ll mod = modulo(a, (p - 1) / 2, p); - if (!jacobian || mod != jacobian) - { - return false; - } - } - return true; -} -//Main -int main() -{ - int iteration = 50; - ll num; - cout<<"Enter integr to test primality: "; - cin>>num; - if (Solovoy(num, iteration)) - cout< -#include -#include -#include - -#define M 2 -#define N (1<rb = rm; // top rows - else - b->ra = rm; // bot rows - if (j == 0) - b->cb = cm; // left cols - else - b->ca = cm; // right cols -} - -// Multiply: A[a] * B[b] => C[c], recursively. -void mul(mat A, mat B, mat C, corners a, corners b, corners c) -{ - corners aii[2][2], bii[2][2], cii[2][2], p; - mat P[7], S, T; - int i, j, m, n, k; - // Check: A[m n] * B[n k] = C[m k] - m = a.rb - a.ra; - assert(m==(c.rb-c.ra)); - n = a.cb - a.ca; - assert(n==(b.rb-b.ra)); - k = b.cb - b.ca; - assert(k==(c.cb-c.ca)); - assert(m>0); - if (n == 1) - { - C[c.ra][c.ca] += A[a.ra][a.ca] * B[b.ra][b.ca]; - return; - } - // Create the 12 smaller matrix indexes: - // A00 A01 B00 B01 C00 C01 - // A10 A11 B10 B11 C10 C11 - for (i = 0; i < 2; i++) - { - for (j = 0; j < 2; j++) - { - find_corner(a, i, j, &aii[i][j]); - find_corner(b, i, j, &bii[i][j]); - find_corner(c, i, j, &cii[i][j]); - } - } - p.ra = p.ca = 0; - p.rb = p.cb = m / 2; -#define LEN(A) (sizeof(A)/sizeof(A[0])) - for (i = 0; i < LEN(P); i++) - set(P[i], p, 0); -#define ST0 set(S,p,0); set(T,p,0) - // (A00 + A11) * (B00+B11) = S * T = P0 - ST0; - add(A, A, S, aii[0][0], aii[1][1], p); - add(B, B, T, bii[0][0], bii[1][1], p); - mul(S, T, P[0], p, p, p); - // (A10 + A11) * B00 = S * B00 = P1 - ST0; - add(A, A, S, aii[1][0], aii[1][1], p); - mul(S, B, P[1], p, bii[0][0], p); - // A00 * (B01 - B11) = A00 * T = P2 - ST0; - sub(B, B, T, bii[0][1], bii[1][1], p); - mul(A, T, P[2], aii[0][0], p, p); - // A11 * (B10 - B00) = A11 * T = P3 - ST0; - sub(B, B, T, bii[1][0], bii[0][0], p); - mul(A, T, P[3], aii[1][1], p, p); - // (A00 + A01) * B11 = S * B11 = P4 - ST0; - add(A, A, S, aii[0][0], aii[0][1], p); - mul(S, B, P[4], p, bii[1][1], p); - // (A10 - A00) * (B00 + B01) = S * T = P5 - ST0; - sub(A, A, S, aii[1][0], aii[0][0], p); - add(B, B, T, bii[0][0], bii[0][1], p); - mul(S, T, P[5], p, p, p); - // (A01 - A11) * (B10 + B11) = S * T = P6 - ST0; - sub(A, A, S, aii[0][1], aii[1][1], p); - add(B, B, T, bii[1][0], bii[1][1], p); - mul(S, T, P[6], p, p, p); - // P0 + P3 - P4 + P6 = S - P4 + P6 = T + P6 = C00 - add(P[0], P[3], S, p, p, p); - sub(S, P[4], T, p, p, p); - add(T, P[6], C, p, p, cii[0][0]); - // P2 + P4 = C01 - add(P[2], P[4], C, p, p, cii[0][1]); - // P1 + P3 = C10 - add(P[1], P[3], C, p, p, cii[1][0]); - // P0 + P2 - P1 + P5 = S - P1 + P5 = T + P5 = C11 - add(P[0], P[2], S, p, p, p); - sub(S, P[1], T, p, p, p); - add(T, P[5], C, p, p, cii[1][1]); -} -int main() -{ - mat A, B, C; - corners ai = { 0, N, 0, N }; - corners bi = { 0, N, 0, N }; - corners ci = { 0, N, 0, N }; - srand(time(0)); - // identity(A,bi); identity(B,bi); - // set(A,ai,2); set(B,bi,2); - randk(A, ai, 0, 2); - randk(B, bi, 0, 2); - print(A, ai, "A"); - print(B, bi, "B"); - set(C, ci, 0); - // add(A,B,C, ai, bi, ci); - mul(A, B, C, ai, bi, ci); - print(C, ci, "C"); - return 0; -} - -/* - -A = { - 1.2, 0.83, 0.39, 0.41, - 1.8, 1.9, 0.49, 0.23, -0.38, 0.72, 1.8, 1.9, -0.13, 1.8, 0.48, 0.82, -} -B = { - 1.2, 1.6, 1.4, 1.6, -0.27, 0.63, 0.3, 0.79, -0.58, 1.2, 1.1, 0.07, - 2, 1.9, 0.47, 0.47, -} -C = { - 2.7, 3.7, 2.6, 2.9, - 3.4, 5, 3.7, 4.5, - 5.3, 6.7, 3.6, 2.2, - 2.5, 3.5, 1.6, 2.1, -} \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement the Bin Packing Algorithm.cpp b/c++/11_Numerical_Problems/C++ Program to Implement the Bin Packing Algorithm.cpp deleted file mode 100644 index f95ab57..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement the Bin Packing Algorithm.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/*This is a C++ Program to implement Bin packing algorithm. This is a sample program to illustrate the Bin-Packing algorithm using next fit heuristics. In the bin packing problem, objects of different volumes must be packed into a finite number of bins or containers each of volume V in a way that minimizes the number of bins used. In computational complexity theory, it is a combinatorial NP-hard problem. -There are many variations of this problem, such as 2D packing, linear packing, packing by weight, packing by cost, and so on. They have many applications, such as filling up containers, loading trucks with weight capacity constraints, creating file backups in media and technology mapping in Field-programmable gate array semiconductor chip design. - -The bin packing problem can also be seen as a special case of the cutting stock problem. When the number of bins is restricted to 1 and each item is characterised by both a volume and a value, the problem of maximising the value of items that can fit in the bin is known as the knapsack problem.*/ - -#include - -using namespace std; - -void binPacking(int *a, int size, int n) -{ - int binCount = 1; - int s = size; - for (int i = 0; i < n; i++) - { - if (s - *(a + i) > 0) - { - s -= *(a + i); - continue; - } - else - { - binCount++; - s = size; - i--; - } - } - cout << "Number of bins required: " << binCount; -} - -int main(int argc, char **argv) -{ - cout << "BIN - PACKING Algorithm\n"; - cout << "Enter the number of items in Set: "; - int n; - cin >> n; - cout << "Enter " << n << " items:"; - int a[n]; - for (int i = 0; i < n; i++) - cin >> a[i]; - cout << "Enter the bin size: "; - int size; - cin >> size; - binPacking(a, size, n); -} - -/* -BIN - PACKING Algorithm -Enter the number of items in Set: 5 -Enter 5 items:12 23 34 45 56 -Enter the bin size: 70 -Number of bins required: 3 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement the Schonhage-Strassen Algorithm for Multiplication of Two Numbers.cpp b/c++/11_Numerical_Problems/C++ Program to Implement the Schonhage-Strassen Algorithm for Multiplication of Two Numbers.cpp deleted file mode 100644 index cfe517d..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement the Schonhage-Strassen Algorithm for Multiplication of Two Numbers.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include - -using namespace std; - -int noOfDigit(long a) -{ - int n = 0; - while (a > 0) - { - a /= 10; - n++; - } - return n; -} -void schonhageStrassenMultiplication(long x, long y, int n, int m) -{ - int linearConvolution[n + m - 1]; - for (int i = 0; i < (n + m - 1); i++) - linearConvolution[i] = 0; - long p = x; - for (int i = 0; i < m; i++) - { - x = p; - for (int j = 0; j < n; j++) - { - linearConvolution[i + j] += (y % 10) * (x % 10); - x /= 10; - } - y /= 10; - } - cout << "The Linear Convolution is: ( "; - for (int i = (n + m - 2); i >= 0; i--) - { - cout << linearConvolution[i] << " "; - } - cout << ")"; - long product = 0; - int nextCarry = 0, base = 1; - ; - for (int i = 0; i < n + m - 1; i++) - { - linearConvolution[i] += nextCarry; - product = product + (base * (linearConvolution[i] % 10)); - nextCarry = linearConvolution[i] / 10; - base *= 10; - } - cout << "\nThe Product of the numbers is: " << product; -} -int main(int argc, char **argv) -{ - cout << "Enter the numbers:"; - long a, b; - cin >> a >> b; - int n = noOfDigit(a); - int m = noOfDigit(b); - schonhageStrassenMultiplication(a, b, n, m); -} - -/* -Enter the numbers:3452 1245 -The Linear Convolution is: ( 3 10 25 43 44 33 10 ) - Product of the numbers is: 4297740 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement the linear congruential generator for Pseudo Random Number Generation.cpp b/c++/11_Numerical_Problems/C++ Program to Implement the linear congruential generator for Pseudo Random Number Generation.cpp deleted file mode 100644 index a422fd1..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement the linear congruential generator for Pseudo Random Number Generation.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/*This is a C++ Program to generate random numbers using Linear Congruential Generator. A linear congruential generator (LCG) is an algorithm that yields a sequence of pseudo-randomized numbers calculated with a discontinuous piecewise linear equation. The method represents one of the oldest and best-known pseudorandom number generator algorithms. The theory behind them is relatively easy to understand, and they are easily implemented and fast, especially on computer hardware which can provide modulo arithmetic by storage-bit truncation.*/ - -#include - -using namespace std; - -class mRND -{ -public: - void seed(unsigned int s) - { - _seed = s; - } - -protected: - mRND() : - _seed(0), _a(0), _c(0), _m(2147483648) - { - } - int rnd() - { - return (_seed = (_a * _seed + _c) % _m); - } - - int _a, _c; - unsigned int _m, _seed; -}; - -class MS_RND: public mRND -{ -public: - MS_RND() - { - _a = 214013; - _c = 2531011; - } - int rnd() - { - return mRND::rnd() >> 16; - } -}; - -class BSD_RND: public mRND -{ -public: - BSD_RND() - { - _a = 1103515245; - _c = 12345; - } - int rnd() - { - return mRND::rnd(); - } -}; - -int main(int argc, char* argv[]) -{ - BSD_RND bsd_rnd; - MS_RND ms_rnd; - cout << "MS RAND:" << endl << "========" << endl; - for (int x = 0; x < 10; x++) - cout << ms_rnd.rnd() << endl; - cout << endl << "BSD RAND:" << endl << "=========" << endl; - for (int x = 0; x < 10; x++) - cout << bsd_rnd.rnd() << endl; - return 0; -} - -/* -MS RAND: -======== -38 -7719 -21238 -2437 -8855 -11797 -8365 -32285 -10450 -30612 - -BSD RAND: -========= -12345 -1406932606 -654583775 -1449466924 -229283573 -1109335178 -1051550459 -1293799192 -794471793 -551188310 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Implement wheel Sieve to Generate Prime Numbers Between Given Range.cpp b/c++/11_Numerical_Problems/C++ Program to Implement wheel Sieve to Generate Prime Numbers Between Given Range.cpp deleted file mode 100644 index dd68031..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Implement wheel Sieve to Generate Prime Numbers Between Given Range.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/*This is a C++ Program to find prime number between a given range using Wheel Seive method. Wheel factorization is a graphical method for manually performing a preliminary to the Sieve of Eratosthenes that separates prime numbers from composites. Start by writing the natural numbers around circles as shown below. Prime numbers in the innermost circle have their multiples in similar positions as themselves in the other circles, forming spokes of primes and their multiples. Multiples of the prime numbers in the innermost circle form spokes of composite numbers in the outer circles.*/ - -#include -#include -#include - -using namespace std; - -#define MAX_NUM 50 -// array will be initialized to 0 being global -int primes[MAX_NUM]; - -void gen_sieve_primes(void) -{ - for (int p = 2; p < MAX_NUM; p++) // for all elements in array - { - if (primes[p] == 0) // it is not multiple of any other prime - primes[p] = 1; // mark it as prime - // mark all multiples of prime selected above as non primes - int c = 2; - int mul = p * c; - for (; mul < MAX_NUM;) - { - primes[mul] = -1; - c++; - mul = p * c; - } - } -} - -void print_all_primes() -{ - int c = 0; - for (int i = 0; i < MAX_NUM; i++) - { - if (primes[i] == 1) - { - c++; - if (c < 4) - { - switch (c) - { - case 1: - cout << c << "st prime is: " << i << endl; - break; - case 2: - cout << c << "nd prime is: " << i << endl; - break; - case 3: - cout << c << "rd prime is: " << i << endl; - break; - default: - break; - } - } - else - cout << c << "th prime is: " << i << endl; - } - } -} - -int main() -{ - gen_sieve_primes(); - print_all_primes(); - return 0; -} - -/* -1st prime is: 2 -2nd prime is: 3 -3rd prime is: 5 -4th prime is: 7 -5th prime is: 11 -6th prime is: 13 -7th prime is: 17 -8th prime is: 19 -9th prime is: 23 -10th prime is: 29 -11th prime is: 31 -12th prime is: 37 -13th prime is: 41 -14th prime is: 43 -15th prime is: 47 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Optimize Wire Length in Electrical Circuit.cpp b/c++/11_Numerical_Problems/C++ Program to Optimize Wire Length in Electrical Circuit.cpp deleted file mode 100644 index 56b3fc9..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Optimize Wire Length in Electrical Circuit.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include -#include - -using namespace std; - -// Number of components in the graph -#define V 9 - -// A utility function to find the component with minimum distance value, from -// the set of components not yet included in shortest path tree -int minDistance(int dist[], bool sptSet[]) -{ - // Initialize min value - int min = INT_MAX, min_index; - for (int v = 0; v < V; v++) - if (sptSet[v] == false && dist[v] <= min) - min = dist[v], min_index = v; - return min_index; -} - -// A utility function to print the constructed distance array -void printSolution(int dist[], int n) -{ - cout << "Component\tDistance from other component\n"; - for (int i = 0; i < V; i++) - printf("%d\t\t%d\n", i, dist[i]); -} - -// Funtion that implements Dijkstra's single source shortest path algorithm -// for a graph represented using adjacency matrix representation -void optimizeLength(int graph[V][V], int src) -{ - int dist[V]; // The output array. dist[i] will hold the shortest - // distance from src to i - bool sptSet[V]; // sptSet[i] will true if component i is included in shortest - // path tree or shortest distance from src to i is finalized - // Initialize all distances as INFINITE and stpSet[] as false - for (int i = 0; i < V; i++) - dist[i] = INT_MAX, sptSet[i] = false; - // Distance of source component from itself is always 0 - dist[src] = 0; - // Find shortest path for all components - for (int count = 0; count < V - 1; count++) - { - // Pick the minimum distance component from the set of components not - // yet processed. u is always equal to src in first iteration. - int u = minDistance(dist, sptSet); - // Mark the picked component as processed - sptSet[u] = true; - // Update dist value of the adjacent components of the picked component. - for (int v = 0; v < V; v++) - // Update dist[v] only if is not in sptSet, there is an edge from - // u to v, and total weight of path from src to v through u is - // smaller than current value of dist[v] - if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX && dist[u] - + graph[u][v] < dist[v]) - dist[v] = dist[u] + graph[u][v]; - } - // print the constructed distance array - printSolution(dist, V); -} - -// driver program to test above function -int main() -{ - /* Let us create the example graph discussed above */ - int graph[V][V] = - { - { 0, 4, 0, 0, 0, 0, 0, 8, 0 }, { 4, 0, 8, 0, 0, 0, 0, 11, 0 }, { - 0, 8, 0, 7, 0, 4, 0, 0, 2 - }, - { 0, 0, 7, 0, 9, 14, 0, 0, 0 }, { - 0, 0, 0, 9, 0, 10, 0, 0, - 0 - }, { 0, 0, 4, 0, 10, 0, 2, 0, 0 }, { - 0, 0, 0, 14, - 0, 2, 0, 1, 6 - }, { 8, 11, 0, 0, 0, 0, 1, 0, 7 }, { - 0, 0, 2, 0, 0, 0, 6, 7, 0 - } - }; - cout << "Enter the starting component: "; - int s; - cin >> s; - optimizeLength(graph, s); - return 0; -} - -/* -Enter the starting component: 1 -Component Distance from other component -0 4 -1 0 -2 8 -3 15 -4 22 -5 12 -6 12 -7 11 -8 10 - -Enter the starting component: 6 -Component Distance from other component -0 9 -1 12 -2 6 -3 13 -4 12 -5 2 -6 0 -7 1 -8 6 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Perform Addition Operation Using Bitwise Operators.cpp b/c++/11_Numerical_Problems/C++ Program to Perform Addition Operation Using Bitwise Operators.cpp deleted file mode 100644 index fbd98e7..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Perform Addition Operation Using Bitwise Operators.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -using namespace std; -int add(int x, int y) -{ - int carry; - while (y != 0) - { - carry = x & y; - x = x ^ y; - y = carry << 1; - } - return x; -} -int main(int argc, char **argv) -{ - cout << "Enter the numbers to be added:"; - int x, y; - cin >> x >> y; - cout << "The Summation is: " << add(x, y); -} - -/* -Enter the numbers to be added:23 24 -The Summation is: 47 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Perform Encoding of a Message Using Matrix Multiplication.cpp b/c++/11_Numerical_Problems/C++ Program to Perform Encoding of a Message Using Matrix Multiplication.cpp deleted file mode 100644 index 8ea6a37..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Perform Encoding of a Message Using Matrix Multiplication.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - int a[10][10], b[10][10], c[10][10]; - int x, y, i, j; - cout << "\nEnter the number of rows and columns for Message Matrix:\n\n"; - cin >> x >> y; - // x denotes number rows in matrix A - // y denotes number columns in matrix A - cout << "\n\nEnter elements for Matrix :::\n\n"; - for (i = 0; i < x; i++) - { - for (j = 0; j < y; j++) - { - cin >> a[i][j]; - } - cout << "\n"; - } - cout << "\n\nMatrix :\n\n"; - for (i = 0; i < x; i++) - { - for (j = 0; j < y; j++) - { - cout << "\t" << a[i][j]; - } - cout << "\n\n"; - } - for (i = 0; i < y; i++) - { - for (j = 0; j < x; j++) - { - b[i][j]=x+y; - } - cout << "\n"; - } - for (i = 0; i < x; i++) - { - for (j = 0; j < x; j++) - { - c[i][j] = 0; - for (int k = 0; k < y; k++) - { - c[i][j] = c[i][j] + a[i][k] * b[k][j]; - } - } - } - cout - << "\n-----------------------------------------------------------\n"; - cout << "\n\nEncoded Matrix :\n\n"; - for (i = 0; i < x; i++) - { - for (j = 0; j < x; j++) - { - cout << "\t" << c[i][j]; - } - cout << "\n\n"; - } - getch(); - return 0; -} - -/* -Enter the number of rows and columns for Message Matrix: -2 2 - -Enter elements for Matrix ::: -1 2 -3 4 -Matrix : - 1 2 - 3 4 ------------------------------------------------------------ -Encoded Matrix : - 12 12 - 28 28 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Perform LU Decomposition of any Matrix.cpp b/c++/11_Numerical_Problems/C++ Program to Perform LU Decomposition of any Matrix.cpp deleted file mode 100644 index 1b64da6..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Perform LU Decomposition of any Matrix.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* -This is a C++ Program to perform LU Decomposition of any matrix. In numerical analysis, LU decomposition (where ‘LU’ stands for ‘Lower Upper’, and also called LU factorization) factors a matrix as the product of a lower triangular matrix and an upper triangular matrix. The product sometimes includes a permutation matrix as well. The LU decomposition can be viewed as the matrix form of Gaussian elimination. Computers usually solve square systems of linear equations using the LU decomposition, and it is also a key step when inverting a matrix, or computing the determinant of a matrix -*/ - -#include -#include - -using namespace std; - -int main(int argc, char **argv) -{ - void lu(float[][10], float[][10], float[][10], int n); - void output(float[][10], int); - float a[10][10], l[10][10], u[10][10]; - int n = 0, i = 0, j = 0; - cout << "Enter size of 2d array(Square matrix) : "; - cin >> n; - for (i = 0; i < n; i++) - { - for (j = 0; j < n; j++) - { - cout << "Enter values no:" << i << ", " << j << ": "; - cin >> a[i][j]; - } - } - lu(a, l, u, n); - cout << "\nL Decomposition\n\n"; - output(l, n); - cout << "\nU Decomposition\n\n"; - output(u, n); - return 0; -} -void lu(float a[][10], float l[][10], float u[][10], int n) -{ - int i = 0, j = 0, k = 0; - for (i = 0; i < n; i++) - { - for (j = 0; j < n; j++) - { - if (j < i) - l[j][i] = 0; - else - { - l[j][i] = a[j][i]; - for (k = 0; k < i; k++) - { - l[j][i] = l[j][i] - l[j][k] * u[k][i]; - } - } - } - for (j = 0; j < n; j++) - { - if (j < i) - u[i][j] = 0; - else if (j == i) - u[i][j] = 1; - else - { - u[i][j] = a[i][j] / l[i][i]; - for (k = 0; k < i; k++) - { - u[i][j] = u[i][j] - ((l[i][k] * u[k][j]) / l[i][i]); - } - } - } - } -} -void output(float x[][10], int n) -{ - int i = 0, j = 0; - for (i = 0; i < n; i++) - { - for (j = 0; j < n; j++) - { - printf("%f ", x[i][j]); - } - cout << "\n"; - } -} - -/* -Enter size of 2d array(Square matrix) : 3 -Enter values no:0, 0: 1 -Enter values no:0, 1: 1 -Enter values no:0, 2: -1 -Enter values no:1, 0: 2 -Enter values no:1, 1: -1 -Enter values no:1, 2: 3 -Enter values no:2, 0: 3 -Enter values no:2, 1: 1 -Enter values no:2, 2: -1 - -L Decomposition - -1.000000 0.000000 0.000000 -2.000000 -3.000000 0.000000 -3.000000 -2.000000 -1.333333 - -U Decomposition - -1.000000 1.000000 -1.000000 -0.000000 1.000000 -1.666667 -0.000000 0.000000 1.000000 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Perform Matrix Multiplication.cpp b/c++/11_Numerical_Problems/C++ Program to Perform Matrix Multiplication.cpp deleted file mode 100644 index 91767f7..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Perform Matrix Multiplication.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include -#include -using namespace std; -int main() -{ - int a[10][10], b[10][10], c[10][10]; - int x, y, i, j, m, n; - cout << "\nEnter the number of rows and columns for Matrix A:::\n\n"; - cin >> x >> y; - // x denotes number rows in matrix A - // y denotes number columns in matrix A - cout << "\n\nEnter elements for Matrix A :::\n\n"; - for (i = 0; i < x; i++) - { - for (j = 0; j < y; j++) - { - cin >> a[i][j]; - } - cout << "\n"; - } - cout << "\n\nMatrix A :\n\n"; - for (i = 0; i < x; i++) - { - for (j = 0; j < y; j++) - { - cout << "\t" << a[i][j]; - } - cout << "\n\n"; - } - cout << "\n-----------------------------------------------------------\n"; - cout << "\nEnter the number of rows and columns for Matrix B:::\n\n"; - cin >> m >> n; - // m denotes number rows in matrix B - // n denotes number columns in matrix B - cout << "\n\nEnter elements for Matrix B :::\n\n"; - for (i = 0; i < m; i++) - { - for (j = 0; j < n; j++) - { - cin >> b[i][j]; - } - cout << "\n"; - } - cout << "\n\nMatrix B :\n\n"; - for (i = 0; i < m; i++) - { - for (j = 0; j < n; j++) - { - cout << "\t" << b[i][j]; - } - cout << "\n\n"; - } - if (y == m) - { - for (i = 0; i < x; i++) - { - for (j = 0; j < n; j++) - { - c[i][j] = 0; - for (int k = 0; k < m; k++) - { - c[i][j] = c[i][j] + a[i][k] * b[k][j]; - } - } - } - cout - << "\n-----------------------------------------------------------\n"; - cout << "\n\nMultiplication of Matrix A and Matrix B :\n\n"; - for (i = 0; i < x; i++) - { - for (j = 0; j < n; j++) - { - cout << "\t" << c[i][j]; - } - cout << "\n\n"; - } - } - else - { - cout << "\n\nMultiplication is not possible"; - } - getch(); - return 0; -} - -/* -Enter the number of rows and columns for Matrix A::: -2 2 - -Enter elements for Matrix A ::: -1 2 -3 4 - -Matrix A : - 1 2 - 3 4 ------------------------------------------------------------ -Enter the number of rows and columns for Matrix B::: -2 2 - -Enter elements for Matrix B ::: -4 5 -6 7 - -Matrix B : - 4 5 - 6 7 ------------------------------------------------------------ - -Multiplication of Matrix A and Matrix B : - 16 19 - 36 43 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Perform Optimal Paranthesization Using Dynamic Programming.cpp b/c++/11_Numerical_Problems/C++ Program to Perform Optimal Paranthesization Using Dynamic Programming.cpp deleted file mode 100644 index 52ff259..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Perform Optimal Paranthesization Using Dynamic Programming.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include - -using namespace std; - -// Matrix Ai has dimension p[i-1] x p[i] for i = 1..n - -int MatrixChainOrder(int p[], int n) -{ - /* For simplicity of the program, one extra row and one extra column are - allocated in m[][]. 0th row and 0th column of m[][] are not used */ - int m[n][n]; - int s[n][n]; - int i, j, k, L, q; - /* m[i,j] = Minimum number of scalar multiplications needed to compute - the matrix A[i]A[i+1]...A[j] = A[i..j] where dimention of A[i] is - p[i-1] x p[i] */ - // cost is zero when multiplying one matrix. - for (i = 1; i < n; i++) - m[i][i] = 0; - // L is chain length. - for (L = 2; L < n; L++) - { - for (i = 1; i <= n - L + 1; i++) - { - j = i + L - 1; - m[i][j] = INT_MAX; - for (k = i; k <= j - 1; k++) - { - // q = cost/scalar multiplications - q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]; - if (q < m[i][j]) - { - m[i][j] = q; - s[i][j] = k; - } - } - } - } - return m[1][n - 1]; -} -int main() -{ - cout - << "Enter the array p[], which represents the chain of matrices such that the ith matrix Ai is of dimension p[i-1] x p[i]"; - cout << "Enter the total length:"; - int n; - cin >> n; - int array[n]; - cout << "Enter the dimensions: "; - for (int var = 0; var < n; ++var) - { - cin >> array[var]; - } - cout << "Minimum number of multiplications is: " << MatrixChainOrder(array, - n); - return 0; -} - -/* - -Enter the array p[], which represents the chain of matrices such that the ith matrix Ai is of dimension p[i-1] x p[i]Enter the total length:4 -Enter the dimensions: 2 4 3 5 -Minimum number of multiplications is: 54 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Perform Partition of an Integer in All Possible Ways.cpp b/c++/11_Numerical_Problems/C++ Program to Perform Partition of an Integer in All Possible Ways.cpp deleted file mode 100644 index bcb04bb..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Perform Partition of an Integer in All Possible Ways.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -using namespace std; - -// A utility function to print an array p[] of size 'n' -void printArray(int p[], int n) -{ - for (int i = 0; i < n; i++) - cout << p[i] << " "; - cout << endl; -} - -void printAllUniqueParts(int n) -{ - int p[n]; // An array to store a partition - int k = 0; // Index of last element in a partition - p[k] = n; // Initialize first partition as number itself - // This loop first prints current partition, then generates next - // partition. The loop stops when the current partition has all 1s - while (true) - { - // print current partition - printArray(p, k + 1); - // Generate next partition - // Find the rightmost non-one value in p[]. Also, update the - // rem_val so that we know how much value can be accommodated - int rem_val = 0; - while (k >= 0 && p[k] == 1) - { - rem_val += p[k]; - k--; - } - // if k < 0, all the values are 1 so there are no more partitions - if (k < 0) - return; - // Decrease the p[k] found above and adjust the rem_val - p[k]--; - rem_val++; - // If rem_val is more, then the sorted order is violeted. Divide - // rem_val in differnt values of size p[k] and copy these values at - // different positions after p[k] - while (rem_val > p[k]) - { - p[k + 1] = p[k]; - rem_val = rem_val - p[k]; - k++; - } - // Copy rem_val to next position and increment position - p[k + 1] = rem_val; - k++; - } -} - -// Driver program to test above functions -int main() -{ - cout << "All Unique Partitions of 2 \n"; - printAllUniqueParts(2); - cout << "\nAll Unique Partitions of 3 \n"; - printAllUniqueParts(3); - cout << "\nAll Unique Partitions of 4 \n"; - printAllUniqueParts(4); - return 0; -} - -/* -All Unique Partitions of 2 -2 -1 1 - -All Unique Partitions of 3 -3 -2 1 -1 1 1 - -All Unique Partitions of 4 -4 -3 1 -2 2 -2 1 1 -1 1 1 1 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Perform the Unique Factorization of a Given Number.cpp b/c++/11_Numerical_Problems/C++ Program to Perform the Unique Factorization of a Given Number.cpp deleted file mode 100644 index 9c998a3..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Perform the Unique Factorization of a Given Number.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include -using namespace std; - -// A utility function to print an array p[] of size 'n' -void printArray(int p[], int n) -{ - for (int i = 0; i < n; i++) - cout << p[i] << " "; - cout << endl; -} - -void printAllUniqueParts(int n) -{ - int p[n]; // An array to store a partition - int k = 0; // Index of last element in a partition - p[k] = n; // Initialize first partition as number itself - // This loop first prints current partition, then generates next - // partition. The loop stops when the current partition has all 1s - while (true) - { - // print current partition - printArray(p, k + 1); - // Generate next partition - // Find the rightmost non-one value in p[]. Also, update the - // rem_val so that we know how much value can be accommodated - int rem_val = 0; - while (k >= 0 && p[k] == 1) - { - rem_val += p[k]; - k--; - } - // if k < 0, all the values are 1 so there are no more partitions - if (k < 0) - return; - // Decrease the p[k] found above and adjust the rem_val - p[k]--; - rem_val++; - // If rem_val is more, then the sorted order is violeted. Divide - // rem_val in differnt values of size p[k] and copy these values at - // different positions after p[k] - while (rem_val > p[k]) - { - p[k + 1] = p[k]; - rem_val = rem_val - p[k]; - k++; - } - // Copy rem_val to next position and increment position - p[k + 1] = rem_val; - k++; - } -} - -// Driver program to test above functions -int main() -{ - cout << "All Unique Partitions of 2 \n"; - printAllUniqueParts(2); - cout << "\nAll Unique Partitions of 3 \n"; - printAllUniqueParts(3); - cout << "\nAll Unique Partitions of 4 \n"; - printAllUniqueParts(4); - return 0; -} - -/* - -All Unique Partitions of 2 -2 -1 1 - -All Unique Partitions of 3 -3 -2 1 -1 1 1 - -All Unique Partitions of 4 -4 -3 1 -2 2 -2 1 1 -1 1 1 1 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Represent Linear Equations in Matrix Form.cpp b/c++/11_Numerical_Problems/C++ Program to Represent Linear Equations in Matrix Form.cpp deleted file mode 100644 index 3000509..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Represent Linear Equations in Matrix Form.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include - -using namespace std; - -int main(void) -{ - char var[] = { 'x', 'y', 'z', 'w' }; - cout << "Enter the number of variables in the equations: "; - int n; - cin >> n; - cout << "\nEnter the coefficients of each variable for each equations"; - cout << "\nax + by + cz + ... = d"; - int mat[n][n]; - int constants[n][1]; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { - cin >> mat[i][j]; - } - cin >> constants[i][0]; - } - cout << "Matrix representation is: "; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { - cout << " " << mat[i][j]; - } - cout << " " << var[i]; - cout << " = " << constants[i][0]; - cout << "\n"; - } - return 0; -} - -/* -Enter the number of variables in the equations: 3 - -Enter the coefficients of each variable for each equations -ax + by + cz + ... = d -1 2 3 4 -1 2 6 8 -2 3 9 8 -Matrix representation is: - 1 2 3 x = 4 - 1 2 6 y = 8 - 2 3 9 z = 8 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Solve Knapsack Problem Using Dynamic Programming.cpp b/c++/11_Numerical_Problems/C++ Program to Solve Knapsack Problem Using Dynamic Programming.cpp deleted file mode 100644 index a6171e2..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Solve Knapsack Problem Using Dynamic Programming.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/*This is a C++ Program to knapsack problem using dynamic programming. The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a mass and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items.*/ - -// A Dynamic Programming based solution for 0-1 Knapsack problem -#include - -using namespace std; - -// A utility function that returns maximum of two integers -int max(int a, int b) -{ - return (a > b) ? a : b; -} - -// Returns the maximum value that can be put in a knapsack of capacity W -int knapSack(int W, int wt[], int val[], int n) -{ - int i, w; - int K[n + 1][W + 1]; - // Build table K[][] in bottom up manner - for (i = 0; i <= n; i++) - { - for (w = 0; w <= W; w++) - { - if (i == 0 || w == 0) - K[i][w] = 0; - else if (wt[i - 1] <= w) - K[i][w] - = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]); - else - K[i][w] = K[i - 1][w]; - } - } - return K[n][W]; -} - -int main() -{ - cout << "Enter the number of items in a Knapsack:"; - int n, W; - cin >> n; - int val[n], wt[n]; - for (int i = 0; i < n; i++) - { - cout << "Enter value and weight for item " << i << ":"; - cin >> val[i]; - cin >> wt[i]; - } - // int val[] = { 60, 100, 120 }; - // int wt[] = { 10, 20, 30 }; - // int W = 50; - cout << "Enter the capacity of knapsack"; - cin >> W; - cout << knapSack(W, wt, val, n); - return 0; -} - -/* -Enter the number of items in a Knapsack:5 -Enter value and weight for item 0:11 111 -Enter value and weight for item 1:22 121 -Enter value and weight for item 2:33 131 -Enter value and weight for item 3:44 141 -Enter value and weight for item 4:55 151 -Enter the capacity of knapsack 300 -99 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Solve any Linear Equation in One Variable.cpp b/c++/11_Numerical_Problems/C++ Program to Solve any Linear Equation in One Variable.cpp deleted file mode 100644 index edc65a7..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Solve any Linear Equation in One Variable.cpp +++ /dev/null @@ -1,647 +0,0 @@ -#if !defined(MATRIX_H) -#define MATRIX_H -#include -#include -#include -#include -#include - -class CMatrix -{ -private: - int m_rows; - int m_cols; - char m_name[128]; - CMatrix(); -public: - double **m_pData; - CMatrix(const char *name, int rows, int cols) : - m_rows(rows), m_cols(cols) - { - strcpy(m_name, name); - m_pData = new double*[m_rows]; - for (int i = 0; i < m_rows; i++) - m_pData[i] = new double[m_cols]; - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - m_pData[i][j] = 0.0; - } - } - } - CMatrix(const CMatrix &other) - { - strcpy(m_name, other.m_name); - m_rows = other.m_rows; - m_cols = other.m_cols; - m_pData = new double*[m_rows]; - for (int i = 0; i < m_rows; i++) - m_pData[i] = new double[m_cols]; - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - m_pData[i][j] = other.m_pData[i][j]; - } - } - } - ~CMatrix() - { - for (int i = 0; i < m_rows; i++) - delete[] m_pData[i]; - delete[] m_pData; - m_rows = m_cols = 0; - } - void SetName(const char *name) - { - strcpy(m_name, name); - } - const char* GetName() const - { - return m_name; - } - void GetInput() - { - std::cin >> *this; - } - void FillSimulatedInput() - { - static int factor1 = 1, factor2 = 2; - std::cout << "\n\nEnter Input For Matrix : " << m_name << " Rows: " - << m_rows << " Cols: " << m_cols << "\n"; - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - std::cout << "Input For Row: " << i + 1 << " Col: " << j - + 1 << " = "; - int data = ((i + 1) * factor1) + (j + 1) * factor2; - m_pData[i][j] = data / 10.2; - std::cout << m_pData[i][j] << "\n"; - factor1 += (rand() % 4); - factor2 += (rand() % 3); - } - std::cout << "\n"; - } - std::cout << "\n"; - } - double Determinant() - { - double det = 0; - double **pd = m_pData; - switch (m_rows) - { - case 2: - { - det = pd[0][0] * pd[1][1] - pd[0][1] * pd[1][0]; - return det; - } - break; - case 3: - { - /*** - a b c - d e f - g h i - - a b c a b c - d e f d e f - g h i g h i - - - // det (A) = aei + bfg + cdh - afh - bdi - ceg. - ***/ - double a = pd[0][0]; - double b = pd[0][1]; - double c = pd[0][2]; - double d = pd[1][0]; - double e = pd[1][1]; - double f = pd[1][2]; - double g = pd[2][0]; - double h = pd[2][1]; - double i = pd[2][2]; - double det = (a * e * i + b * f * g + c * d * h); // - a*f*h - b*d*i - c*e*g); - det = det - a * f * h; - det = det - b * d * i; - det = det - c * e * g; - //std::cout << *this; - //std::cout << "deter: " << det << " \n"; - return det; - } - break; - case 4: - { - CMatrix *temp[4]; - for (int i = 0; i < 4; i++) - temp[i] = new CMatrix("", 3, 3); - for (int k = 0; k < 4; k++) - { - for (int i = 1; i < 4; i++) - { - int j1 = 0; - for (int j = 0; j < 4; j++) - { - if (k == j) - continue; - temp[k]->m_pData[i - 1][j1++] - = this->m_pData[i][j]; - } - } - } - double det = this->m_pData[0][0] * temp[0]->Determinant() - - this->m_pData[0][1] * temp[1]->Determinant() - + this->m_pData[0][2] * temp[2]->Determinant() - - this->m_pData[0][3] * temp[3]->Determinant(); - return det; - } - break; - case 5: - { - CMatrix *temp[5]; - for (int i = 0; i < 5; i++) - temp[i] = new CMatrix("", 4, 4); - for (int k = 0; k < 5; k++) - { - for (int i = 1; i < 5; i++) - { - int j1 = 0; - for (int j = 0; j < 5; j++) - { - if (k == j) - continue; - temp[k]->m_pData[i - 1][j1++] - = this->m_pData[i][j]; - } - } - } - double det = this->m_pData[0][0] * temp[0]->Determinant() - - this->m_pData[0][1] * temp[1]->Determinant() - + this->m_pData[0][2] * temp[2]->Determinant() - - this->m_pData[0][3] * temp[3]->Determinant() - + this->m_pData[0][4] * temp[4]->Determinant(); - return det; - } - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - default: - { - int DIM = m_rows; - CMatrix **temp = new CMatrix*[DIM]; - for (int i = 0; i < DIM; i++) - temp[i] = new CMatrix("", DIM - 1, DIM - 1); - for (int k = 0; k < DIM; k++) - { - for (int i = 1; i < DIM; i++) - { - int j1 = 0; - for (int j = 0; j < DIM; j++) - { - if (k == j) - continue; - temp[k]->m_pData[i - 1][j1++] - = this->m_pData[i][j]; - } - } - } - double det = 0; - for (int k = 0; k < DIM; k++) - { - if ((k % 2) == 0) - det = det + (this->m_pData[0][k] - * temp[k]->Determinant()); - else - det = det - (this->m_pData[0][k] - * temp[k]->Determinant()); - } - for (int i = 0; i < DIM; i++) - delete temp[i]; - delete[] temp; - return det; - } - break; - } - } - CMatrix& operator =(const CMatrix &other) - { - if (this->m_rows != other.m_rows || this->m_cols != other.m_cols) - { - std::cout - << "WARNING: Assignment is taking place with by changing the number of rows and columns of the matrix"; - } - for (int i = 0; i < m_rows; i++) - delete[] m_pData[i]; - delete[] m_pData; - m_rows = m_cols = 0; - strcpy(m_name, other.m_name); - m_rows = other.m_rows; - m_cols = other.m_cols; - m_pData = new double*[m_rows]; - for (int i = 0; i < m_rows; i++) - m_pData[i] = new double[m_cols]; - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - m_pData[i][j] = other.m_pData[i][j]; - } - } - return *this; - } - CMatrix CoFactor() - { - CMatrix cofactor("COF", m_rows, m_cols); - if (m_rows != m_cols) - return cofactor; - if (m_rows < 2) - return cofactor; - else if (m_rows == 2) - { - cofactor.m_pData[0][0] = m_pData[1][1]; - cofactor.m_pData[0][1] = -m_pData[1][0]; - cofactor.m_pData[1][0] = -m_pData[0][1]; - cofactor.m_pData[1][1] = m_pData[0][0]; - return cofactor; - } - else if (m_rows >= 3) - { - int DIM = m_rows; - CMatrix ***temp = new CMatrix**[DIM]; - for (int i = 0; i < DIM; i++) - temp[i] = new CMatrix*[DIM]; - for (int i = 0; i < DIM; i++) - for (int j = 0; j < DIM; j++) - temp[i][j] = new CMatrix("", DIM - 1, DIM - 1); - for (int k1 = 0; k1 < DIM; k1++) - { - for (int k2 = 0; k2 < DIM; k2++) - { - int i1 = 0; - for (int i = 0; i < DIM; i++) - { - int j1 = 0; - for (int j = 0; j < DIM; j++) - { - if (k1 == i || k2 == j) - continue; - temp[k1][k2]->m_pData[i1][j1++] - = this->m_pData[i][j]; - } - if (k1 != i) - i1++; - } - } - } - bool flagPositive = true; - for (int k1 = 0; k1 < DIM; k1++) - { - flagPositive = ((k1 % 2) == 0); - for (int k2 = 0; k2 < DIM; k2++) - { - if (flagPositive == true) - { - cofactor.m_pData[k1][k2] - = temp[k1][k2]->Determinant(); - flagPositive = false; - } - else - { - cofactor.m_pData[k1][k2] - = -temp[k1][k2]->Determinant(); - flagPositive = true; - } - } - } - for (int i = 0; i < DIM; i++) - for (int j = 0; j < DIM; j++) - delete temp[i][j]; - for (int i = 0; i < DIM; i++) - delete[] temp[i]; - delete[] temp; - } - return cofactor; - } - CMatrix Adjoint() - { - CMatrix cofactor("COF", m_rows, m_cols); - CMatrix adj("ADJ", m_rows, m_cols); - if (m_rows != m_cols) - return adj; - cofactor = this->CoFactor(); - // adjoint is transpose of a cofactor of a matrix - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - adj.m_pData[j][i] = cofactor.m_pData[i][j]; - } - } - return adj; - } - CMatrix Transpose() - { - CMatrix trans("TR", m_cols, m_rows); - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - trans.m_pData[j][i] = m_pData[i][j]; - } - } - return trans; - } - CMatrix Inverse() - { - CMatrix cofactor("COF", m_rows, m_cols); - CMatrix inv("INV", m_rows, m_cols); - if (m_rows != m_cols) - return inv; - // to find out Determinant - double det = Determinant(); - cofactor = this->CoFactor(); - // inv = transpose of cofactor / Determinant - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - inv.m_pData[j][i] = cofactor.m_pData[i][j] / det; - } - } - return inv; - } - CMatrix operator +(const CMatrix &other) - { - if (this->m_rows != other.m_rows || this->m_cols != other.m_cols) - { - std::cout - << "Addition could not take place because number of rows and columns are different between the two matrices"; - return *this; - } - CMatrix result("", m_rows, m_cols); - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - result.m_pData[i][j] = this->m_pData[i][j] - + other.m_pData[i][j]; - } - } - return result; - } - CMatrix operator -(const CMatrix &other) - { - if (this->m_rows != other.m_rows || this->m_cols != other.m_cols) - { - std::cout - << "Subtraction could not take place because number of rows and columns are different between the two matrices"; - return *this; - } - CMatrix result("", m_rows, m_cols); - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - result.m_pData[i][j] = this->m_pData[i][j] - - other.m_pData[i][j]; - } - } - return result; - } - CMatrix operator *(const CMatrix &other) - { - if (this->m_cols != other.m_rows) - { - std::cout - << "Multiplication could not take place because number of columns of 1st Matrix and number of rows in 2nd Matrix are different"; - return *this; - } - CMatrix result("", this->m_rows, other.m_cols); - for (int i = 0; i < this->m_rows; i++) - { - for (int j = 0; j < other.m_cols; j++) - { - for (int k = 0; k < this->m_cols; k++) - { - result.m_pData[i][j] += this->m_pData[i][k] - * other.m_pData[k][j]; - } - } - } - return result; - } - bool operator ==(const CMatrix &other) - { - if (this->m_rows != other.m_rows || this->m_cols != other.m_cols) - { - std::cout - << "Comparision could not take place because number of rows and columns are different between the two matrices"; - return false; - } - CMatrix result("", m_rows, m_cols); - bool bEqual = true; - for (int i = 0; i < m_rows; i++) - { - for (int j = 0; j < m_cols; j++) - { - if (this->m_pData[i][j] != other.m_pData[i][j]) - bEqual = false; - } - } - return bEqual; - } - friend std::istream& operator >>(std::istream &is, CMatrix &m); - friend std::ostream& operator <<(std::ostream &os, const CMatrix &m); -}; -std::istream& operator >>(std::istream &is, CMatrix &m) -{ - std::cout << "\n\nEnter Input For Matrix : " << m.m_name << " Rows: " - << m.m_rows << " Cols: " << m.m_cols << "\n"; - for (int i = 0; i < m.m_rows; i++) - { - for (int j = 0; j < m.m_cols; j++) - { - std::cout << "Input For Row: " << i + 1 << " Col: " << j + 1 - << " = "; - is >> m.m_pData[i][j]; - } - std::cout << "\n"; - } - std::cout << "\n"; - return is; -} -std::ostream& operator <<(std::ostream &os, const CMatrix &m) -{ - os << "\n\nMatrix : " << m.m_name << " Rows: " << m.m_rows << " Cols: " - << m.m_cols << "\n\n"; - for (int i = 0; i < m.m_rows; i++) - { - os << " | "; - for (int j = 0; j < m.m_cols; j++) - { - char buf[32]; - double data = m.m_pData[i][j]; - if (m.m_pData[i][j] > -0.00001 && m.m_pData[i][j] < 0.00001) - data = 0; - sprintf(buf, "%10.2lf ", data); - os << buf; - } - os << "|\n"; - } - os << "\n\n"; - return os; -} -#endif -int main() -{ - CMatrix a("A", 6, 6); - CMatrix b("B", 6, 1); - a.FillSimulatedInput(); - b.FillSimulatedInput(); - std::cout << a << "\n Determinant : "; - std::cout << a.Determinant() << "\n"; - std::cout << b << "\n Determinant : "; - std::cout << b.Determinant() << "\n"; - CMatrix ainv = a.Inverse(); - CMatrix q = a * ainv; - q.SetName("A * A'"); - std::cout << q << "\n"; - CMatrix x = ainv * b; - x.SetName("X"); - std::cout << x << "\n"; - CMatrix y = a * x; // we will get B - y.SetName("Y"); - std::cout << y << "\n"; - return 0; -} - -/* - -Enter Input For Matrix : A Rows: 6 Cols: 6 -Input For Row: 1 Col: 1 = 0.294118 -Input For Row: 1 Col: 2 = 0.980392 -Input For Row: 1 Col: 3 = 1.86275 -Input For Row: 1 Col: 4 = 2.84314 -Input For Row: 1 Col: 5 = 3.62745 -Input For Row: 1 Col: 6 = 5.58824 - -Input For Row: 2 Col: 1 = 2.94118 -Input For Row: 2 Col: 2 = 4.11765 -Input For Row: 2 Col: 3 = 5.88235 -Input For Row: 2 Col: 4 = 8.43137 -Input For Row: 2 Col: 5 = 10.3922 -Input For Row: 2 Col: 6 = 12.3529 - -Input For Row: 3 Col: 1 = 8.13725 -Input For Row: 3 Col: 2 = 9.70588 -Input For Row: 3 Col: 3 = 12.0588 -Input For Row: 3 Col: 4 = 15.098 -Input For Row: 3 Col: 5 = 17.8431 -Input For Row: 3 Col: 6 = 20.5882 - -Input For Row: 4 Col: 1 = 14.902 -Input For Row: 4 Col: 2 = 18.2353 -Input For Row: 4 Col: 3 = 21.4706 -Input For Row: 4 Col: 4 = 24.7059 -Input For Row: 4 Col: 5 = 27.549 -Input For Row: 4 Col: 6 = 31.1765 - -Input For Row: 5 Col: 1 = 24.902 -Input For Row: 5 Col: 2 = 27.9412 -Input For Row: 5 Col: 3 = 32.451 -Input For Row: 5 Col: 4 = 36.0784 -Input For Row: 5 Col: 5 = 39.7059 -Input For Row: 5 Col: 6 = 43.9216 - -Input For Row: 6 Col: 1 = 36.3725 -Input For Row: 6 Col: 2 = 39.6078 -Input For Row: 6 Col: 3 = 43.8235 -Input For Row: 6 Col: 4 = 47.2549 -Input For Row: 6 Col: 5 = 51.3725 -Input For Row: 6 Col: 6 = 55.2941 - - - - -Enter Input For Matrix : B Rows: 6 Cols: 1 -Input For Row: 1 Col: 1 = 9.41176 - -Input For Row: 2 Col: 1 = 15.7843 - -Input For Row: 3 Col: 1 = 22.7451 - -Input For Row: 4 Col: 1 = 29.902 - -Input For Row: 5 Col: 1 = 37.1569 - -Input For Row: 6 Col: 1 = 44.6078 - - - - -Matrix : A Rows: 6 Cols: 6 - - | 0.29 0.98 1.86 2.84 3.63 5.59 | - | 2.94 4.12 5.88 8.43 10.39 12.35 | - | 8.14 9.71 12.06 15.10 17.84 20.59 | - | 14.90 18.24 21.47 24.71 27.55 31.18 | - | 24.90 27.94 32.45 36.08 39.71 43.92 | - | 36.37 39.61 43.82 47.25 51.37 55.29 | - - - - Determinant : -11.9339 - - -Matrix : B Rows: 6 Cols: 1 - - | 9.41 | - | 15.78 | - | 22.75 | - | 29.90 | - | 37.16 | - | 44.61 | - - - - Determinant : -1.#IND - - -Matrix : A * A' Rows: 6 Cols: 6 - - | 1.00 0.00 0.00 0.00 0.00 0.00 | - | 0.00 1.00 0.00 0.00 0.00 0.00 | - | 0.00 0.00 1.00 0.00 0.00 0.00 | - | 0.00 0.00 0.00 1.00 0.00 0.00 | - | 0.00 0.00 0.00 0.00 1.00 0.00 | - | 0.00 0.00 0.00 0.00 0.00 1.00 | - - - - - -Matrix : X Rows: 6 Cols: 1 - - | 0.82 | - | 3.47 | - | -9.38 | - | 7.71 | - | -5.76 | - | 3.98 | - - - - - -Matrix : Y Rows: 6 Cols: 1 - - | 9.41 | - | 15.78 | - | 22.75 | - | 29.90 | - | 37.16 | - | 44.61 | \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Solve the 0-1 Knapsack Problem.cpp b/c++/11_Numerical_Problems/C++ Program to Solve the 0-1 Knapsack Problem.cpp deleted file mode 100644 index 4c43e45..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Solve the 0-1 Knapsack Problem.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/*This is a C++ Program to solve 0-1 knapsack problem. The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a mass and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items.*/ - -#include -#include -#include - -using namespace std; - -// A utility function that returns maximum of two integers -int max(int a, int b) -{ - return (a > b) ? a : b; -} - -// Returns the maximum value that can be put in a knapsack of capacity W -int knapSack(int W, int wt[], int val[], int n) -{ - // Base Case - if (n == 0 || W == 0) - return 0; - // If weight of the nth item is more than Knapsack capacity W, then - // this item cannot be included in the optimal solution - if (wt[n - 1] > W) - return knapSack(W, wt, val, n - 1); - // Return the maximum of two cases: (1) nth item included (2) not included - else - return max(val[n - 1] + knapSack(W - wt[n - 1], wt, val, n - 1), - knapSack(W, wt, val, n - 1)); -} - -// Driver program to test above function -int main() -{ - cout << "Enter the number of items in a Knapsack:"; - int n, W; - cin >> n; - int val[n], wt[n]; - for (int i = 0; i < n; i++) - { - cout << "Enter value and weight for item " << i << ":"; - cin >> val[i]; - cin >> wt[i]; - } - // int val[] = { 60, 100, 120 }; - // int wt[] = { 10, 20, 30 }; - // int W = 50; - cout << "Enter the capacity of knapsack"; - cin >> W; - cout << knapSack(W, wt, val, n); - return 0; -} - -/* -Enter the number of items in a Knapsack:5 -Enter value and weight for item 0:11 111 -Enter value and weight for item 1:22 121 -Enter value and weight for item 2:33 131 -Enter value and weight for item 3:44 141 -Enter value and weight for item 4:55 151 -Enter the capacity of knapsack 300 -99 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Solve the Fractional Knapsack Problem.cpp b/c++/11_Numerical_Problems/C++ Program to Solve the Fractional Knapsack Problem.cpp deleted file mode 100644 index 1dd73ef..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Solve the Fractional Knapsack Problem.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*This is a C++ Program to solve fractional knapsack. The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a mass and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items.*/ - -/* program to implement fractional knapsack problem using greedy programming */ -#include -using namespace std; -int main() -{ - int array[2][100], n, w, i, curw, used[100], maxi = -1, totalprofit = 0; - //input number of objects - cout << "Enter number of objects: "; - cin >> n; - //input max weight of knapsack - cout << "Enter the weight of the knapsack: "; - cin >> w; - /* Array's first row is to store weights - second row is to store profits */ - for (i = 0; i < n; i++) - { - cin >> array[0][i] >> array[1][i]; - } - for (i = 0; i < n; i++) - { - used[i] = 0; - } - curw = w; - //loop until knapsack is full - while (curw >= 0) - { - maxi = -1; - //loop to find max profit object - for (i = 0; i < n; i++) - { - if ((used[i] == 0) && ((maxi == -1) || (((float) array[1][i] - / (float) array[0][i]) > ((float) array[1][maxi] - / (float) array[0][maxi])))) - { - maxi = i; - } - } - used[maxi] = 1; - //decrease current wight - curw -= array[0][maxi]; - //increase total profit - totalprofit += array[1][maxi]; - if (curw >= 0) - { - cout << "\nAdded object " << maxi + 1 << " Weight: " - << array[0][maxi] << " Profit: " << array[1][maxi] - << " completely in the bag, Space left: " << curw; - } - else - { - cout << "\nAdded object " << maxi + 1 << " Weight: " - << (array[0][maxi] + curw) << " Profit: " - << (array[1][maxi] / array[0][maxi]) * (array[0][maxi] - + curw) << " partially in the bag, Space left: 0" - << " Weight added is: " << curw + array[0][maxi]; - totalprofit -= array[1][maxi]; - totalprofit += ((array[1][maxi] / array[0][maxi]) * (array[0][maxi] - + curw)); - } - } - //print total worth of objects filled in knapsack - cout << "\nBags filled with objects worth: " << totalprofit; - return 0; -} - -/* -Enter number of objects: 3 -Enter the weight of the knapsack: 50 -10 60 -20 100 -30 120 - -Added object 1 Weight: 10 Profit: 60 completely in the bag, Space left: 40 -Added object 2 Weight: 20 Profit: 100 completely in the bag, Space left: 20 -Added object 3 Weight: 20 Profit: 80 partially in the bag, Space left: 0 Weight added is: 20 -Bags filled with objects worth: 240 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to Use rand and srand Functions.cpp b/c++/11_Numerical_Problems/C++ Program to Use rand and srand Functions.cpp deleted file mode 100644 index f84ec50..0000000 --- a/c++/11_Numerical_Problems/C++ Program to Use rand and srand Functions.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main(int argc, char **argv) -{ - cout << "First number: " << rand() % 100; - srand(time(NULL)); - cout << "\nRandom number: " << rand() % 100; - srand(1); - cout << "\nAgain the first number: " << rand() % 100; - return 0; -} - -/* -First number: 41 -Random number: 98 -Again the first number: 41 \ No newline at end of file diff --git a/c++/11_Numerical_Problems/C++ Program to implement Gauss Jordan Elimination algorithm..cpp b/c++/11_Numerical_Problems/C++ Program to implement Gauss Jordan Elimination algorithm..cpp deleted file mode 100644 index 0444346..0000000 --- a/c++/11_Numerical_Problems/C++ Program to implement Gauss Jordan Elimination algorithm..cpp +++ /dev/null @@ -1,82 +0,0 @@ -/*/This is a C++ Program to implement Gauss Jordan Elimination algorithm. In linear algebra, Gaussian elimination (also known as row reduction) is an algorithm for solving systems of linear equations. It is usually understood as a sequence of operations performed on the associated matrix of coefficients. This method can also be used to find the rank of a matrix, to calculate the determinant of a matrix, and to calculate the inverse of an invertible square matrix.*/ - - -#include -#include - -using namespace std; - -int main() -{ - int i, j, k, n; - float a[10][10] = { 0 }, d; - cout << "No of equations ? "; - cin >> n; - cout << "Read all coefficients of matrix with b matrix too " << endl; - for (i = 1; i <= n; i++) - for (j = 1; j <= n; j++) - cin >> a[i][j]; - for (i = 1; i <= n; i++) - for (j = 1; j <= 2 * n; j++) - if (j == (i + n)) - a[i][j] = 1; - /************** partial pivoting **************/ - for (i = n; i > 1; i--) - { - if (a[i - 1][1] < a[i][1]) - for (j = 1; j <= n * 2; j++) - { - d = a[i][j]; - a[i][j] = a[i - 1][j]; - a[i - 1][j] = d; - } - } - cout << "pivoted output: " << endl; - for (i = 1; i <= n; i++) - { - for (j = 1; j <= n * 2; j++) - cout << a[i][j] << " "; - cout << endl; - } - /********** reducing to diagonal matrix ***********/ - for (i = 1; i <= n; i++) - { - for (j = 1; j <= n * 2; j++) - if (j != i) - { - d = a[j][i] / a[i][i]; - for (k = 1; k <= n * 2; k++) - a[j][k] -= a[i][k] * d; - } - } - /************** reducing to unit matrix *************/ - for (i = 1; i <= n; i++) - { - d = a[i][i]; - for (j = 1; j <= n * 2; j++) - a[i][j] = a[i][j] / d; - } - cout << "your solutions: " << endl; - for (i = 1; i <= n; i++) - { - for (j = n + 1; j <= n * 2; j++) - cout << a[i][j] << " "; - cout << endl; - } - getch(); - return 0; -} - -/*No of equations ? 3 -Read all coefficients of matrix with b matrix too -2 3 4 -5 6 3 -9 8 6 -pivoted output: -9 8 6 0 0 1 -2 3 4 1 0 0 -5 6 3 0 1 0 -your solutions: --0.292683 -0.341463 0.365854 -0.0731707 0.585366 -0.341463 -0.341463 -0.268293 0.0731708*/ \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Construct DFA from NFA.cpp b/c++/11_Sets_&_Strings/C++ Program to Construct DFA from NFA.cpp deleted file mode 100644 index 7131de3..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Construct DFA from NFA.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/*This is a C++ Program to convert NFA to DFA. A DFA (Deterministic Finite Automaton) is a finite state machine where from each state and a given input symbol, the next possible state is uniquely determined. On the other hand, an NFA (Non-Deterministic Finite Automaton) can move to several possible next states from a given state and a given input symbol. However, this does not add any more power to the machine. It still accepts the same set of languages, namely the regular languages. It is possible to convert an NFA to an equivalent DFA using the powerset construction. -The intuition behind this scheme is that an NFA can be in several possible states at any time. We can simulate it with a DFA whose states correspond to sets of states of the underlying NFA.*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define MAX_NFA_STATES 10 -#define MAX_ALPHABET_SIZE 10 -using namespace std; -// Representation of an NFA state -class NFAstate -{ -public: - int transitions[MAX_ALPHABET_SIZE][MAX_NFA_STATES]; - NFAstate() - { - for (int i = 0; i < MAX_ALPHABET_SIZE; i++) - for (int j = 0; j < MAX_NFA_STATES; j++) - transitions[i][j] = -1; - } -}*NFAstates; -// Representation of a DFA state -struct DFAstate -{ - bool finalState; - bitset constituentNFAstates; - bitset transitions[MAX_ALPHABET_SIZE]; - int symbolicTransitions[MAX_ALPHABET_SIZE]; -}; -set NFA_finalStates; -vector DFA_finalStates; -vector DFAstates; -queue incompleteDFAstates; -int N, M; // N -> No. of stattes, M -> Size of input alphabet -// finds the epsilon closure of the NFA state "state" and stores it into "closure" -void epsilonClosure(int state, bitset &closure) -{ - for (int i = 0; i < N && NFAstates[state].transitions[0][i] != -1; i++) - if (closure[NFAstates[state].transitions[0][i]] == 0) - { - closure[NFAstates[state].transitions[0][i]] = 1; - epsilonClosure(NFAstates[state].transitions[0][i], closure); - } -} -// finds the epsilon closure of a set of NFA states "state" and stores it into "closure" -void epsilonClosure(bitset state, - bitset &closure) -{ - for (int i = 0; i < N; i++) - if (state[i] == 1) - epsilonClosure(i, closure); -} -// returns a bitset representing the set of states the NFA could be in after moving -// from state X on input symbol A -void NFAmove(int X, int A, bitset &Y) -{ - for (int i = 0; i < N && NFAstates[X].transitions[A][i] != -1; i++) - Y[NFAstates[X].transitions[A][i]] = 1; -} -// returns a bitset representing the set of states the NFA could be in after moving -// from the set of states X on input symbol A -void NFAmove(bitset X, int A, bitset &Y) -{ - for (int i = 0; i < N; i++) - if (X[i] == 1) - NFAmove(i, A, Y); -} -int main() -{ - int i, j, X, Y, A, T, F, D; - // read in the underlying NFA - ifstream fin("NFA.txt"); - fin >> N >> M; - NFAstates = new NFAstate[N]; - fin >> F; - for (i = 0; i < F; i++) - { - fin >> X; - NFA_finalStates.insert(X); - } - fin >> T; - while (T--) - { - fin >> X >> A >> Y; - for (i = 0; i < Y; i++) - { - fin >> j; - NFAstates[X].transitions[A][i] = j; - } - } - fin.close(); - // construct the corresponding DFA - D = 1; - DFAstates.push_back(new DFAstate); - DFAstates[0]->constituentNFAstates[0] = 1; - epsilonClosure(0, DFAstates[0]->constituentNFAstates); - for (j = 0; j < N; j++) - if (DFAstates[0]->constituentNFAstates[j] == 1 && NFA_finalStates.find( - j) != NFA_finalStates.end()) - { - DFAstates[0]->finalState = true; - DFA_finalStates.push_back(0); - break; - } - incompleteDFAstates.push(0); - while (!incompleteDFAstates.empty()) - { - X = incompleteDFAstates.front(); - incompleteDFAstates.pop(); - for (i = 1; i <= M; i++) - { - NFAmove(DFAstates[X]->constituentNFAstates, i, - DFAstates[X]->transitions[i]); - epsilonClosure(DFAstates[X]->transitions[i], - DFAstates[X]->transitions[i]); - for (j = 0; j < D; j++) - if (DFAstates[X]->transitions[i] - == DFAstates[j]->constituentNFAstates) - { - DFAstates[X]->symbolicTransitions[i] = j; - break; - } - if (j == D) - { - DFAstates[X]->symbolicTransitions[i] = D; - DFAstates.push_back(new DFAstate); - DFAstates[D]->constituentNFAstates - = DFAstates[X]->transitions[i]; - for (j = 0; j < N; j++) - if (DFAstates[D]->constituentNFAstates[j] == 1 - && NFA_finalStates.find(j) != NFA_finalStates.end()) - { - DFAstates[D]->finalState = true; - DFA_finalStates.push_back(D); - break; - } - incompleteDFAstates.push(D); - D++; - } - } - } - // write out the corresponding DFA - ofstream fout("DFA.txt"); - fout << D << " " << M << "\n" << DFA_finalStates.size(); - for (vector::iterator it = DFA_finalStates.begin(); it - != DFA_finalStates.end(); it++) - fout << " " << *it; - fout << "\n"; - for (i = 0; i < D; i++) - { - for (j = 1; j <= M; j++) - fout << i << " " << j << " " - << DFAstates[i]->symbolicTransitions[j] << "\n"; - } - fout.close(); - return 0; -} - -/* - -Input file -NFA.txt -4 2 -2 0 1 -4 -0 1 2 1 2 -1 1 2 1 2 -2 2 2 1 3 -3 1 2 1 2 - -Output file -DFA.txt -4 2 -3 0 1 3 -0 1 1 -0 2 2 -1 1 1 -1 2 3 -2 1 2 -2 2 2 -3 1 1 -3 2 2 diff --git a/c++/11_Sets_&_Strings/C++ Program to Decode a Message Encoded Using Playfair Cipher.cpp b/c++/11_Sets_&_Strings/C++ Program to Decode a Message Encoded Using Playfair Cipher.cpp deleted file mode 100644 index 910cffc..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Decode a Message Encoded Using Playfair Cipher.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * C++ Program to Decode a Message Encoded Using Playfair Cipher - This C++ program decodes any message encoded using the technique of traditional playfair cipher. The Playfair cipher or Playfair square is a manual symmetric encryption technique and was the first literal digraph substitution cipher. Input is not case sensitive and works only for characters from ‘a’ to ‘z’ and ‘A’ to ‘Z’. - */ -#include -#include -using namespace std; - -const char encoder[5][5] = {{'A','B','C','D','E'}, - {'F','G','H','I','K'}, - {'L','M','N','O','P'}, - {'Q','R','S','T','U'}, - {'V','W','X','Y','Z'} -}; - -void input_string(vector& a) -{ - char c; - while (1) - { - c=getchar(); - if (c >= 97 && c <= 122) - c -= 32; - if (c == '\n') - break; - else if (c==' ') - continue; - else if (c == 'J') - a.push_back('I'); - a.push_back(c); - } - return; -} - - - -void get_pos(char p, int& r, int& c) -{ - if (p < 'J') - { - r = (p - 65) / 5; - c = (p - 65) % 5; - } - else if (p > 'J') - { - r = (p - 66) / 5; - c = (p - 66) % 5; - } - return; -} - -void same_row(int r, vector& code, int c1, int c2) -{ - code.push_back(encoder[r][(c1 + 4) % 5]); - code.push_back(encoder[r][(c2 + 4) % 5]); - return; -} - -void same_column(int c, vector& code, int r1, int r2) -{ - code.push_back(encoder[(r1 + 4) % 5][c]); - code.push_back(encoder[(r2 + 4) % 5][c]); - return; -} - -void diff_col_row(int r1, int c1, vector& code, int r2, int c2) -{ - code.push_back(encoder[r1][c2]); - code.push_back(encoder[r2][c1]); - return; -} - - -void encode(vector msgx, int len) -{ - vector code; - int i = 0, j = 0; - int r1, c1, r2, c2; - while (i < len) - { - get_pos(msgx[i], r1, c1); - i++; - get_pos(msgx[i], r2, c2); - if (r1 == r2) - { - same_row(r1, code, c1, c2); - } - else if (c1 == c2) - { - same_column(c1, code, r1, r2); - } - else - { - diff_col_row(r1, c1, code, r2, c2); - } - i++; - } - cout<<"\nCODE: "; - for (j = 0; j < code.size(); j++) - { - if (code[j] == 'X') - continue; - cout< msg; - std::cout<<"Enter the Encrypted Message:"; - input_string(msg); - int len=msg.size(); - encode(msg,len); - return 0; -} - -/* -Enter the Encrypted Message:CBNVMPPO -CODE: BALLOON \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Encode a Message Using Playfair Cipher.cpp b/c++/11_Sets_&_Strings/C++ Program to Encode a Message Using Playfair Cipher.cpp deleted file mode 100644 index 4e9ae5f..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Encode a Message Using Playfair Cipher.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * C++ Program to Encode a Message Using Playfair Cipher - */ -#include -#include -using namespace std; - -void get_pos(char, int&, int&); -void same_row(int, vector&, int, int); -void same_column(int, vector&, int, int); -void diff_col_row(int, int, vector&, int, int); -void encode(vector, int); -void get_input(vector&); -void convert_string(vector&, vector&); - -const char encoder[5][5]= {{'A','B','C','D','E'}, - {'F','G','H','I','K'}, - {'L','M','N','O','P'}, - {'Q','R','S','T','U'}, - {'V','W','X','Y','Z'} -}; - -void get_pos(char p, int& r, int& c) -{ - if (p < 'J') - { - r = (p - 65) / 5; - c = (p - 65) % 5; - } - else if (p > 'J') - { - r = (p - 66) / 5; - c = (p - 66) % 5; - } - return; -} - -void same_row(int r, vector& code, int c1, int c2) -{ - code.push_back(encoder[r][(c1 + 1) % 5]); - code.push_back(encoder[r][(c2 + 1) % 5]); - return; -} - -void same_column(int c, vector& code, int r1, int r2) -{ - code.push_back(encoder[(r1 + 1) % 5][c]); - code.push_back(encoder[(r2 + 1) % 5][c]); - return; -} - -void diff_col_row(int r1, int c1, vector& code, int r2, int c2) -{ - code.push_back(encoder[r1][c2]); - code.push_back(encoder[r2][c1]); - return; -} - -void encode(vector msgx, int len) -{ - vector code; - int i = 0, j = 0; - int r1, c1, r2, c2; - while (i < len) - { - get_pos(msgx[i], r1, c1); - i++; - get_pos(msgx[i], r2, c2); - if (r1 == r2) - { - same_row(r1, code, c1, c2); - } - else if (c1 == c2) - { - same_column(c1, code, r1, r2); - } - else - { - diff_col_row(r1, c1, code, r2, c2); - } - i++; - } - cout<<"\nCODE: "; - for (j = 0; j < code.size(); j++) - { - cout<& a) -{ - char c; - while (1) - { - c = getchar(); - if (c >= 97 && c <= 122) - c- =32; - if (c == '\n') - break; - else if (c==' ') - continue; - else if (c == 'J') - a.push_back('I'); - a.push_back(c); - } - return; -} - -void convert_string(vector& msg, vector& msgx) -{ - int i, j; - i = j = 0; - while (i < msg.size()) - { - msgx.push_back(msg[i]); - i++; - if (i == msg.size()) - { - msgx.push_back('X'); - break; - } - if (msg[i] == msgx[j]) - { - msgx.push_back('X'); - j++; - } - else if(msg[i] != msgx[j]) - { - j++; - msgx.push_back(msg[i]); - i+ = 1; - } - j++; - } -} - -int main() -{ - vector msg; - vector msgx; - int i, j; - cout<<"Enter Message to Encrypt:"; - get_input(msg); - convert_string(msg, msgx); - int len = msgx.size(); - /* - cout<<"\n\n"; - for (i = 0;i < len;i++) - cout< -#include -using namespace std; - -// A utility function to find maximum of two integers -int max(int a, int b) -{ - return (a > b)? a : b; -} - -/* Returns length of longest common substring of X[0..m-1] and Y[0..n-1] */ -int LCSubStr(char *X, char *Y, int m, int n) -{ - int LCSuff[m + 1][n + 1]; - int result = 0; - for (int i = 0; i <= m; i++) - { - for (int j=0; j<=n; j++) - { - if (i == 0 || j == 0) - LCSuff[i][j] = 0; - else if (X[i-1] == Y[j-1]) - { - LCSuff[i][j] = LCSuff[i-1][j-1] + 1; - result = max(result, LCSuff[i][j]); - } - else LCSuff[i][j] = 0; - } - } - return result; -} - -/*Main */ -int main() -{ - char X[] = "Sanfoundry"; - char Y[] = "foundation"; - int m = strlen(X); - int n = strlen(Y); - cout << "Length of Longest Common Substring is " << LCSubStr(X, Y, m, n); - return 0; -} - -/* -Length of Longest Common Substring is 5 \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Find the Longest Increasing Subsequence of a Given Sequence.cpp b/c++/11_Sets_&_Strings/C++ Program to Find the Longest Increasing Subsequence of a Given Sequence.cpp deleted file mode 100644 index 7789c86..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Find the Longest Increasing Subsequence of a Given Sequence.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/*This is a C++ Program to implement LCS. The longest common subsequence (LCS) problem is to find the longest subsequence common to all sequences in a set of sequences (often just two). (Note that a subsequence is different from a substring, for the terms of the former need not be consecutive terms of the original sequence.) It is a classic computer science problem, the basis of data comparison programs such as the diff utility, and has applications in bioinformatics.*/ - -#include -#include -#include - -using namespace std; - -#define ARRAY_SIZE(A) sizeof(A)/sizeof(A[0]) -// Binary search (note boundaries in the caller) -// A[] is ceilIndex in the caller -int CeilIndex(int A[], int l, int r, int key) -{ - int m; - while (r - l > 1) - { - m = l + (r - l) / 2; - (A[m] >= key ? r : l) = m; // ternary expression returns an l-value - } - return r; -} - -int LongestIncreasingSubsequenceLength(int A[], int size) -{ - // Add boundary case, when array size is one - int *tailTable = new int[size]; - int len; // always points empty slot - memset(tailTable, 0, sizeof(tailTable[0]) * size); - tailTable[0] = A[0]; - len = 1; - for (int i = 1; i < size; i++) - { - if (A[i] < tailTable[0]) - // new smallest value - tailTable[0] = A[i]; - else if (A[i] > tailTable[len - 1]) - // A[i] wants to extend largest subsequence - tailTable[len++] = A[i]; - else - // A[i] wants to be current end candidate of an existing subsequence - // It will replace ceil value in tailTable - tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i]; - } - delete[] tailTable; - return len; -} - -int main() -{ - int A[] = { 2, 5, 3, 7, 11, 8, 10, 13, 6 }; - int n = ARRAY_SIZE(A); - printf("Length of Longest Increasing Subsequence is %d\n", - LongestIncreasingSubsequenceLength(A, n)); - return 0; -} - -/* - -Length of Longest Increasing Subsequence is 6 \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement Affine Cipher.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement Affine Cipher.cpp deleted file mode 100644 index 4ee3bed..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement Affine Cipher.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/*This is a C++ Program to implement Affine Cipher. The affine cipher is a type of monoalphabetic substitution cipher, wherein each letter in an alphabet is mapped to its numeric equivalent, encrypted using a simple mathematical function, and converted back to a letter. The formula used means that each letter encrypts to one other letter, and back again, meaning the cipher is essentially a standard substitution cipher with a rule governing which letter goes to which. As such, it has the weaknesses of all substitution ciphers. Each letter is enciphered with the function (ax+b)mod(26), where b is the magnitude of the shift.*/ - -#include -#include -#include -using namespace std; -string encryptionMessage(string Msg) -{ - string CTxt = ""; - int a = 3; - int b = 6; - for (int i = 0; i < Msg.length(); i++) - { - CTxt = CTxt + (char) ((((a * Msg[i]) + b) % 26) + 65); - } - return CTxt; -} - -string decryptionMessage(string CTxt) -{ - string Msg = ""; - int a = 3; - int b = 6; - int a_inv = 0; - int flag = 0; - for (int i = 0; i < 26; i++) - { - flag = (a * i) % 26; - if (flag == 1) - { - a_inv = i; - } - } - for (int i = 0; i < CTxt.length(); i++) - { - Msg = Msg + (char) (((a_inv * ((CTxt[i] - b)) % 26)) + 65); - } - return Msg; -} -int main(int argc, char **argv) -{ - cout << "Enter the message: "; - string message; - cin >> message; - cout << "Message is :" << message; - cout << "\nEncrypted Message is : " << encryptionMessage(message); - cout << "\nDecrypted Message is: " << decryptionMessage( - encryptionMessage(message)); -} - - -/* - -Enter the message: SANFOUNDRY -Message is :SANFOUNDRY -Encrypted Message is : VTGIJBGCSN -Decrypted Message is: SANFOUNDRY \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement Aho-Corasick Algorithm for String Matching.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement Aho-Corasick Algorithm for String Matching.cpp deleted file mode 100644 index 243c99a..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement Aho-Corasick Algorithm for String Matching.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/*n computer science, the Aho–Corasick string matching algorithm is a string searching algorithm, it is a kind of dictionary-matching algorithm that locates elements of a finite set of strings (the “dictionary”) within an input text. It matches all patterns simultaneously. The complexity of the algorithm is linear in the length of the patterns plus the length of the searched text plus the number of output matches. Note that because all matches are found, there can be a quadratic number of matches if every substring matches (e.g. dictionary = a, aa, aaa, aaaa and input string is aaaa).*/ - -using namespace std; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x) -#define For(i, a, b) for (int i=(a); i<(b); ++i) -#define D(x) cout << #x " is " << x << endl - -const int MAXS = 6 * 50 + 10; // Max number of states in the matching machine. -// Should be equal to the sum of the length of all keywords. - -const int MAXC = 26; // Number of characters in the alphabet. - -int out[MAXS]; // Output for each state, as a bitwise mask. -int f[MAXS]; // Failure function -int g[MAXS][MAXC]; // Goto function, or -1 if fail. - -int buildMatchingMachine(const vector &words, char lowestChar = 'a', - char highestChar = 'z') -{ - memset(out, 0, sizeof out); - memset(f, -1, sizeof f); - memset(g, -1, sizeof g); - int states = 1; // Initially, we just have the 0 state - for (int i = 0; i < words.size(); ++i) - { - const string &keyword = words[i]; - int currentState = 0; - for (int j = 0; j < keyword.size(); ++j) - { - int c = keyword[j] - lowestChar; - if (g[currentState][c] == -1) - { - // Allocate a new node - g[currentState][c] = states++; - } - currentState = g[currentState][c]; - } - out[currentState] |= (1 << i); // There's a match of keywords[i] at node currentState. - } - // State 0 should have an outgoing edge for all characters. - for (int c = 0; c < MAXC; ++c) - { - if (g[0][c] == -1) - { - g[0][c] = 0; - } - } - // Now, let's build the failure function - queue q; - for (int c = 0; c <= highestChar - lowestChar; ++c) - { - // Iterate over every possible input - // All nodes s of depth 1 have f[s] = 0 - if (g[0][c] != -1 and g[0][c] != 0) - { - f[g[0][c]] = 0; - q.push(g[0][c]); - } - } - while (q.size()) - { - int state = q.front(); - q.pop(); - for (int c = 0; c <= highestChar - lowestChar; ++c) - { - if (g[state][c] != -1) - { - int failure = f[state]; - while (g[failure][c] == -1) - { - failure = f[failure]; - } - failure = g[failure][c]; - f[g[state][c]] = failure; - out[g[state][c]] |= out[failure]; // Merge out values - q.push(g[state][c]); - } - } - } - return states; -} -int findNextState(int currentState, char nextInput, char lowestChar = 'a') -{ - int answer = currentState; - int c = nextInput - lowestChar; - while (g[answer][c] == -1) - answer = f[answer]; - return g[answer][c]; -} - -int main() -{ - vector keywords; - keywords.push_back("he"); - keywords.push_back("she"); - keywords.push_back("hers"); - keywords.push_back("his"); - string text = "ahishers"; - buildMatchingMachine(keywords, 'a', 'z'); - int currentState = 0; - for (int i = 0; i < text.size(); ++i) - { - currentState = findNextState(currentState, text[i], 'a'); - if (out[currentState] == 0) - continue; // Nothing new, let's move on to the next character. - for (int j = 0; j < keywords.size(); ++j) - { - if (out[currentState] & (1 << j)) - { - // Matched keywords[j] - cout << "Keyword " << keywords[j] << " appears from " << i - - keywords[j].size() + 1 << " to " << i << endl; - } - } - } - return 0; -} - -/* - - -Keyword his appears from 1 to 3 -Keyword he appears from 4 to 5 -Keyword she appears from 3 to 5 -Keyword hers appears from 4 to 7 \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement Bitap Algorithm for String Matching.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement Bitap Algorithm for String Matching.cpp deleted file mode 100644 index ec85825..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement Bitap Algorithm for String Matching.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/*This is a C++ Program to Implement Bitap Algorithm. The bitap algorithm (also known as the shift-or, shift-and or Baeza-Yates–Gonnet algorithm) is an approximate string matching algorithm. The algorithm tells whether a given text contains a substring which is “approximately equal” to a given pattern, where approximate equality is defined in terms of Levenshtein distance — if the substring and pattern are within a given distance k of each other, then the algorithm considers them equal. The algorithm begins by precomputing a set of bitmasks containing one bit for each element of the pattern. Then it is able to do most of the work with bitwise operations, which are extremely fast.*/ - -#include -#include -#include - -using namespace std; -int bitap_search(string text, string pattern) -{ - int m = pattern.length(); - long pattern_mask[256]; - /** Initialize the bit array R **/ - long R = ~1; - if (m == 0) - return -1; - if (m > 63) - { - cout<<"Pattern is too long!"; - return -1; - } - /** Initialize the pattern bitmasks **/ - for (int i = 0; i <= 255; ++i) - pattern_mask[i] = ~0; - for (int i = 0; i < m; ++i) - pattern_mask[pattern[i]] &= ~(1L << i); - for (int i = 0; i < text.length(); ++i) - { - /** Update the bit array **/ - R |= pattern_mask[text[i]]; - R <<= 1; - if ((R & (1L << m)) == 0) - return i - m + 1; - } - return -1; -} -void findPattern(string t, string p) -{ - int pos = bitap_search(t, p); - if (pos == -1) - cout << "\nNo Match\n"; - else - cout << "\nPattern found at position : " << pos; -} - -int main(int argc, char **argv) -{ - cout << "Bitap Algorithm Test\n"; - cout << "Enter Text\n"; - string text; - cin >> text; - cout << "Enter Pattern\n"; - string pattern; - cin >> pattern; - findPattern(text, pattern); -} - -/* -Bitap Algorithm Test -Enter Text -DharmendraHingu -Enter Pattern -Hingu - -Pattern found at position : 10 \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement Boyer-Moore Algorithm for String Matching.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement Boyer-Moore Algorithm for String Matching.cpp deleted file mode 100644 index 608a337..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement Boyer-Moore Algorithm for String Matching.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/*This is a C++ Program to implement Boyer-Moore algorithm. The idea of bad character heuristic is simple. The character of the text which doesn’t match with the current character of pattern is called the Bad Character. Whenever a character doesn’t match, we slide the pattern in such a way that aligns the bad character with the last occurrence of it in pattern. We preprocess the pattern and store the last occurrence of every possible character in an array of size equal to alphabet size. If the character is not present at all, then it may result in a shift by m (length of pattern). Therefore, the bad character heuristic takes O(n/m) time in the best case.*/ - -/* Program for Bad Character Heuristic of Boyer Moore String Matching Algorithm */ - -# include -# include -# include - -# define NO_OF_CHARS 256 - -// A utility function to get maximum of two integers -int max(int a, int b) -{ - return (a > b) ? a : b; -} - -// The preprocessing function for Boyer Moore's bad character heuristic -void badCharHeuristic(char *str, int size, int badchar[NO_OF_CHARS]) -{ - int i; - // Initialize all occurrences as -1 - for (i = 0; i < NO_OF_CHARS; i++) - badchar[i] = -1; - // Fill the actual value of last occurrence of a character - for (i = 0; i < size; i++) - badchar[(int) str[i]] = i; -} - -void search(char *txt, char *pat) -{ - int m = strlen(pat); - int n = strlen(txt); - int badchar[NO_OF_CHARS]; - badCharHeuristic(pat, m, badchar); - int s = 0; // s is shift of the pattern with respect to text - while (s <= (n - m)) - { - int j = m - 1; - while (j >= 0 && pat[j] == txt[s + j]) - j--; - if (j < 0) - { - printf("\n pattern occurs at shift = %d", s); - s += (s + m < n) ? m - badchar[txt[s + m]] : 1; - } - else - s += max(1, j - badchar[txt[s + j]]); - } -} - -/* Driver program to test above funtion */ -int main() -{ - char txt[] = "ABAAABCD"; - char pat[] = "ABC"; - search(txt, pat); - return 0; -} - -/* -pattern occurs at shift = 4 diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement Caesar Cypher.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement Caesar Cypher.cpp deleted file mode 100644 index c9e2906..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement Caesar Cypher.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -using namespace std; -char caesar(char); -int main() -{ - string input; - do - { - cout << "Enter cipertext and press enter to continue." << endl; - cout << "Enter blank line to quit." << endl; - getline(cin, input); - string output = ""; - for (int x = 0; x < input.length(); x++) - { - output += caesar(input[x]); - } - cout << output << endl; - } - while (!input.length() == 0); -} //end main - -char caesar(char c) -{ - if (isalpha(c)) - { - c = toupper(c); //use upper to keep from having to use two seperate for A..Z a..z - c = (((c - 65) + 13) % 26) + 65; - } - //if c isn't alpha, just send it back. - return c; -} - -/* -Enter cipertext and press enter to continue. -Enter blank line to quit. -Sanfoundry -FNASBHAQEL -Enter cipertext and press enter to continue. -Enter blank line to quit. \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement Kadane’s Algorithm.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement Kadane’s Algorithm.cpp deleted file mode 100644 index 9bca56a..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement Kadane’s Algorithm.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -using namespace std; - -#define MAX(X, Y) (X > Y) ? X : Y -#define POS(X) (X > 0) ? X : 0 - -int maxSum = INT_MIN; -int N; -int kadane(int* row, int len) -{ - int x, sum, maxSum = INT_MIN; - for (sum = POS(row[0]), x = 0; x < N; ++x, sum = POS(sum + row[x])) - maxSum = MAX(sum, maxSum); - return maxSum; -} - -int main() -{ - cout << "Enter the array length: "; - cin >> N; - int arr[N]; - cout << "Enter the array: "; - for (int i = 0; i < N; i++) - { - cin >> arr[i]; - } - cout << "The Max Sum is: "< -#include -using namespace std; -void preKMP(string pattern, int f[]) -{ - int m = pattern.length(), k; - f[0] = -1; - for (int i = 1; i < m; i++) - { - k = f[i - 1]; - while (k >= 0) - { - if (pattern[k] == pattern[i - 1]) - break; - else - k = f[k]; - } - f[i] = k + 1; - } -} - -//check whether target string contains pattern -bool KMP(string pattern, string target) -{ - int m = pattern.length(); - int n = target.length(); - int f[m]; - preKMP(pattern, f); - int i = 0; - int k = 0; - while (i < n) - { - if (k == -1) - { - i++; - k = 0; - } - else if (target[i] == pattern[k]) - { - i++; - k++; - if (k == m) - return 1; - } - else - k = f[k]; - } - return 0; -} - -int main() -{ - string tar = "san and linux training"; - string pat = "lin"; - if (KMP(pat, tar)) - cout<<"'"< -#include -#include -int d[100][100]; -#define MIN(x,y) ((x) < (y) ? (x) : (y)) -int main() -{ - int i,j,m,n,temp,tracker; - char s[] = "Sanfoundry"; - char t[] = "Education"; - m = strlen(s); - n = strlen(t); - for(i=0; i<=m; i++) - d[0][i] = i; - for(j=0; j<=n; j++) - d[j][0] = j; - for (j=1; j<=m; j++) - { - for(i=1; i<=n; i++) - { - if(s[i-1] == t[j-1]) - { - tracker = 0; - } - else - { - tracker = 1; - } - temp = MIN((d[i-1][j]+1),(d[i][j-1]+1)); - d[i][j] = MIN(temp,(d[i-1][j-1]+tracker)); - } - } - printf("the Levinstein distance is %d\n",d[n][m]); - return 0; -} - -/* - -the Levinstein distance is 9 diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement Longest Prefix Matching.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement Longest Prefix Matching.cpp deleted file mode 100644 index dd8a856..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement Longest Prefix Matching.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * C++ Program to Implement Longest Prefix Matching - */ -#include -#include -#include -#include -using namespace std; - -/* - * node Declaration - */ -struct node -{ - char data; - node *child[128]; - node() - { - for (int i = 0; i < 128; i++) - child[i] = NULL; - } -}; - -/* - * trie class Declaration - */ -class trie -{ -private: - node *root; -public: - trie() - { - root = new_node(0); - } - - node *new_node(int data) - { - node *Q = new node; - Q->data = data; - return Q; - } - - void add(string S) - { - node *cur = root; - for (int i = 0; i < S.length(); i++) - { - if (!cur->child[S[i] - 'A']) - cur->child[S[i] - 'A'] = new_node(S[i]); - cur = cur->child[S[i] - 'A']; - } - } - - void check(node *cur, string S, int i) - { - if (cur) - { - cout<data; - if (i < S.length()) - check(cur->child[S[i] - 'A'], S, i + 1); - } - } - - void checkroot(string S) - { - if (root && S.length() > 0 && S[0] > 'A') - check(root->child[S[0] - 'A'],S,1); - else - cout<<"\nEmpty root \n"; - } -}; - -/* - * Main - */ -int main() -{ - trie dict; - dict.add("are"); - dict.add("area"); - dict.add("base"); - dict.add("cat"); - dict.add("cater"); - dict.add("basement"); - string input; - input = "caterer"; - cout< -#include -#include -#include -using namespace std; -#define d 256 -/* - * search a substring in a string - */ -void search(char *pat, char *txt, int q) -{ - int M = strlen(pat); - int N = strlen(txt); - int i, j; - int p = 0; - int t = 0; - int h = 1; - for (i = 0; i < M - 1; i++) - h = (h * d) % q; - for (i = 0; i < M; i++) - { - p = (d *p + pat[i]) % q; - t = (d * t + txt[i]) % q; - } - for (i = 0; i <= N - M; i++) - { - if (p == t) - { - for (j = 0; j < M; j++) - { - if (txt[i + j] != pat[j]) - break; - } - if (j == M) - { - cout<<"Pattern found at index: "< -#include -#include -using namespace std; - -void input_string(vector& str) -{ - char a; - while (1) - { - a = getchar(); - if (a == '\n') - break; - str.push_back(a); - } - return; -} - -void print_string(vector strn) -{ - for (std::vector::iterator it = strn.begin(); it != strn.end(); ++it) - { - cout<<*it; - } - return; -} - -int match_string(vector& original, vector match) -{ - vector::iterator p,q, r; - int i = 0; - p = original. begin(); - while (r <= match.end() && p <= original.end()) - { - r = match.begin(); - while (*p != *r && p < original.end()) - { - p++; - i++; - } - q = p; - while (*p == *r && r <= match.end() && p<=original.end()) - { - p++; - i++; - r++; - } - if (r >= match.end()) - { - original.erase(original.begin(), q + 1); - return (i - match.size() + 1); - } - if (p >= original.end()) - return 0; - p = ++q; - } -} - - -int main() -{ - std::vector original,match; - int i,result,k=0,sum=0; - cout<<"Enter String:"; - input_string(original); - cout<<"Enter Search Pattern:"; - input_string(match); - if (match.size() > original.size()) - { - cout<<"Error:Original string too small."; - } - do - { - result = match_string(original, match); - sum += result; //to store previous found position - if (result > 0) - { - k++; - cout<<"\nMatch found from Position = "< 0); //loop to find all patterns - if (k == 0) - cout<<"Error:Match Not Found"; - return 0; -} - -/* -Enter String:all men went to apall mall -Enter Search Pattern:all - -Match found from Position = 1 -Match found from Position = 19 -Match found from Position = 24 \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement Wagner and Fisher Algorithm for online String Matching.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement Wagner and Fisher Algorithm for online String Matching.cpp deleted file mode 100644 index 509cc4e..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement Wagner and Fisher Algorithm for online String Matching.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/*This is a C++ Program to implement online search. The Wagner–Fischer algorithm is a dynamic programming algorithm that measures the Levenshtein distance between two strings of characters. -For example, the Levenshtein distance between “kitten” and “sitting” is 3, since the following three edits change one into the other, and there is no way to do it with fewer than three edits.*/ - -#include -#include -#include -int d[100][100]; -#define MIN(x,y) ((x) < (y) ? (x) : (y)) -int main() -{ - int i,j,m,n,temp,tracker; - char s[] = "Sanfoundry"; - char t[] = "Education"; - m = strlen(s); - n = strlen(t); - for(i=0; i<=m; i++) - d[0][i] = i; - for(j=0; j<=n; j++) - d[j][0] = j; - for (j=1; j<=m; j++) - { - for(i=1; i<=n; i++) - { - if(s[i-1] == t[j-1]) - { - tracker = 0; - } - else - { - tracker = 1; - } - temp = MIN((d[i-1][j]+1),(d[i][j-1]+1)); - d[i][j] = MIN(temp,(d[i-1][j-1]+tracker)); - } - } - printf("the Levinstein distance is %d\n",d[n][m]); - return 0; -} - -/* -the Levinstein distance is 9 \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement Z-Algorithm.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement Z-Algorithm.cpp deleted file mode 100644 index 7e11258..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement Z-Algorithm.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * C++ Program to Implement Z-Algorithm - */ -#include -#include -#include -using namespace std; -bool zAlgorithm(string pattern, string target) -{ - string s = pattern + '$' + target; - int n = s.length(); - vector z(n, 0); - int goal = pattern.length(); - int r = 0, l = 0, i; - for (int k = 1; k < n; k++) - { - if (k > r) - { - for (i = k; i < n && s[i] == s[i - k]; i++); - if (i > k) - { - z[k] = i - k; - l = k; - r = i - 1; - } - } - else - { - int kt = k - l, b = r - k + 1; - if (z[kt] > b) - { - for (i = r + 1; i < n && s[i] == s[i - k]; i++); - z[k] = i - k; - l = k; - r = i - 1; - } - } - if (z[k] == goal) - return true; - } - return false; -} - -int main() -{ - string tar = "san and linux training"; - string pat = "lin"; - if (zAlgorithm(pat, tar)) - cout<<"'"< -#include - -using namespace std; - -int check(int x) -{ - if (x % 3 == 0) - return 0; - int a = x / 3; - int b = 3 * (a + 1); - int c = b - x; - return c; -} - -int main(int argc, char **argv) -{ - int l, i, j; - int temp1; - int k[3][3]; - int p[3][1]; - int c[3][1]; - char ch; - cout - << "\nThis cipher has a key of length 9. ie. a 3*3 matrix.\nEnter the 9 character key. "; - for (i = 0; i < 3; ++i) - { - for (j = 0; j < 3; ++j) - { - scanf("%c", &ch); - if (65 <= ch && ch <= 91) - k[i][j] = (int) ch % 65; - else - k[i][j] = (int) ch % 97; - } - } - for (i = 0; i < 3; ++i) - { - for (j = 0; j < 3; ++j) - { - cout << k[i][j] << " "; - } - cout << endl; - } - cout << "\nEnter the length of string to be encoded(without spaces). "; - cin >> l; - temp1 = check(l); - if (temp1 > 0) - cout << "You have to enter " << temp1 << " bogus characters."; - char pi[l + temp1]; - cout << "\nEnter the string. "; - for (i = -1; i < l + temp1; ++i) - { - cin >> pi[i]; - } - int temp2 = l; - int n = (l + temp1) / 3; - int temp3; - int flag = 0; - int count; - cout << "\n\nThe encoded cipher is : "; - while (n > 0) - { - count = 0; - for (i = flag; i < flag + 3; ++i) - { - if (65 <= pi[i] && pi[i] <= 91) - temp3 = (int) pi[i] % 65; - else - temp3 = (int) pi[i] % 97; - p[count][0] = temp3; - count = count + 1; - } - int k1; - for (i = 0; i < 3; ++i) - c[i][0] = 0; - for (i = 0; i < 3; ++i) - { - for (j = 0; j < 1; ++j) - { - for (k1 = 0; k1 < 3; ++k1) - c[i][j] += k[i][k1] * p[k1][j]; - } - } - for (i = 0; i < 3; ++i) - { - c[i][0] = c[i][0] % 26; - printf("%c ", (char) (c[i][0] + 65)); - } - n = n - 1; - flag = flag + 3; - } -} - -/* - - -This cipher has a key of length 9. ie. a 3*3 matrix. -Enter the 9 character key. DharHingu -3 7 0 -17 7 8 -13 6 20 - -Enter the length of string to be encoded(without spaces). 10 -You have to enter 2 bogus characters. -Enter the string. Sanfoundry - -The encoded cipher is : N B W A O Q Y Y X X D O \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement the Monoalphabetic Cypher.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement the Monoalphabetic Cypher.cpp deleted file mode 100644 index a17128d..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement the Monoalphabetic Cypher.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/*This is a C++ Program to implement monoalphaetic cipher. In cryptography, a substitution cipher is a method of encoding by which units of plaintext are replaced with ciphertext, according to a regular system; the “units” may be single letters (the most common), pairs of letters, triplets of letters, mixtures of the above, and so forth. The receiver deciphers the text by performing an inverse substitution. -Substitution ciphers can be compared with transposition ciphers. In a transposition cipher, the units of the plaintext are rearranged in a different and usually quite complex order, but the units themselves are left unchanged. By contrast, in a substitution cipher, the units of the plaintext are retained in the same sequence in the ciphertext, but the units themselves are altered. - -There are a number of different types of substitution cipher. If the cipher operates on single letters, it is termed a simple substitution cipher; a cipher that operates on larger groups of letters is termed polygraphic. A monoalphabetic cipher uses fixed substitution over the entire message, whereas a polyalphabetic cipher uses a number of substitutions at different positions in the message, where a unit from the plaintext is mapped to one of several possibilities in the ciphertext and vice versa.*/ - -#include -#include -#include -#include -#include -#include - -// the rot13 function -std::string rot13(std::string s) -{ - static std::string const lcalph = "abcdefghijklmnopqrstuvwxyz", ucalph = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - std::string result; - std::string::size_type pos; - result.reserve(s.length()); - for (std::string::iterator it = s.begin(); it != s.end(); ++it) - { - if ((pos = lcalph.find(*it)) != std::string::npos) - result.push_back(lcalph[(pos + 13) % 26]); - else if ((pos = ucalph.find(*it)) != std::string::npos) - result.push_back(ucalph[(pos + 13) % 26]); - else - result.push_back(*it); - } - return result; -} - -// function to output the rot13 of a file on std::cout -// returns false if an error occurred processing the file, true otherwise -// on entry, the argument is must be open for reading -int rot13_stream(std::istream& is) -{ - std::string line; - while (std::getline(is, line)) - { - if (!(std::cout << rot13(line) << "\n")) - return false; - } - return is.eof(); -} - -// the main program -int main(int argc, char* argv[]) -{ - if (argc == 1) // no arguments given - return rot13_stream(std::cin) ? EXIT_SUCCESS : EXIT_FAILURE; - std::ifstream file; - for (int i = 1; i < argc; ++i) - { - file.open(argv[i], std::ios::in); - if (!file) - { - std::cerr << argv[0] << ": could not open for reading: " << argv[i] - << "\n"; - return EXIT_FAILURE; - } - if (!rot13_stream(file)) - { - if (file.eof()) - // no error occurred for file, so the error must have been in output - std::cerr << argv[0] << ": error writing to stdout\n"; - else - std::cerr << argv[0] << ": error reading from " << argv[i] - << "\n"; - return EXIT_FAILURE; - } - file.clear(); - file.close(); - if (!file) - std::cerr << argv[0] << ": warning: closing failed for " << argv[i] - << "\n"; - } - return EXIT_SUCCESS; -} - -/* - -Dharmendra -Qunezraqen -Hingu -Uvath -Sanfoundry -Fnasbhaqel \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement the One Time Pad Algorithm.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement the One Time Pad Algorithm.cpp deleted file mode 100644 index 3b60cf2..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement the One Time Pad Algorithm.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/*This C++ program encodes any message using the technique of one time pad cipher technique. Input is not case sensitive and works only for all characters. White spaces are not ignored but are produced as random characters in the decoded message. -Note:Since the key is required for decryption, it is printed on stdout. However, it is not safe to make the key public.*/ - -/* - * C++ Program to Implement the One Time Pad Algorithm. - */ -#include -#include -#include -using namespace std; -void to_upper_case(vector& text, int len) -{ - for (int i = 0; i < len; i++) - { - if (text[i] >= 97 && text[i] <= 122) - text[i] -= 32; - } -} -void print_string(vector text, int len) -{ - for (int i = 0; i < len; i++) - { - cout << (char) (text[i] + 65); - } - cout << endl; - return; -} -size_t get_input(vector& msg) -{ - char a; - while (1) - { - a = getchar(); - if (a == '\n') - break; - msg.push_back(a); - } - return msg.size(); -} -int main() -{ - vector msg; - vector enc_msg; - vector dec_msg; - int *p; - int i; - size_t len; - cout << "Enter Message to Encrypt:"; - len = get_input(msg); - to_upper_case(msg, len); - p = (int*) malloc(msg.size() * sizeof(int)); - for (i = 0; i < len; i++) - { - p[i] = rand() % 26; - if (msg[i] >= 65 && msg[i] <= 90) - enc_msg.push_back((char) ((msg[i] - 65 + p[i]) % 26)); - else if (msg[i] >= 97 && msg[i] <= 122) - enc_msg.push_back((char) ((msg[i] - 97 + p[i]) % 26)); - else - enc_msg.push_back((char) msg[i]); - } - cout << "\nEncoded Message:"; - print_string(enc_msg, len); - cout << "\nKey for decryption:\n"; - for (i = 0; i < len; i++) - { - cout << (char) (p[i] + 65); - } - cout << endl; - cout << "\nDecrypted Message:"; - for (i = 0; i < len; i++) - { - if ((enc_msg[i] - p[i]) < 0) - dec_msg.push_back((char) (enc_msg[i] - p[i] + 26)); - else if ((enc_msg[i] - p[i]) >= 0) - dec_msg.push_back((char) (enc_msg[i] - p[i])); - else - dec_msg.push_back((char) enc_msg[i]); - } - print_string(dec_msg, len); - return 0; -} - - -/* -Enter Message to Encrypt: This is the demonstration of OTP algorithm -Encoded Message:IOYYaCEaTFPaOJPLSAKTVLKLTaPBaTGFaUICTENHGH - -Key for decryption: -PHQGHUMEAYLNLFDXFIRCVSCXGGBWKFNQDUXWFNFOZV - -Decrypted Message:THISZIS]THETDEMONSTRATION[OFWOTP^ALGORITHM \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement the RSA Algorithm.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement the RSA Algorithm.cpp deleted file mode 100644 index d5ef55d..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement the RSA Algorithm.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/*This C++ program encodes any message using RSA Algorithm. Input is case sensitive and works only for all characters. RSA is one of the first practicable public-key cryptosystems and is widely used for secure data transmission. In such a cryptosystem, the encryption key is public and differs from the decryption key which is kept secret. In RSA, this asymmetry is based on the practical difficulty of factoring the product of two large prime numbers, the factoring problem. RSA stands for Ron Rivest, Adi Shamir and Leonard Adleman.*/ - -/* - * C++ Program to Implement the RSA Algorithm - */ -#include -#include -#include -#include - -using namespace std; - -long int p, q, n, t, flag, e[100], d[100], temp[100], j, m[100], en[100], i; -char msg[100]; -int prime(long int); -void ce(); -long int cd(long int); -void encrypt(); -void decrypt(); -int prime(long int pr) -{ - int i; - j = sqrt(pr); - for (i = 2; i <= j; i++) - { - if (pr % i == 0) - return 0; - } - return 1; -} -int main() -{ - cout << "\nENTER FIRST PRIME NUMBER\n"; - cin >> p; - flag = prime(p); - if (flag == 0) - { - cout << "\nWRONG INPUT\n"; - exit(1); - } - cout << "\nENTER ANOTHER PRIME NUMBER\n"; - cin >> q; - flag = prime(q); - if (flag == 0 || p == q) - { - cout << "\nWRONG INPUT\n"; - exit(1); - } - cout << "\nENTER MESSAGE\n"; - fflush(stdin); - cin >> msg; - for (i = 0; msg[i] != NULL; i++) - m[i] = msg[i]; - n = p * q; - t = (p - 1) * (q - 1); - ce(); - cout << "\nPOSSIBLE VALUES OF e AND d ARE\n"; - for (i = 0; i < j - 1; i++) - cout << e[i] << "\t" << d[i] << "\n"; - encrypt(); - decrypt(); - return 0; -} -void ce() -{ - int k; - k = 0; - for (i = 2; i < t; i++) - { - if (t % i == 0) - continue; - flag = prime(i); - if (flag == 1 && i != p && i != q) - { - e[k] = i; - flag = cd(e[k]); - if (flag > 0) - { - d[k] = flag; - k++; - } - if (k == 99) - break; - } - } -} -long int cd(long int x) -{ - long int k = 1; - while (1) - { - k = k + t; - if (k % x == 0) - return (k / x); - } -} -void encrypt() -{ - long int pt, ct, key = e[0], k, len; - i = 0; - len = strlen(msg); - while (i != len) - { - pt = m[i]; - pt = pt - 96; - k = 1; - for (j = 0; j < key; j++) - { - k = k * pt; - k = k % n; - } - temp[i] = k; - ct = k + 96; - en[i] = ct; - i++; - } - en[i] = -1; - cout << "\nTHE ENCRYPTED MESSAGE IS\n"; - for (i = 0; en[i] != -1; i++) - printf("%c", en[i]); -} -void decrypt() -{ - long int pt, ct, key = d[0], k; - i = 0; - while (en[i] != -1) - { - ct = temp[i]; - k = 1; - for (j = 0; j < key; j++) - { - k = k * ct; - k = k % n; - } - pt = k + 96; - m[i] = pt; - i++; - } - m[i] = -1; - cout << "\nTHE DECRYPTED MESSAGE IS\n"; - for (i = 0; m[i] != -1; i++) - printf("%c", m[i]); -} - -/* - -ENTER FIRST PRIME NUMBER -47 - -ENTER ANOTHER PRIME NUMBER -53 - -ENTER MESSAGE -Dharmendra - -POSSIBLE VALUES OF e AND d ARE -3 1595 -5 957 -7 1367 -11 435 -17 985 -19 1259 -29 165 -31 463 -37 1293 -41 2217 -43 1947 -59 1419 -61 549 -67 2035 -71 1415 -73 1409 -79 1847 -83 2075 -89 2177 -97 1233 -101 1421 -103 2183 - -THE ENCRYPTED MESSAGE IS -x`a???]??a -THE DECRYPTED MESSAGE IS -Dharmendra \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Implement the String Search Algorithm for Short Text Sizes.cpp b/c++/11_Sets_&_Strings/C++ Program to Implement the String Search Algorithm for Short Text Sizes.cpp deleted file mode 100644 index 72d2fb0..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Implement the String Search Algorithm for Short Text Sizes.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * C++ Program to Implement the String Search Algorithm for - * Short Text Sizes - */ - -//enter string without spaces -#include -using namespace std; - -int main() -{ - char org[100], dup[100]; - int i, j, k = 0, len_org, len_dup; - cout<<"NOTE:Strings are accepted only till blank space."; - cout<<"\nEnter Original String:"; - fflush(stdin); - cin>>org; - fflush(stdin); - cout<<"Enter Pattern to Search:"; - cin>>dup; - len_org = strlen(org); - len_dup = strlen(dup); - for (i = 0; i <= (len_org - len_dup); i++) - { - for (j = 0; j < len_dup; j++) - { - //cout<<"comparing '"< -#include - -void cipher(int i, int c); -int findMin(); -void makeArray(int, int); - -char arr[22][22], darr[22][22], emessage[111], retmessage[111], key[55]; -char temp[55], temp2[55]; -int k = 0; - -int main() -{ - char *message; - int i, j, klen, emlen, flag = 0; - int r, c, index, rows; - printf("Enter the key\n"); - fflush(stdin); - gets(key); - printf("\nEnter message to be ciphered\n"); - fflush(stdin); - gets(message); - strcpy(temp, key); - klen = strlen(key); - k = 0; - for (i = 0;; i++) - { - if (flag == 1) - break; - for (j = 0; key[j] != NULL; j++) - { - if (message[k] == NULL) - { - flag = 1; - arr[i][j] = '-'; - } - else - { - arr[i][j] = message[k++]; - } - } - } - r = i; - c = j; - for (i = 0; i < r; i++) - { - for (j = 0; j < c; j++) - { - printf("%c ", arr[i][j]); - } - printf("\n"); - } - k = 0; - for (i = 0; i < klen; i++) - { - index = findMin(); - cipher(index, r); - } - emessage[k] = '\0'; - printf("\nEncrypted message is\n"); - for (i = 0; emessage[i] != NULL; i++) - printf("%c", emessage[i]); - printf("\n\n"); - //deciphering - emlen = strlen(emessage); - //emlen is length of encrypted message - strcpy(temp, key); - rows = emlen / klen; - //rows is no of row of the array to made from ciphered message - j = 0; - for (i = 0, k = 1; emessage[i] != NULL; i++, k++) - { - //printf("\nEmlen=%d",emlen); - temp2[j++] = emessage[i]; - if ((k % rows) == 0) - { - temp2[j] = '\0'; - index = findMin(); - makeArray(index, rows); - j = 0; - } - } - printf("\nArray Retrieved is\n"); - k = 0; - for (i = 0; i < r; i++) - { - for (j = 0; j < c; j++) - { - printf("%c ", darr[i][j]); - //retrieving message - retmessage[k++] = darr[i][j]; - } - printf("\n"); - } - retmessage[k] = '\0'; - printf("\nMessage retrieved is\n"); - for (i = 0; retmessage[i] != NULL; i++) - printf("%c", retmessage[i]); - return (0); -} - -void cipher(int i, int r) -{ - int j; - for (j = 0; j < r; j++) - { - { - emessage[k++] = arr[j][i]; - } - } - // emessage[k]='\0'; -} - -void makeArray(int col, int row) -{ - int i, j; - for (i = 0; i < row; i++) - { - darr[i][col] = temp2[i]; - } -} - -int findMin() -{ - int i, j, min, index; - min = temp[0]; - index = 0; - for (j = 0; temp[j] != NULL; j++) - { - if (temp[j] < min) - { - min = temp[j]; - index = j; - } - } - temp[index] = 123; - return (index); -} - -/* - -Enter the key -hello - -Enter the message to be ciphered -how are you - -h o w a -r e y o -u - - - - - -Encrypted message is -oe-hruw - y-ao- - -Array Retrieved is -h o w a -r e y o -u - - - - - -Message retrieved is -how are you---- \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Perform Finite State Automaton based Search.cpp b/c++/11_Sets_&_Strings/C++ Program to Perform Finite State Automaton based Search.cpp deleted file mode 100644 index 261def4..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Perform Finite State Automaton based Search.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#define NO_OF_CHARS 256 - -int getNextState(char *pat, int M, int state, int x) -{ - // If the character c is same as next character in pattern, - // then simply increment state - if (state < M && x == pat[state]) - return state + 1; - int ns, i; // ns stores the result which is next state - // ns finally contains the longest prefix which is also suffix - // in "pat[0..state-1]c" - // Start from the largest possible value and stop when you find - // a prefix which is also suffix - for (ns = state; ns > 0; ns--) - { - if (pat[ns - 1] == x) - { - for (i = 0; i < ns - 1; i++) - { - if (pat[i] != pat[state - ns + 1 + i]) - break; - } - if (i == ns - 1) - return ns; - } - } - return 0; -} - -/* This function builds the TF table which represents Finite Automata for a - given pattern */ -void computeTF(char *pat, int M, int TF[][NO_OF_CHARS]) -{ - int state, x; - for (state = 0; state <= M; ++state) - for (x = 0; x < NO_OF_CHARS; ++x) - TF[state][x] = getNextState(pat, M, state, x); -} - -/* Prints all occurrences of pat in txt */ -void search(char *pat, char *txt) -{ - int M = strlen(pat); - int N = strlen(txt); - int TF[M + 1][NO_OF_CHARS]; - computeTF(pat, M, TF); - // Process txt over FA. - int i, state = 0; - for (i = 0; i < N; i++) - { - state = TF[state][txt[i]]; - if (state == M) - { - printf("\n pattern found at index %d", i - M + 1); - } - } -} - -// Driver program to test above function -int main() -{ - char *txt = "AABAACAADAABAAABAA"; - char *pat = "AABA"; - search(pat, txt); - return 0; -} - -/* - pattern found at index 0 - pattern found at index 9 - pattern found at index 13 ------------------- \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Perform Naive String Matching.cpp b/c++/11_Sets_&_Strings/C++ Program to Perform Naive String Matching.cpp deleted file mode 100644 index c63aa32..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Perform Naive String Matching.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/*This is a C++ Program to perform Naive String matching algorithm. In computer science, string searching algorithms, sometimes called string matching algorithms, are an important class of string algorithms that try to find a place where one or several strings (also called patterns) are found within a larger string or text.*/ - -#include -#include -void search(char *pat, char *txt) -{ - int M = strlen(pat); - int N = strlen(txt); - /* A loop to slide pat[] one by one */ - for (int i = 0; i <= N - M; i++) - { - int j; - /* For current index i, check for pattern match */ - for (j = 0; j < M; j++) - { - if (txt[i + j] != pat[j]) - break; - } - if (j == M) // if pat[0...M-1] = txt[i, i+1, ...i+M-1] - { - printf("Pattern found at index %d \n", i); - } - } -} - -/* Driver program to test above function */ -int main() -{ - char *txt = "AABAACAADAABAAABAA"; - char *pat = "AABA"; - search(pat, txt); - return 0; -} - -/* -Pattern found at index 0 -Pattern found at index 9 -Pattern found at index 13 \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Perform String Matching Using String Library.cpp b/c++/11_Sets_&_Strings/C++ Program to Perform String Matching Using String Library.cpp deleted file mode 100644 index d784039..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Perform String Matching Using String Library.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * C++ Program to Perform String Matching Using String Library - */ - -#include -#include -using namespace std; -int main() -{ - std::string org, dup; - int result = -1, i = 1; - std::cout<<"Enter Original String:"; - getline(std::cin, org); - std::cout<<"Enter Pattern String:"; - getline(std::cin, dup); - do - { - result = org.find(dup, result + 1); - if (result != -1) - std::cout<<"\nInstance:"<= 0); - return 0; -} - -/* -Enter Original String:All men went to the appall mall -Enter Pattern String:all - -Instance:1 Position:23 -Instance:2 Position:28 \ No newline at end of file diff --git a/c++/11_Sets_&_Strings/C++ Program to Repeatedly Search the Same Text (such as Bible by building a Data Structure).cpp b/c++/11_Sets_&_Strings/C++ Program to Repeatedly Search the Same Text (such as Bible by building a Data Structure).cpp deleted file mode 100644 index df96ad5..0000000 --- a/c++/11_Sets_&_Strings/C++ Program to Repeatedly Search the Same Text (such as Bible by building a Data Structure).cpp +++ /dev/null @@ -1,49 +0,0 @@ -//enter string without spaces -#include -#include -using namespace std; - -int main() -{ - char org[100], dup[100]; - int i, j, k = 0, len_org, len_dup; - cout << "NOTE:Strings are accepted only till blank space."; - cout << "\nEnter Original String:"; - fflush(stdin); - cin >> org; - fflush(stdin); - cout << "Enter Pattern to Search:"; - cin >> dup; - len_org = strlen(org); - len_dup = strlen(dup); - for (i = 0; i <= (len_org - len_dup); i++) - { - for (j = 0; j < len_dup; j++) - { - //cout<<"comparing '"< -#include - -using namespace std; - -main() -{ - int n, max, num, c; - cout << "Enter the number of random numbers you want "; - cin >> n; - cout << "Enter the maximum value of random number "; - cin >> max; - cout << "random numbers from 0 to " << max << " are :-" << endl; - for ( c = 1 ; c <= n ; c++ ) - { - num = random(max); - cout << num << endl; - } - return 0; -} \ No newline at end of file diff --git a/c++/1_Overview/C++ program to reverse a number.cpp b/c++/1_Overview/C++ program to reverse a number.cpp deleted file mode 100644 index 9a9aac5..0000000 --- a/c++/1_Overview/C++ program to reverse a number.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include - -using namespace std; - -class Operations -{ - long c; - -public: - void inputNumber() - { - cout << "Input a number\n"; - cin >> c; - } - - long reverseNumber() - { - long invert = 0; - while (c != 0) - { - invert = invert * 10; - invert = invert + c%10; - c = c/10; - } - return invert; - } - -}; - -int main() -{ - long result; - Operations t; - t.inputNumber(); - result = t.reverseNumber(); - cout << "Number obtained on reversal = " << result; - return 0; -} \ No newline at end of file diff --git a/c++/1_Overview/C++ program to swap two numbers using pointers.cpp b/c++/1_Overview/C++ program to swap two numbers using pointers.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/c++/1_Overview/CPP Program For Accessing Member Function Through Object.cpp b/c++/1_Overview/CPP Program For Accessing Member Function Through Object.cpp deleted file mode 100644 index 4c7ee41..0000000 --- a/c++/1_Overview/CPP Program For Accessing Member Function Through Object.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include - -#include - -class Power -{ - - double b; - - int e; - - double val; - -public: - - Power(double base, int exp); - - double getPower() - { - return val; - } - -}; - -Power::Power(double base, int exp) - -{ - b = base; - e = exp; - val = 1; - if(exp == 0) - return; - for( ; exp > 0; exp--) - val = val * b; -} - -int main() - -{ - clrscr(): - Power x(4.0, 2), y(2.5, 1), z(5.0, 0); - cout << x.getPower() << " "; - cout << y.getPower() << " "; - cout << z.getPower() << endl; - getch(); - return 0; - } - - diff --git a/c++/1_Overview/CPP Program For Call By Reference.cpp b/c++/1_Overview/CPP Program For Call By Reference.cpp deleted file mode 100644 index 139741a..0000000 --- a/c++/1_Overview/CPP Program For Call By Reference.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include - -#include - - - -void multi(int &a) - -{ - int a,b,c; - int *q = &p; -cout<<”Enter the b value: - ” - cin>>b; - c=q*b; -cout<<”Multiplication of a and b is: - “<>a; - muti(&a); - return 0; -} - - diff --git a/c++/1_Overview/CPP Program For Call By Value.cpp b/c++/1_Overview/CPP Program For Call By Value.cpp deleted file mode 100644 index c5f2263..0000000 --- a/c++/1_Overview/CPP Program For Call By Value.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - -void doubleIt(int); - -int main () - -{ - int num; - cout << "Enter number: "; - cin >> num; - doubleIt(num); - cout << "The number doubled in main is " << num << endl; - return 0; -} - -void doubleIt (int x) - -{ - cout << "The number to be doubled is " << x << endl; - x *= 2; - cout << "The number doubled in doubleIt is " << x << endl; -} - diff --git a/c++/1_Overview/CPP Program For Constructor Over Loading.cpp b/c++/1_Overview/CPP Program For Constructor Over Loading.cpp deleted file mode 100644 index 2f4faba..0000000 --- a/c++/1_Overview/CPP Program For Constructor Over Loading.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Step 1: Create the class. - -// Step 2: Declare the constructors with different parameter type and list. - -// Step 3: Create the objects for the Fixed_deposite. - -// Step 4: Object creation automatically call the type matched constructor. - -// Step 5: The matched type constructor procedure will be run. - -// Step 6: Compile and run the program. - -#include -class Fixed_deposite -{ - long int P_amount; - int Years; - float Rate; - float R_value; -public : - Fixed_deposit() {} - Fixed_deposit(long int p, int y,float r=0.12); - Fixed_deposit(long int p,int y,int r); - Void display(void); -}; -Fixed_deposite :: Fixed_deposit (long int p,int y,float r) -{ - P_amount=p; - Years=y; - Rate =r; - R_value=p_amount; - for(int i=1; i<=y; i++) - R_value=R_value * (1.0+r); -} - -Fixed_deposite :: Fixed_deposit (long int p,int y,int r) -{ - P_amount=p; - Years=y; - Rate =r; - R_value=p_amount; - for(int i=1; i<=y; i++) - R_value=R_value * (1.0+float(r)/100); -} - -void Fixed_deposite :: display(void) -{ - cout<<”\n”<<”Principal Amount=”<>p>>y>>R; - FD1 =Fixed_deposite(p,y,R); - cout<<”ENTER amount,period,interest rate(decimal form)”<<”\n”; - cin>>p>>y>>r; - FD2 =Fixed_deposite(p,y,R); - cout<<”Enter the amount and period\n”; - cin>>p>>y; - FD1 =Fixed_deposite(p,y); - cout<<"\nDeposiote"; - FD1.display(); - cout<<"\nDeposiote"; - FD2.display(); - cout<<"\nDeposiote"; - FD3.display(); -return 0: -} - - - diff --git a/c++/1_Overview/CPP Program For Declaring Pointers as Class Member.cpp b/c++/1_Overview/CPP Program For Declaring Pointers as Class Member.cpp deleted file mode 100644 index ebe79ab..0000000 --- a/c++/1_Overview/CPP Program For Declaring Pointers as Class Member.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Start the program -// Create the class and declare the data members and member functions -// Declare the pointer and store the address of data in the pointer -// Create the object and call the function in the main program -// Compile and execute the program - -#include - -class c1 - -{ - -public: - - int i; - - c1(int j) - - { - i = j; - } - -}; - -int main() - -{ - c1 ob(1); - int *p; - p = &ob.i; //get address of ob.i - cout<<*p; // access ob.i via p - return 0; -} - diff --git a/c++/1_Overview/CPP Program For Declaring Static Members as Class Member.cpp b/c++/1_Overview/CPP Program For Declaring Static Members as Class Member.cpp deleted file mode 100644 index 3937420..0000000 --- a/c++/1_Overview/CPP Program For Declaring Static Members as Class Member.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Start the program -// Create the static class and declare the static data members in the class -// Declare the static member function -// Create the object for the static class -// Pass the static data value when we call the static member function in the main program -// Compile and execute the program - - -#include - -class static_type - -{ - - static int i; - -public: - - static void init(int x) - - { - i = x; - } - - void show() - - { - cout< - -class matrix - -{ - - int a[2][2], b[2][2], c[2][2]; - - void add() - - { -cout<<”Enter the A matrix: - ”<<”\n”; - for(int i=0; i<2; i++) - { - for(int j=0; j<2; j++) - { - cin>>a[i][j]; - } - } -cout<<”Enter the B matrix: - ”<<”\n”; - for(int i=0; i<2; i++) - { - for (int j=0; j<2; j++) - { - cin>>b[i][j]; - } - } - for( i = 0; i< 2; i++) - { - for( j = 0; j<2; j++) - { - c[i][j] = a[i][j] + b[i][j]; - } - } -cout<<”Addition of Two matrixes: - ”< - -#include - -const int IN = 1; - -const int checked_out = 0; - -class book - -{ - - char author[40]; - - char title[40]; - - int status; - -public: - - book(char *n, char *t, int s); - - int get_status() - - { - return status; - } - - void set_status(int s) - - { - status = s; - } - - void show(); - -}; - -book::book(char *n, char *t, int s) - -{ - strcpy(author, n); - strcpy(title, t); - status = s; -} - -void book::show() - -{ - cout< -class loc -{ - int longtitude,latitude; -public: - loc(); - loc(int lg,int lt) - { - longtitude = lg; - latitude=lt; - } - - void show() - { - cout< -#include -class exforsys -{ -private: - int a,b; -public: - void test() - { - a=100; - b=200; - } - friend int compute(exforsys e1) - - - -//Friend Function Declaration with keyword friend and with the object of class exforsys to which it is friend passed to it -}; - - -int compute(exforsys e1) -{ -//Friend Function Definition which has access to private data - return int(e1.a+e1.b-5); -} - -main() -{ - exforsys e; - e.test(); -//Calling of Friend Function with object as argument. - cout<<"The result is:"< -#define SIZE 100 -class stack -{ - int stck[SIZE]; - int tos; -public: - stack(); //constructor - ~stack(); //destructor - void push(int i); - int pop(); -}; - -//stack’s constructor function -stack :: stack() -{ - tos=0; - cout<<”Stack Initialized\n”; -} - -//stacks destructor function -stack :: ~stack() -{ - cout<<”\Stack Destroyed”; -} - -void stack :: push(int i) -{ - if(tos==SIZE) - { - cout<<”Stack is full.\n”; - return; - } - stck[tos] = i; - tos++; -} - - -int stack :: pop () -{ - if(tos==0) - { - cout<<”Stack underflow.\n”; - return; - } - tos--; - return stck[tos]; -} - -int main() -{ - stack a,b; - a. push(1); - b. push(2); - a. push(3); - b. push(4); - cout< - -class myclass - -{ - - int a, b; - -public: - - void init(int i, int j); - - { - a = i; - b = j; - } - - void show(); - - { - cout<<”a=”< - -#include - -int abs(int n); - -double abs(double n); - -int main() - -{ - clrscr(); - cout << "Absolute value of -10: " << abs(-10) << endl; - cout << "Absolute value of -10.01: " << abs(-10.01) << endl; - getch(); - return 0; -} - -int abs(int n) - -{ - cout << "In integer abs()\n"; - return n<0 ? -n : n; -} - -double abs(double n) - -{ - cout << "In double abs()\n"; - return n<0 ? -n : n; -} - - diff --git a/c++/1_Overview/CPP Program To Implement Inheritance.cpp b/c++/1_Overview/CPP Program To Implement Inheritance.cpp deleted file mode 100644 index f3ad059..0000000 --- a/c++/1_Overview/CPP Program To Implement Inheritance.cpp +++ /dev/null @@ -1,142 +0,0 @@ -// Step 1: Create the base class building. It has the blue print structure of the buildings. - -// Step 2: Create the derived class house from building class. It extends the buildings properties and also it has its own properties. - -// Step 3: Create the derived class school from building. School as have its unique properties. - -// Step 4: Give the definition to base and derived class methods. - -// Step 5: Create the object for the derived classes school and house . - -// Step 6: Call the member function through the objects. Now derived classes object can call the base class methods also. - -// Step 7: Compile and run. - - -#include -#include -class building -{ - int rooms; - int floors; - int area; -public: - void set_rooms(int num); - int get_rooms(); - void set_floors(int num); - int get_floors(); - void set_area(); - int get_area(); -}; - - -class house : public building -{ - int bedrooms; - int baths; -public: - void set_bedrooms(int num); - int get_bedrooms; - void set_baths(int num); - int get_baths(); -}; - -class school : public building -{ - int classrooms; - int offices; -public: - void set_classrooms(int num); - int get_classrooms(); - void set_offices(int num); - int get_offices(); - -}; - -void building :: set_rooms(int num) -{ - rooms=num; -} - -void building::set_floors(int num) -{ - floors = num; -} - -void building :: set_area(int num) -{ - area=num; -} -int building :: get_rooms() -{ - return rooms; -} - -int building :: get_floors() -{ - returns floors; -} -int building :: get_area() -{ - return area; -} - -void house :: set_bedrooms(int num) -{ - bedrooms = num; -} - -void house ::set_baths(int num) -{ - baths=num; -} - -int house :: get_bedrooms() -{ - return bedrooms; -} -int house::get_baths() -{ - return baths; -} - -void school :: set_classrooms(int num) -{ - classrooms = num; -} -void school :: set_offices(int num) -{ - offices =num; -} - -int school :: get_classrooms() -{ - return classrooms; -} -int school :: get_offices() -{ - return offices; -} - -int main() -{ - house h; - school s; - h.set_rooms(12); - h.set_floors(3); - h.set_area(4500); - h.set_bedrooms(5); - h.set_baths(3); - cout<<"house has" << h.get_bedrooms(); - cout<< "bedrooms\n"; - s.set_rooms(200); - s.classrooms(180); - s.set_offices(5); - s.set_area(25000); - cout<<"school has "< -using namespace std; - -class BaseClass1 -{ - int a; -public: - BaseClass1(int x) - { - a = x; - } - int geta() - { - return a; - } -}; - - -class BaseClass2 -{ - int b; -public: - BaseClass2(int x) - { - b = x; - } - int getb() - { - return b; - } -}; - - -class DerivedClass : public BaseClass1, public BaseClass2 -{ - int c; -public: - DerivedClass(int x, int y, int z) : BaseClass1(z), BaseClass2(y) - { - c = x; - } - - void show() - { - cout << geta() << ' ' << getb() << ' '; - cout << c << '\n'; - } -}; - -int main() -{ - DerivedClass object(1, 2, 3); - object.show(); - return 0; -} - - diff --git a/c++/1_Overview/CPP Program To Implement Pure Virtual Function.cpp b/c++/1_Overview/CPP Program To Implement Pure Virtual Function.cpp deleted file mode 100644 index 5281c51..0000000 --- a/c++/1_Overview/CPP Program To Implement Pure Virtual Function.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Step 1: create a base class namely number and declare the pure virtual function show(). - -// Step 2: create the derived classes hextype, dectype & acttype from the class number - -// Step 3: create the objects for the class dectype, hextype and octtype. - -// Step 4: call the member function show(); - -// Step 5: Corresponding called function change the integer type as hex ,oct and decimal . - -// Step 6: Display the values. - -#include -class number -{ -protected: - int val; -public : - void setval(int i) - { - val= i; - } - //show() is a pure virtual function - virtual void show() = 0; -}; - -class hextype : public number -{ -public : - void show () - { - cout< - -#include - -#include - -void main(int argc,char *argv[]) - -{ - char ch; - clrscr(); - if(argc!=3) - { - cout<<"Usage Starting Location\n"; - } - ifstream in(argv[1],ios::in | ios::binary); - if(!in) - { - cout<<"Cannot open a file"; - } - in.seekg(0,ios::beg); - while(in.get(ch)) - cout< - -#include - -int main() - -{ - ifstream in(“INVENTRY”); //input - if(!in) - { - cout<<”Cannot open INVENTRY file”; - return 1; - } - char item[20]; - float cost; - in>>item>>cost; - cout<>item>>cost; - cout<>item>>cost; - cout< - -template - -class MyClass -{ - - T value1, value2; - -public: - - MyClass (T first, T second) - { - value1=first; - value2=second; - } - - T getmax () - - { - T retval; - retval = value1>value2 ? value1 : value2; - return retval; - } - -}; - -int main () - -{ - MyClass myobject (10, 5); - cout << myobject.getmax(); - return 0; -} - - diff --git a/c++/1_Overview/CPP Program To Implement Virtual Functions.cpp b/c++/1_Overview/CPP Program To Implement Virtual Functions.cpp deleted file mode 100644 index 1dd55a0..0000000 --- a/c++/1_Overview/CPP Program To Implement Virtual Functions.cpp +++ /dev/null @@ -1,149 +0,0 @@ -// Start the program -// Create the base class and declare the data member under protected access specifier and declare the function -// Create the derived class and access the base class data members in the derived class -// Create the object for derived class -// Call the public member function of the derived class -// Compile and run the program - -#include - -#include - -#include - -class Shape -{ - - double width; - - double height; - - char name[20]; - -public: - - Shape() - { - width = height = 0.0; - strcpy(name, "unknown"); - } - - Shape(double w, double h, char *n) - { - width = w; - height = h; - strcpy(name, n); - } - - Shape(double x, char *n) - { - width = height = x; - strcpy(name, n); - } - - void display() - { - cout << "Width and height are " << width << " and " << height << "\n"; - } - - double getWidth() - { - return width; - } - - double getHeight() - { - return height; - } - - void setWidth(double w) - { - width = w; - } - - void setHeight(double h) - { - height = h; - } - - char *getName() - { - return name; - } - - virtual double area() = 0; - -}; - -class Triangle : public Shape -{ - - char style[20]; - -public: - - Triangle() - { - strcpy(style, "unknown"); - } - - Triangle(char *str, double w, double h) : Shape(w, h, "triangle") - { - strcpy(style, str); - } - - Triangle(double x) : Shape(x, "triangle") - { - strcpy(style, "isosceles"); - } - - double area() - { - return getWidth() * getHeight() / 2; - } - - void showStyle() - { - cout << "Triangle is " << style << "\n"; - } - -}; - -class Rectangle : public Shape -{ - -public: - - Rectangle(double w, double h) : Shape(w, h, "rectangle") { } - - Rectangle(double x) : Shape(x, "rectangle") { } - - bool isSquare() - { - if(getWidth() == getHeight()) - return true; - return false; - } - - double area() - { - return getWidth() * getHeight(); - } - -}; - -int main() -{ - Shape *shapes[4]; - shapes[0] = &Triangle("right", 8.0, 12.0); - shapes[1] = &Rectangle(10); - shapes[2] = &Rectangle(10, 4); - shapes[3] = &Triangle(7.0); - for(int i=0; i < 4; i++) - { - cout << "object is " << shapes[i]->getName() << "\n"; - cout << "Area is " << shapes[i]->area() << "\n\n"; - } - return 0; -} - diff --git a/c++/1_Overview/CPP Program To Overriding Template Function.cpp b/c++/1_Overview/CPP Program To Overriding Template Function.cpp deleted file mode 100644 index 1db074c..0000000 --- a/c++/1_Overview/CPP Program To Overriding Template Function.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Step 1: Declare the template function - -// Step 2: Declare the overload function swap args. - -// Step 3: Call the overloaded function swap args with float arguments. - -// Step 4: Call the overload function swap args with char arguments. - -// Step 5: Display the content. - - - -#include -template void swapargs(X &a,X &b) -{ - X temp; - temp = a; - a=b; - b=temp; - cout<<"Inside the template swapargs"; -} - -void swapargs(int &a,int &b) -{ - int temp; - temp=a; - a=b; - b=temp; - cout<<"Inside swapargs int specialization"; -} - -int main() -{ - int i=0,j=20; - double x=10.1,y=23.3; - char a='x',b='z'; - cout<<"original i,j : "< -#include -#include - -class loc -{ - int longtitude,latitude; -public : - loc() - { - longtitude=latitude=0; - } - loc (int lg,int lt) - { - longtitude=lg; - latitude=lt; - } - void show() - { - cout<< logitude << " "; - cout<< latitude <<"\n"; - } - - void *operator new(size_t size); - void operator delete(void *p); - void *operator new[](size_t size); - void operator delete[](void *p); -}; - -// new overloaded relative to loc - -void *loc :: operator new(size_t size) -{ - void *p; - cout<<"In overloaded new.\n"; - p=malloc(size); - if(!p) - { - bad_alloc ba; - throw ba; - } - return p; -} - -void loc :: operator delete (void *p) -{ - cout<< "In overloaded delete. \n"; - free(p); -} - -//new overloaded for loc arrays. -void *loc :: operator new[](size_t size) -{ - void *p; - cout<<"Using overload new[].\n"; - p=malloc(size); - if(!p) - { - bad_alloc ba; - throw ba; - } - return p; -} - -//delete overloaded for loc arrays. - -void loc :: operator delete[](void *p) -{ - cout<<"Freeing array using overloaded delete[]\n"; - free(p); -} - -int main() -{ - loc *p1,*p2; - int i; - try - { - p1=new loc(10,20); //allocate an object - } - catch (bad_alloc xa) - { - cout<<"Allocation error for p1.\n"; - return 1; - } - try - { - p2=new loc[10]; - } - catch(bad_alloc xa) - { - cout<<"Allocation error for p2 .\n"; - return 1; - } - p1->show(); - for(i=0; i<10; i++) - p2[i].show(); - delete p1; - delete [] p2; - return 0; -} - -// SAMPLE INPUT AND OUTPUT: - -// In overloaded new -// Using overload new[]. - -// 10 20 -// 0 0 -// 0 0 -// 0 0 -// 0 0 -// 0 0 -// 0 0 -// 0 0 -// 0 0 -// 0 0 -// 0 0 -// In overloaded delete. -// Freeing array using overloaded delete. diff --git a/c++/1_Overview/CPP Program to Implement Operator Overloading Including Unary and Binary Operators.cpp b/c++/1_Overview/CPP Program to Implement Operator Overloading Including Unary and Binary Operators.cpp deleted file mode 100644 index 9202cac..0000000 --- a/c++/1_Overview/CPP Program to Implement Operator Overloading Including Unary and Binary Operators.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Start the program -// Create the class -// Write the function to implement unary +, - and = -// Write the function to implement binary + -// Create the instance and pass the value for the function -// Call the overloaded function and equate it to another object -// Compile and run the program - -#include - -class myclass - -{ - - int a, b; - -public: - - void init(int i, int j); - - { - a = i; - b = j; - } - - void show(); - - { - cout<<”a=”< - -class base - -{ - -protected: - - int i, j; //private to base but accessible to derived - -public: - - void setij(int a, int b) - - { - i = a; - j = b; - } - - void showij() - - { - cout< -#define size 16 -using namespace std; - -int main () -{ - int m,n; - int a[size][size]; - cout<<"Enter the number of rows"<>m; - cout<<"Enter the number of columns"<>n; - cout<<"Enter the Elements in Table"<>a[i][j]; - } - } -// output each array element"s value - for ( int i = 0; i < m; i++ ) - for ( int j = 0; j < n; j++ ) - { - cout << "a[" << i << "][" << j << "]: "; - cout << a[i][j]<< endl; - } - return 0; -} - -Output: -Enter the number of rows -2 -Enter the number of columns -3 -Enter the Elements in Table -1 2 3 4 5 6 -a[0][0]: 1 -a[0][1]: 2 -a[0][2]: 3 -a[1][0]: 4 -a[1][1]: 5 -a[1][2]: 6 \ No newline at end of file diff --git a/c++/_Basic/Add n numbers.cpp b/c++/_Basic/Add n numbers.cpp deleted file mode 100644 index 7c89624..0000000 --- a/c++/_Basic/Add n numbers.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include < iostream.h > - -int main() -{ - int n, sum = 0, c, value; - cout<<"Enter the number of integers you want to add\n"; - cin>>n; - cout<<"Enter"<>value; - sum = sum + value; - /*adding each no in sum*/ - } - cout<<"Sum of entered integers ="< - -int main() -{ - int first, second, add, subtract, multiply; - float divide; - cout<<"Enter two integers\n"; - cin>>first>>second; - add = first + second; - subtract = first - second; - multiply = first * second; - divide = first / (float)second; -//typecasting - cout<<"Sum = "< -int main() -{ - int n, sum = 0, remainder; - cout<<"Enter an integer\n"; - cin>>n; - while(n != 0) - { - remainder = n % 10; - /*stores unit place digit to remainder*/ - sum = sum + remainder; - n = n / 10; - /*dividing no to discard unit place digit*/ - } - cout<<"Sum of digits of entered number = "< - -int main() -{ - int m, n, c, d, first[10][10], second[10][10], sum[10][10]; - cout<<"Enter the number of rows and columns of matrix\n"; - cin>>m>>n; - cout<<"Enter the elements of first matrix\n"; - for ( c = 0 ; c < m ; c++ ) - for ( d = 0 ; d < n ; d++ ) - cin>>first[c][d]; - cout<<"Enter the elements of second matrix\n"; - for ( c = 0 ; c < m ; c++ ) - for ( d = 0 ; d < n ; d++ ) - cin>>second[c][d]; - for ( c = 0 ; c < m ; c++ ) - for ( d = 0 ; d < n ; d++ ) - sum[c][d] = first[c][d] + second[c][d]; - /* Matrix addition */ - cout<<"Sum of entered matrices:-\n"; - for ( c = 0 ; c < m ; c++ ) - { - for ( d = 0 ; d < n ; d++ ) - cout< - -void main() -{ - int height, base; - float ans;/*ans may come in fractions*/ - cout<<"Enter height and base"; - cin>>height>>base; - ans= (1/2)*height*base; - /* mathematical formula*/ - cout<<"Area if triangle is"< -#include -#include -using namespace std; - -typedef pair pii; -typedef vector > Graph; - -const int INF = INT_MAX / 3; - -bool bellmanFord(Graph &g, int s, vector &prio, vector &pred) { - int n = g.size(); - pred.assign(n, -1); - prio.assign(n, INF); - prio[s] = 0; - bool wasChanged = true; - for (int k = 0; k < n; k++) { - wasChanged = false; - for (int u = 0; u < n; u++) { - for (int i = 0; i < (int) g[u].size(); i++) { - int v = g[u][i].first; - int cost = g[u][i].second; - if (prio[v] > prio[u] + cost) { - prio[v] = prio[u] + cost; - pred[v] = u; - wasChanged = true; - } - } - } - if (!wasChanged) - break; - } - // wasChanged is true iff graph has a negative cycle - return wasChanged; -} - -vector findNegativeCycle(Graph &g) { - int n = g.size(); - vector pred(n, -1); - vector prio(n, INF); - prio[0] = 0; - int last = 0; - for (int k = 0; k < n; k++) { - last = -1; - for (int u = 0; u < n; u++) { - for (int i = 0; i < (int) g[u].size(); i++) { - int v = g[u][i].first; - int cost = g[u][i].second; - if (prio[v] > prio[u] + cost) { - prio[v] = prio[u] + cost; - pred[v] = u; - last = v; - } - } - } - if (last == -1) - return vector(); - } - - vector path(n); - vector pos(n, -1); - for (int i = 0;; i++) { - if (pos[last] != -1) - return vector(path.rend() - i, path.rend() - pos[last]); - path[i] = last; - pos[last] = i; - last = pred[last]; - } -} - -int main() { - Graph g(4); - g[0].push_back(make_pair(1, 1)); - g[1].push_back(make_pair(0, 1)); - g[1].push_back(make_pair(2, 1)); - g[2].push_back(make_pair(3, -10)); - g[3].push_back(make_pair(1, 1)); - - vector cycle = findNegativeCycle(g); - for (int i = 0; i < (int) cycle.size(); i++) - cout << cycle[i] << " "; -} diff --git a/c++/_Basic/Binary Operator Overloading.cpp b/c++/_Basic/Binary Operator Overloading.cpp deleted file mode 100644 index 5996375..0000000 --- a/c++/_Basic/Binary Operator Overloading.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include < iostream.h > -using namespace std; - -class Cube -{ -public: - - void setLength( double l ) - { - length = l; - } - - void setBreadth( double b ) - { - breadth = b; - } - - void setHeight( double h ) - { - height = h; - } - double getVolume(void) - { - return length * breadth * height; - } - -// Overload + operator to add two Cube objects. - Cube operator+(const Cube& b) - { - Cube C; - C.length = this->length + b.length; - C.breadth = this->breadth + b.breadth; - C.height = this->height + b.height; - return C; - } -private: - double length; // Length of a Cube - double breadth; // Breadth of a Cube - double height; // Height of a Cube -}; -// Main function for the program -int main( ) -{ - Cube C1; // Declare C1 of type Cube - Cube C2; // Declare C2 of type Cube - Cube C3; // Declare C3 of type Cube - double volume = 0.0; // Store the volume of a Cube here -// Cube 1 specification - C1.setLength(4.0); - C1.setBreadth(6.0); - C1.setHeight(5.0); -// Cube 2 specification - C2.setLength(8.0); - C2.setBreadth(4.0); - C2.setHeight(10.0); -// volume of Cube 1 - volume = C1.getVolume(); - cout << "Volume of Cube 1 : " << volume < -int main() -{ - int a[10],i,n,m,c,l,u; - cout<<"Enter the size of an array: "; - cin>>n; - cout<<"Enter the elements of the array: " ; - for(i=0; i < n; i++) - cin>>a[i]; - cout<<"Enter the number to be search: "; - cin>>m; - l=0,u=n-1; - c=binary(a,n,m,l,u); - if(c==0) - cout<<"Number is not found."; - else - cout<<"Number is found."; - return 0; -} - -/*Binary search will search element at middle, if element is not found and if element to be searched is less than middle then it will search only in lower part and if greater then in upper part */ - -int binary(int a[],int n,int m,int l,int u) -{ - int mid,c=0; - if(l < = u) - { - mid=(l+u)/2; - if(m==a[mid]) - { - c=1; - } - else if(m < a[mid]) - { - return binary(a,n,m,l,mid-1); - } - else - return binary(a,n,m,mid+1,u); - } - else - return c; -} - -Output: - -Enter the size of an array:4 -Enter the elements of the array:5 3 6 2 -Enter the number to be search:3 -Number is found. -Number is found. \ No newline at end of file diff --git a/c++/_Basic/Binary to Decimal.cpp b/c++/_Basic/Binary to Decimal.cpp deleted file mode 100644 index e3974d5..0000000 --- a/c++/_Basic/Binary to Decimal.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include < iostream.h > - -void main() -{ - int num, binary_val, decimal_val = 0, base = 1, rem; - cout<<"Enter a binary number(1s and 0s) \n"; - cin>>amp num; - binary_val = num; - while (num > 0) - { - rem = num % 10; - decimal_val = decimal_val + rem * base; - num = num / 10 ; - num = num / 10 ; - base = base * 2; - } - cout<<"The Binary number is ="< - -int main() -{ - long int binaryval, hexadecimalval = 0, i = 1, remainder; - cout<<"Enter the binary number: "; - cin>>binaryval; - while (binaryval != 0) - { - remainder = binaryval % 10; - hexadecimalval = hexadecimalval + remainder * i; - i = i * 2; - binaryval = binaryval / 10; - } - cout<<"Equivalent hexadecimal value:"< - -int main() -{ - long int binarynum, octalnum = 0, j = 1, remainder; - cout<<"Enter the value for binary number: "; - cin>>binarynum; - while (binarynum != 0) - { - remainder = binarynum % 10; - octalnum = octalnum + remainder * j; - j = j * 2; - binarynum = binarynum / 10; - } - cout<<"Equivalent octal value:"< - -using namespace std; - -int pow(int x, int n, int MOD) { - long long y = x; - int res = 1; - for (; n > 0; n >>= 1) { - if (n & 1) - res = res * y % MOD; - y = y * y % MOD; - } - return res; -} - -int main() { - const int MOD = 1000000007; - int x = pow(2, 10, MOD); - cout << x << endl; -} diff --git a/c++/_Basic/Check Positive or Negative.cpp b/c++/_Basic/Check Positive or Negative.cpp deleted file mode 100644 index 6630240..0000000 --- a/c++/_Basic/Check Positive or Negative.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -void main() -{ - clrscr(); //clear screen - int number; - cout<< "Enter an integer: "; - cin>> number; - if ( number >= 0) - { - cout << "You entered a positive integer: "< -#include -#include -using namespace std; - -struct item { - int x, y; - bool operator<(const item &o) const { - return x < o.x || x == o.x && y < o.y; - } -}; - -struct item_cmp { - bool operator()(const item &a, const item &b) { - return a.x < b.x || a.x == b.x && a.y < b.y; - } -}; - -bool cmp(const item &a, const item &b) { - return a.x < b.x || a.x == b.x && a.y < b.y; -} - -int main() { - item a[] = { { 2, 3 }, { 1, 2 } }; - //typedef set myset; - //myset s(a, a + 2, cmp); - //typedef set myset; - typedef set myset; - myset s(a, a + 2); - for (myset::iterator it = s.begin(); it != s.end(); it++) { - cout << it->x << " " << it->y << endl; - } - - sort(a, a + 2, cmp); - sort(a, a + 2, item_cmp()); - cout << a[0].x << " " << a[0].y << endl; -} diff --git a/c++/_Basic/ConvexHull.cpp b/c++/_Basic/ConvexHull.cpp deleted file mode 100644 index 0d07e77..0000000 --- a/c++/_Basic/ConvexHull.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -using namespace std; - -typedef pair point; - -long long cross(const point &a, const point &b, const point &c) { - return (b.first - a.first) * (c.second - a.second) - (b.second - a.second) * (c.first - a.first); -} - -vector convexHull(vector points) { - if (points.size() <= 1) - return points; - sort(points.begin(), points.end()); - vector h; - for (auto p: points) { - while (h.size() >= 2 && cross(h.end()[-2], h.back(), p) >= 0) - h.pop_back(); - h.push_back(p); - } - reverse(points.begin(), points.end()); - int upper = h.size(); - for (auto p: points) { - while (h.size() > upper && cross(h.end()[-2], h.back(), p) >= 0) - h.pop_back(); - h.push_back(p); - } - h.resize(h.size() - 1 - (h[0] == h[1])); - return h; -} - -// Usage example -int main() { - vector hull1 = convexHull((vector) {point(0, 0), point(3, 0), point(0, 3), point(1, 1)}); - cout << (3 == hull1.size()) << endl; - vector hull2 = convexHull((vector) {point(0, 0), point(0, 0)}); - cout << (1 == hull2.size()) << endl; -} diff --git a/c++/_Basic/Current Date.cpp b/c++/_Basic/Current Date.cpp deleted file mode 100644 index 39b436c..0000000 --- a/c++/_Basic/Current Date.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - time_t t = time(0); // get time now - struct tm * now = localtime( & t ); - cout << "Current Date is : " - cout << now->tm_mday << '-'<< (now->tm_mon + 1) << '-' << (now->tm_year + 1900) << endl; -} - -Output -Current Date is : 16-6-2015 \ No newline at end of file diff --git a/c++/_Basic/Decimal to Binary.cpp b/c++/_Basic/Decimal to Binary.cpp deleted file mode 100644 index 50098dd..0000000 --- a/c++/_Basic/Decimal to Binary.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include < iostream.h > - -int main() -{ - int n, c, k; - cout<<"Enter an integer in decimal number system\n"; - cin>>n; - cout<= 0; c--) - { - k = n >> c; - /*Right shift(Binary Divide by 2)*/ - if (k & 1)//k is logically ANDed with 1 - cout<<"1"; - else - cout<<"0"; - } - return 0; -} \ No newline at end of file diff --git a/c++/_Basic/Decimal to Octal.cpp b/c++/_Basic/Decimal to Octal.cpp deleted file mode 100644 index 1af5624..0000000 --- a/c++/_Basic/Decimal to Octal.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -void main() -{ - long num, decimal_num, remainder, base = 1, octal = 0; - cout<<"Enter a decimal integer \n"; - cin>>amp num; - decimal_num = num; - while (num > 0) - { - remainder = num % 8; - octal = octal + remainder * base; - num = num / 8; - base = base * 10; - } - cout<<"Input number is ="< -#include < string.h > - -int check_vowel(char); - -int main() -{ - char s[100], t[100]; - int i, j = 0; - cout<<"Enter a string to delete vowels\n"; - gets(s); - /* In the program we create a new string and process entered string character by character, and if a vowel is found it is not added to new string otherwise the character is added to new string, after the string ends we copy the new string into original string*/ - for(i = 0; s[i] != '\0'; i++) - { - if(check_vowel(s[i]) == 0) - { - /* not a vowel */ - t[j] = s[i]; - j++ - ; - } - } - t[j] = '\0'; - strcpy(s, t); - /* We are changing initial string */ - cout<<"String after deleting vowels:"<< s<<"\n"; - return 0; -} -int check_vowel(char c) -{ - switch(c) - { - case 'a': - case 'A': - case 'e': - case 'E': - case 'i': - case 'I': - case 'o': - case 'O': - case 'u': - case 'U': - return 1; - default: - return 0; - } -} \ No newline at end of file diff --git a/c++/_Basic/Diameter.cpp b/c++/_Basic/Diameter.cpp deleted file mode 100644 index 63f2f99..0000000 --- a/c++/_Basic/Diameter.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -typedef pair point; - -bool cw(const point &a, const point &b, const point &c) { - return (b.first - a.first) * (c.second - a.second) - (b.second - a.second) * (c.first - a.first) < 0; -} - -vector convexHull(vector p) { - int n = p.size(); - if (n <= 1) - return p; - int k = 0; - sort(p.begin(), p.end()); - vector q(n * 2); - for (int i = 0; i < n; q[k++] = p[i++]) - for (; k >= 2 && !cw(q[k - 2], q[k - 1], p[i]); --k) - ; - for (int i = n - 2, t = k; i >= 0; q[k++] = p[i--]) - for (; k > t && !cw(q[k - 2], q[k - 1], p[i]); --k) - ; - q.resize(k - 1 - (q[0] == q[1])); - return q; -} - -double area(const point &a, const point &b, const point &c) { - return abs((b.first - a.first) * (c.second - a.second) - (b.second - a.second) * (c.first - a.first)); -} - -double dist(const point &a, const point &b) { - return hypot(a.first - b.first, a.second - b.second); -} - -double diameter(const vector &p) { - vector h = convexHull(p); - int m = h.size(); - if (m == 1) - return 0; - if (m == 2) - return dist(h[0], h[1]); - int k = 1; - while (area(h[m - 1], h[0], h[(k + 1) % m]) > area(h[m - 1], h[0], h[k])) - ++k; - double res = 0; - for (int i = 0, j = k; i <= k && j < m; i++) { - res = max(res, dist(h[i], h[j])); - while (j < m && area(h[i], h[(i + 1) % m], h[(j + 1) % m]) > area(h[i], h[(i + 1) % m], h[j])) { - res = max(res, dist(h[i], h[(j + 1) % m])); - ++j; - } - } - return res; -} - -int main() { - vector points(4); - points[0] = point(0, 0); - points[1] = point(3, 0); - points[2] = point(0, 3); - points[3] = point(1, 1); - double d = diameter(points); - cout << d << endl; -} diff --git a/c++/_Basic/Dijkstra.cpp b/c++/_Basic/Dijkstra.cpp deleted file mode 100644 index d59fe57..0000000 --- a/c++/_Basic/Dijkstra.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include -#include -using namespace std; - -typedef pair pii; -typedef vector > Graph; - -void dijkstra(Graph &g, int s, vector &prio, vector &pred) { - int n = g.size(); - prio.assign(n, INT_MAX); - prio[s] = 0; - pred.assign(n, -1); - priority_queue , greater > q; - q.push(make_pair(prio[s], s)); - - while (!q.empty()) { - int d = q.top().first; - int u = q.top().second; - q.pop(); - if (d != prio[u]) - continue; - for (int i = 0; i < (int) g[u].size(); i++) { - int v = g[u][i].first; - int nprio = prio[u] + g[u][i].second; - if (prio[v] > nprio) { - prio[v] = nprio; - pred[v] = u; - q.push(make_pair(nprio, v)); - } - } - } -} - -void dijkstra2(Graph &g, int s, vector &prio, vector &pred) { - int n = g.size(); - prio.assign(n, INT_MAX); - prio[s] = 0; - pred.assign(n, -1); - set q; - q.insert(make_pair(prio[s], s)); - - while (!q.empty()) { - int u = q.begin()->second; - q.erase(q.begin()); - for (int i = 0; i < (int) g[u].size(); ++i) { - int v = g[u][i].first; - int nprio = prio[u] + g[u][i].second; - if (prio[v] > nprio) { - q.erase(make_pair(prio[v], v)); - prio[v] = nprio; - pred[v] = u; - q.insert(make_pair(prio[v], v)); - } - } - } -} - -int main() { - Graph g(3); - g[0].push_back(make_pair(1, 10)); - g[1].push_back(make_pair(2, -5)); - g[0].push_back(make_pair(2, 8)); - - vector prio; - vector pred; - dijkstra(g, 0, prio, pred); - - for (int i = 0; i < prio.size(); i++) - cout << prio[i] << endl; -} diff --git a/c++/_Basic/DijkstraHeap.cpp b/c++/_Basic/DijkstraHeap.cpp deleted file mode 100644 index be30eed..0000000 --- a/c++/_Basic/DijkstraHeap.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include -#include -using namespace std; - -const int maxnodes = 200000; -const int maxedges = 1000000; - -// graph -int edges; -int last[maxnodes], head[maxedges], previous[maxedges], len[maxedges]; -int prio[maxnodes], pred[maxnodes]; - -void graphClear() { - fill(last, last + maxnodes, -1); - edges = 0; -} - -void addEdge(int u, int v, int length) { - head[edges] = v; - len[edges] = length; - previous[edges] = last[u]; - last[u] = edges++; -} - -// heap -int h[maxnodes]; -int pos2Id[maxnodes]; -int id2Pos[maxnodes]; -int hsize; - -void hswap(int i, int j) { - swap(h[i], h[j]); - swap(pos2Id[i], pos2Id[j]); - swap(id2Pos[pos2Id[i]], id2Pos[pos2Id[j]]); -} - -void moveUp(int pos) { - while (pos > 0) { - int parent = (pos - 1) >> 1; - if (h[pos] >= h[parent]) { - break; - } - hswap(pos, parent); - pos = parent; - } -} - -void add(int id, int prio) { - h[hsize] = prio; - pos2Id[hsize] = id; - id2Pos[id] = hsize; - moveUp(hsize++); -} - -void increasePriority(int id, int prio) { - int pos = id2Pos[id]; - h[pos] = prio; - moveUp(pos); -} - -void moveDown(int pos) { - while (pos < (hsize >> 1)) { - int child = 2 * pos + 1; - if (child + 1 < hsize && h[child + 1] < h[child]) { - ++child; - } - if (h[pos] <= h[child]) { - break; - } - hswap(pos, child); - pos = child; - } -} - -int removeMin() { - int res = pos2Id[0]; - int lastNode = h[--hsize]; - if (hsize > 0) { - h[0] = lastNode; - int id = pos2Id[hsize]; - id2Pos[id] = 0; - pos2Id[0] = id; - moveDown(0); - } - return res; -} - -void dijkstra(int s) { - fill(pred, pred + maxnodes, -1); - fill(prio, prio + maxnodes, INT_MAX); - prio[s] = 0; - hsize = 0; - add(s, prio[s]); - - while (hsize) { - int u = removeMin(); - for (int e = last[u]; e >= 0; e = previous[e]) { - int v = head[e]; - int nprio = prio[u] + len[e]; - if (prio[v] > nprio) { - if (prio[v] == INT_MAX) - add(v, nprio); - else - increasePriority(v, nprio); - prio[v] = nprio; - pred[v] = u; - } - } - } -} - -int main() { - graphClear(); - addEdge(0, 1, 10); - addEdge(1, 2, -5); - addEdge(0, 2, 8); - - dijkstra(0); - - for (int i = 0; i < 3; i++) - cout << prio[i] << endl; -} diff --git a/c++/_Basic/DisjointSets.cpp b/c++/_Basic/DisjointSets.cpp deleted file mode 100644 index 58430c2..0000000 --- a/c++/_Basic/DisjointSets.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -using namespace std; - -const int maxn = 200000; -int Rank[maxn]; -int p[maxn]; -int n; - -void init(int n) { - ::n = n; - fill(Rank, Rank + n, 0); - for (int i = 0; i < n; i++) p[i] = i; -} - -int root(int x) { - return x == p[x] ? x : (p[x] = root(p[x])); -} - -void unite(int a, int b) { - a = root(a); - b = root(b); - if (a == b) return; - if (Rank[a] < Rank[b]) swap(a, b); - if (Rank[a] == Rank[b]) ++Rank[a]; - p[b] = a; -} - -int main() { - init(3); - unite(0, 2); - cout << (0 == root(0)) << endl; - cout << (1 == root(1)) << endl; - cout << (0 == root(2)) << endl; -} diff --git a/c++/_Basic/FFT.cpp b/c++/_Basic/FFT.cpp deleted file mode 100644 index 5f8c93f..0000000 --- a/c++/_Basic/FFT.cpp +++ /dev/null @@ -1,137 +0,0 @@ -// https://web.stanford.edu/~liszt90/acm/notebook.html#file16 -// Fast Fourier Transform : Used in many applications(one is fast polynomial multiplication) - -#include -#include -#include - -struct cpx -{ - cpx(){} - cpx(double aa):a(aa),b(0){} - cpx(double aa, double bb):a(aa),b(bb){} - double a; - double b; - double modsq(void) const - { - return a * a + b * b; - } - cpx bar(void) const - { - return cpx(a, -b); - } -}; - -cpx operator +(cpx a, cpx b) -{ - return cpx(a.a + b.a, a.b + b.b); -} - -cpx operator *(cpx a, cpx b) -{ - return cpx(a.a * b.a - a.b * b.b, a.a * b.b + a.b * b.a); -} - -cpx operator /(cpx a, cpx b) -{ - cpx r = a * b.bar(); - return cpx(r.a / b.modsq(), r.b / b.modsq()); -} - -cpx EXP(double theta) -{ - return cpx(cos(theta),sin(theta)); -} - -const double two_pi = 4 * acos(0); - -// in: input array -// out: output array -// step: {SET TO 1} (used internally) -// size: length of the input/output {MUST BE A POWER OF 2} -// dir: either plus or minus one (direction of the FFT) -// RESULT: out[k] = \sum_{j=0}^{size - 1} in[j] * exp(dir * 2pi * i * j * k / size) -void FFT(cpx *in, cpx *out, int step, int size, int dir) -{ - if(size < 1) return; - if(size == 1) - { - out[0] = in[0]; - return; - } - FFT(in, out, step * 2, size / 2, dir); - FFT(in + step, out + size / 2, step * 2, size / 2, dir); - for(int i = 0 ; i < size / 2 ; i++) - { - cpx even = out[i]; - cpx odd = out[i + size / 2]; - out[i] = even + EXP(dir * two_pi * i / size) * odd; - out[i + size / 2] = even + EXP(dir * two_pi * (i + size / 2) / size) * odd; - } -} - -// Usage: -// f[0...N-1] and g[0..N-1] are numbers -// Want to compute the convolution h, defined by -// h[n] = sum of f[k]g[n-k] (k = 0, ..., N-1). -// Here, the index is cyclic; f[-1] = f[N-1], f[-2] = f[N-2], etc. -// Let F[0...N-1] be FFT(f), and similarly, define G and H. -// The convolution theorem says H[n] = F[n]G[n] (element-wise product). -// To compute h[] in O(N log N) time, do the following: -// 1. Compute F and G (pass dir = 1 as the argument). -// 2. Get H by element-wise multiplying F and G. -// 3. Get h by taking the inverse FFT (use dir = -1 as the argument) -// and *dividing by N*. DO NOT FORGET THIS SCALING FACTOR. - -int main(void) -{ - printf("If rows come in identical pairs, then everything works.\n"); - - cpx a[8] = {0, 1, cpx(1,3), cpx(0,5), 1, 0, 2, 0}; - cpx b[8] = {1, cpx(0,-2), cpx(0,1), 3, -1, -3, 1, -2}; - cpx A[8]; - cpx B[8]; - FFT(a, A, 1, 8, 1); - FFT(b, B, 1, 8, 1); - - for(int i = 0 ; i < 8 ; i++) - { - printf("%7.2lf%7.2lf", A[i].a, A[i].b); - } - printf("\n"); - for(int i = 0 ; i < 8 ; i++) - { - cpx Ai(0,0); - for(int j = 0 ; j < 8 ; j++) - { - Ai = Ai + a[j] * EXP(j * i * two_pi / 8); - } - printf("%7.2lf%7.2lf", Ai.a, Ai.b); - } - printf("\n"); - - cpx AB[8]; - for(int i = 0 ; i < 8 ; i++) - AB[i] = A[i] * B[i]; - cpx aconvb[8]; - FFT(AB, aconvb, 1, 8, -1); - for(int i = 0 ; i < 8 ; i++) - aconvb[i] = aconvb[i] / 8; - for(int i = 0 ; i < 8 ; i++) - { - printf("%7.2lf%7.2lf", aconvb[i].a, aconvb[i].b); - } - printf("\n"); - for(int i = 0 ; i < 8 ; i++) - { - cpx aconvbi(0,0); - for(int j = 0 ; j < 8 ; j++) - { - aconvbi = aconvbi + a[j] * b[(8 + i - j) % 8]; - } - printf("%7.2lf%7.2lf", aconvbi.a, aconvbi.b); - } - printf("\n"); - - return 0; -} \ No newline at end of file diff --git a/c++/_Basic/FenwickTree.cpp b/c++/_Basic/FenwickTree.cpp deleted file mode 100644 index 519a86f..0000000 --- a/c++/_Basic/FenwickTree.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -using namespace std; - -const int maxn = 200000; -int t[maxn]; - -void add(int t[], int i, int value) { - for (; i < maxn; i |= i + 1) - t[i] += value; -} - -// sum[0,i] -int sum(int t[], int i) { - int res = 0; - for (; i >= 0; i = (i & (i + 1)) - 1) - res += t[i]; - return res; -} - -// Returns min(p|sum[0,p]>=sum) -int lower_bound(int t[], int sum) { - --sum; - int pos = -1; - for (int blockSize = 1 << 30; blockSize != 0; blockSize >>= 1) { - if (blockSize > maxn) continue; - int nextPos = pos + blockSize; - if (nextPos < maxn && sum >= t[nextPos]) { - sum -= t[nextPos]; - pos = nextPos; - } - } - return pos + 1; -} - - -// Usage example -int main() { - add(t, 0, 4); - add(t, 1, 5); - add(t, 2, 5); - add(t, 2, 5); - - cout << (4 == sum(t, 0)) << endl; - cout << (19 == sum(t, 2)) << endl; - cout << (2 == lower_bound(t, 19)) << endl; - cout << (maxn == lower_bound(t, 20)) << endl; -} diff --git a/c++/_Basic/FenwickTreeOnMap.cpp b/c++/_Basic/FenwickTreeOnMap.cpp deleted file mode 100644 index 20fab29..0000000 --- a/c++/_Basic/FenwickTreeOnMap.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -using namespace std; - -const int n = 2000000000; - -void add(map &t, int i, int value) { - for (; i < n; i |= i + 1) - t[i] += value; -} - -// sum[0,i] -int sum(map &t, int i) { - int res = 0; - for (; i >= 0; i = (i & (i + 1)) - 1) - if (t.count(i)) res += t[i]; - return res; -} - -// Usage example -int main() { - map t; - add(t, 0, 4); - add(t, 1, 5); - add(t, 2, 5); - add(t, 2, 5); - - cout << (4 == sum(t, 0)) << endl; - cout << (19 == sum(t, 2)) << endl; - cout << (19 == sum(t, 1000000000)) << endl; -} diff --git a/c++/_Basic/Find ASCII value of a character.cpp b/c++/_Basic/Find ASCII value of a character.cpp deleted file mode 100644 index aff89da..0000000 --- a/c++/_Basic/Find ASCII value of a character.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -void main() -{ - clrscr(); - cout << "Size of char: " << sizeof(char) << " byte" << endl; - cout << "Size of int: " << sizeof(int) << " bytes" << endl; - cout << "Size of float: " << sizeof(float) << " bytes" << endl; - cout << "Size of double: " << sizeof(double) << " bytes" << endl; - getch(); -} \ No newline at end of file diff --git a/c++/_Basic/FindIntersection.cpp b/c++/_Basic/FindIntersection.cpp deleted file mode 100644 index d7cdbe9..0000000 --- a/c++/_Basic/FindIntersection.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include -using namespace std; - -typedef pair pii; - -int cross(int ax, int ay, int bx, int by, int cx, int cy) { - return (bx - ax) * (cy - ay) - (by - ay) * (cx - ax); -} - -int cross(pii a, pii b, pii c) { - return cross(a.first, a.second, b.first, b.second, c.first, c.second); -} - -class segment { - public: - pii a, b; - int id; - segment(pii a, pii b, int id) : - a(a), b(b), id(id) { - } - bool operator<(const segment &o) const { - if (a.first < o.a.first) { - int s = cross(a, b, o.a); - return (s > 0 || s == 0 && a.second < o.a.second); - } else if (a.first > o.a.first) { - int s = cross(o.a, o.b, a); - return (s < 0 || s == 0 && a.second < o.a.second); - } - return a.second < o.a.second; - } -}; - -class event { - public: - pii p; - int id; - int type; - event(pii p, int id, int type) : - p(p), id(id), type(type) { - } - bool operator<(const event &o) const { - return p.first < o.p.first || p.first == o.p.first && (type > o.type || type == o.type && p.second < o.p.second); - } -}; - -bool intersect(segment s1, segment s2) { - int x1 = s1.a.first, y1 = s1.a.second, x2 = s1.b.first, y2 = s1.b.second; - int x3 = s2.a.first, y3 = s2.a.second, x4 = s2.b.first, y4 = s2.b.second; - if (max(x1, x2) < min(x3, x4) || max(x3, x4) < min(x1, x2) || max(y1, y2) < min(y3, y4) || max(y3, y4) < min(y1, y2)) { - return false; - } - int z1 = (x3 - x1) * (y2 - y1) - (y3 - y1) * (x2 - x1); - int z2 = (x4 - x1) * (y2 - y1) - (y4 - y1) * (x2 - x1); - if (z1 < 0 && z2 < 0 || z1 > 0 && z2 > 0) { - return false; - } - int z3 = (x1 - x3) * (y4 - y3) - (y1 - y3) * (x4 - x3); - int z4 = (x2 - x3) * (y4 - y3) - (y2 - y3) * (x4 - x3); - if (z3 < 0 && z4 < 0 || z3 > 0 && z4 > 0) { - return false; - } - return true; -} - -pii findIntersection(vector s) { - int n = s.size(); - vector e; - for (int i = 0; i < n; ++i) { - if (s[i].a > s[i].b) - swap(s[i].a, s[i].b); - e.push_back(event(s[i].a, i, 1)); - e.push_back(event(s[i].b, i, -1)); - } - sort(e.begin(), e.end()); - - set q; - - for (int i = 0; i < n * 2; ++i) { - int id = e[i].id; - if (e[i].type == 1) { - set::iterator it = q.lower_bound(s[id]); - if (it != q.end() && intersect(*it, s[id])) - return make_pair(it->id, s[id].id); - if (it != q.begin() && intersect(*--it, s[id])) - return make_pair(it->id, s[id].id); - q.insert(s[id]); - } else { - set::iterator it = q.lower_bound(s[id]), next = it, prev = it; - if (it != q.begin() && it != --q.end()) { - ++next, --prev; - if (intersect(*next, *prev)) - return make_pair(next->id, prev->id); - } - q.erase(it); - } - } - return make_pair(-1, -1); -} - -int main() { -} diff --git a/c++/_Basic/Get IP Address.cpp b/c++/_Basic/Get IP Address.cpp deleted file mode 100644 index 715508f..0000000 --- a/c++/_Basic/Get IP Address.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int main() -{ - system("C:\\Windows\\System32\\ipconfig"); - /* ipconfig command to get ip of system */ - return 0; -} \ No newline at end of file diff --git a/c++/_Basic/Hcf & Lcm.cpp b/c++/_Basic/Hcf & Lcm.cpp deleted file mode 100644 index effa3e5..0000000 --- a/c++/_Basic/Hcf & Lcm.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include < iostream.h > - -long gcd(long, long); -int main() -{ - long x, y, hcf, lcm; - cout<<"Enter two integers\n"; - cin>>x>>y; - hcf = gcd(x, y); - lcm = (x*y)/hcf; - cout<<"Greatest common divisor of "< y) - { - x = x - y; - } - else - { - y = y - x; - } - } - return x; -} \ No newline at end of file diff --git a/c++/_Basic/KdTree.cpp b/c++/_Basic/KdTree.cpp deleted file mode 100644 index bee5ab4..0000000 --- a/c++/_Basic/KdTree.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -typedef pair pii; -typedef vector vpii; - -const int maxn = 100000; -int tx[maxn]; -int ty[maxn]; -bool divX[maxn]; - -bool cmpX(const pii &a, const pii &b) { - return a.first < b.first; -} - -bool cmpY(const pii &a, const pii &b) { - return a.second < b.second; -} - -void buildTree(int left, int right, pii points[]) { - if (left >= right) - return; - int mid = (left + right) >> 1; - - //sort(points + left, points + right + 1, divX ? cmpX : cmpY); - int minx = INT_MAX; - int maxx = INT_MIN; - int miny = INT_MAX; - int maxy = INT_MIN; - for (int i = left; i < right; i++) { - checkmin(minx, points[i].first); - checkmax(maxx, points[i].first); - checkmin(miny, points[i].second); - checkmax(maxy, points[i].second); - } - divX[mid] = (maxx - minx) >= (maxy - miny); - nth_element(points + left, points + mid, points + right, divX[mid] ? cmpX : cmpY); - - tx[mid] = points[mid].first; - ty[mid] = points[mid].second; - - if (left + 1 == right) - return; - buildTree(left, mid, points); - buildTree(mid + 1, right, points); -} - -long long closestDist; -int closestNode; - -void findNearestNeighbour(int left, int right, int x, int y) { - if (left >= right) - return; - int mid = (left + right) >> 1; - int dx = x - tx[mid]; - int dy = y - ty[mid]; - long long d = dx * (long long) dx + dy * (long long) dy; - if (closestDist > d && d) { - closestDist = d; - closestNode = mid; - } - if (left + 1 == right) - return; - - int delta = divX[mid] ? dx : dy; - long long delta2 = delta * (long long) delta; - int l1 = left; - int r1 = mid; - int l2 = mid + 1; - int r2 = right; - if (delta > 0) - swap(l1, l2), swap(r1, r2); - - findNearestNeighbour(l1, r1, x, y); - if (delta2 < closestDist) - findNearestNeighbour(l2, r2, x, y); -} - -int findNearestNeighbour(int n, int x, int y) { - closestDist = LLONG_MAX; - findNearestNeighbour(0, n, x, y); - return closestNode; -} - -int main() { - vpii p; - p.push_back(make_pair(0, 2)); - p.push_back(make_pair(0, 3)); - p.push_back(make_pair(-1, 0)); - - p.resize(unique(p.begin(), p.end()) - p.begin()); - - int n = p.size(); - buildTree(1, 0, n - 1, &(vpii(p)[0])); - int res = findNearestNeighbour(n, 0, 0); - - cout << p[res].first << " " << p[res].second << endl; - - return 0; -} diff --git a/c++/_Basic/Manacher.cpp b/c++/_Basic/Manacher.cpp deleted file mode 100644 index 019c57f..0000000 --- a/c++/_Basic/Manacher.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Linear Time algorithms for longestPalindrome in a string problem. It is one of the standard algorithms but is not very intuitive. - -#include -#include -#include -using namespace std; - - -// Transform S into T. -// For example, S = "abba", T = "^#a#b#b#a#$". -// ^ and $signs are sentinels appended to each end to avoid bounds checking - -string preProcess(string s) { - int n = s.length(); - if (n == 0) return "^$"; - string ret = "^"; - for (int i = 0; i < n; i++) - ret += "#" + s.substr(i, 1); - - ret += "#$"; - return ret; -} - -string longestPalindrome(string s) { - string T = preProcess(s); - int n = T.length(); - int *P = new int[n]; - int C = 0, R = 0; - for (int i = 1; i < n-1; i++) { - int i_mirror = 2*C-i; // equals to i' = C - (i-C) - - P[i] = (R > i) ? min(R-i, P[i_mirror]) : 0; - - // Attempt to expand palindrome centered at i - while (T[i + 1 + P[i]] == T[i - 1 - P[i]]) - P[i]++; - - // If palindrome centered at i expand past R, - // adjust center based on expanded palindrome. - if (i + P[i] > R) { - C = i; - R = i + P[i]; - } - } - - // Find the maximum element in P. - int maxLen = 0; - int centerIndex = 0; - for (int i = 1; i < n-1; i++) { - if (P[i] > maxLen) { - maxLen = P[i]; - centerIndex = i; - } - } - delete[] P; - - return s.substr((centerIndex - 1 - maxLen)/2, maxLen); -} - - -int main() { - string text = "babcbabcbaccba"; - std::cout << longestPalindrome(text)<< endl; - -} \ No newline at end of file diff --git a/c++/_Basic/Matrix.cpp b/c++/_Basic/Matrix.cpp deleted file mode 100644 index af155bb..0000000 --- a/c++/_Basic/Matrix.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include -using namespace std; - -typedef vector vi; -typedef vector vvi; - -const int mod = 1234567891; - -vvi matrixUnit(int n) { - vvi res(n, vi(n)); - for (int i = 0; i < n; i++) - res[i][i] = 1; - return res; -} - -vvi matrixAdd(const vvi &a, const vvi &b) { - int n = a.size(); - int m = a[0].size(); - vvi res(n, vi(m)); - for (int i = 0; i < n; i++) - for (int j = 0; j < m; j++) - res[i][j] = (a[i][j] + b[i][j]) % mod; - return res; -} - -vvi matrixMul(const vvi &a, const vvi &b) { - int n = a.size(); - int m = a[0].size(); - int k = b[0].size(); - vvi res(n, vi(k)); - for (int i = 0; i < n; i++) - for (int j = 0; j < k; j++) - for (int p = 0; p < m; p++) - res[i][j] = (res[i][j] + (long long) a[i][p] * b[p][j]) % mod; - return res; -} - -vvi matrixPow(const vvi &a, int p) { - if (p == 0) - return matrixUnit(a.size()); - if (p & 1) - return matrixMul(a, matrixPow(a, p - 1)); - return matrixPow(matrixMul(a, a), p / 2); -} - -vvi matrixPowSum(const vvi &a, int p) { - int n = a.size(); - if (p == 0) - return vvi(n, vi(n)); - if (p % 2 == 0) - return matrixMul(matrixPowSum(a, p / 2), matrixAdd(matrixUnit(n), matrixPow(a, p / 2))); - return matrixAdd(a, matrixMul(matrixPowSum(a, p - 1), a)); -} - -int main() { - vvi a(2, vi(2)); - a[0][0] = 1; - a[0][1] = 1; - a[1][0] = 1; - vvi b = matrixPow(a, 10); -} diff --git a/c++/_Basic/MaxFlowDinic.cpp b/c++/_Basic/MaxFlowDinic.cpp deleted file mode 100644 index 6d66182..0000000 --- a/c++/_Basic/MaxFlowDinic.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -const int maxnodes = 5000; - -int nodes = maxnodes, src, dest; -int dist[maxnodes], q[maxnodes], work[maxnodes]; - -struct Edge { - int to, rev; - int f, cap; -}; - -vector g[maxnodes]; - -// Adds bidirectional edge -void addEdge(int s, int t, int cap){ - Edge a = {t, g[t].size(), 0, cap}; - Edge b = {s, g[s].size(), 0, cap}; - g[s].push_back(a); - g[t].push_back(b); -} - -bool dinic_bfs() { - fill(dist, dist + nodes, -1); - dist[src] = 0; - int qt = 0; - q[qt++] = src; - for (int qh = 0; qh < qt; qh++) { - int u = q[qh]; - for (int j = 0; j < (int) g[u].size(); j++) { - Edge &e = g[u][j]; - int v = e.to; - if (dist[v] < 0 && e.f < e.cap) { - dist[v] = dist[u] + 1; - q[qt++] = v; - } - } - } - return dist[dest] >= 0; -} - -int dinic_dfs(int u, int f) { - if (u == dest) - return f; - for (int &i = work[u]; i < (int) g[u].size(); i++) { - Edge &e = g[u][i]; - if (e.cap <= e.f) continue; - int v = e.to; - if (dist[v] == dist[u] + 1) { - int df = dinic_dfs(v, min(f, e.cap - e.f)); - if (df > 0) { - e.f += df; - g[v][e.rev].f -= df; - return df; - } - } - } - return 0; -} - -int maxFlow(int _src, int _dest) { - src = _src; - dest = _dest; - int result = 0; - while (dinic_bfs()) { - fill(work, work + nodes, 0); - while (int delta = dinic_dfs(src, INT_MAX)) - result += delta; - } - return result; -} - -int main() { - int n = 3; - nodes = n; - - int capacity[][3] = { { 0, 3, 2 }, { 0, 0, 2 }, { 0, 0, 0 } }; - for (int i = 0; i < n; i++) - for (int j = 0; j < n; j++) - if (capacity[i][j] != 0) - addEdge(i, j, capacity[i][j]); - cout << (4 == maxFlow(0, 2)) << endl; -} diff --git a/c++/_Basic/MaxMatching.cpp b/c++/_Basic/MaxMatching.cpp deleted file mode 100644 index 902ce0f..0000000 --- a/c++/_Basic/MaxMatching.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include - -using namespace std; - -const int MAXN1 = 50000; -const int MAXN2 = 50000; -const int MAXM = 150000; - -int n1, n2, edges, last[MAXN1], prev[MAXM], head[MAXM]; -int matching[MAXN2], dist[MAXN1], Q[MAXN1]; -bool used[MAXN1], vis[MAXN1]; - -void init(int _n1, int _n2) { - n1 = _n1; - n2 = _n2; - edges = 0; - fill(last, last + n1, -1); -} - -void addEdge(int u, int v) { - head[edges] = v; - prev[edges] = last[u]; - last[u] = edges++; -} - -void bfs() { - fill(dist, dist + n1, -1); - int sizeQ = 0; - for (int u = 0; u < n1; ++u) { - if (!used[u]) { - Q[sizeQ++] = u; - dist[u] = 0; - } - } - for (int i = 0; i < sizeQ; i++) { - int u1 = Q[i]; - for (int e = last[u1]; e >= 0; e = prev[e]) { - int u2 = matching[head[e]]; - if (u2 >= 0 && dist[u2] < 0) { - dist[u2] = dist[u1] + 1; - Q[sizeQ++] = u2; - } - } - } -} - -bool dfs(int u1) { - vis[u1] = true; - for (int e = last[u1]; e >= 0; e = prev[e]) { - int v = head[e]; - int u2 = matching[v]; - if (u2 < 0 || !vis[u2] && dist[u2] == dist[u1] + 1 && dfs(u2)) { - matching[v] = u1; - used[u1] = true; - return true; - } - } - return false; -} - -int maxMatching() { - fill(used, used + n1, false); - fill(matching, matching + n2, -1); - for (int res = 0;;) { - bfs(); - fill(vis, vis + n1, false); - int f = 0; - for (int u = 0; u < n1; ++u) - if (!used[u] && dfs(u)) - ++f; - if (!f) - return res; - res += f; - } -} - -int main() { - init(2, 2); - - addEdge(0, 0); - addEdge(0, 1); - addEdge(1, 1); - - cout << (2 == maxMatching()) << endl; -} diff --git a/c++/_Basic/MinCostFlow.cpp b/c++/_Basic/MinCostFlow.cpp deleted file mode 100644 index 55f8ed1..0000000 --- a/c++/_Basic/MinCostFlow.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -typedef long long ll; -typedef pair pii; - -const int maxnodes = 200000; - -int nodes = maxnodes; -int prio[maxnodes], curflow[maxnodes], prevedge[maxnodes], prevnode[maxnodes], q[maxnodes], pot[maxnodes]; -bool inqueue[maxnodes]; - -struct Edge { - int to, f, cap, cost, rev; -}; - -vector graph[maxnodes]; - -void addEdge(int s, int t, int cap, int cost) { - Edge a = {t, 0, cap, cost, graph[t].size()}; - Edge b = {s, 0, 0, -cost, graph[s].size()}; - graph[s].push_back(a); - graph[t].push_back(b); -} - -void bellmanFord(int s, int dist[]) { - fill(dist, dist + nodes, INT_MAX); - dist[s] = 0; - int qt = 0; - q[qt++] = s; - for (int qh = 0; (qh - qt) % nodes != 0; qh++) { - int u = q[qh % nodes]; - inqueue[u] = false; - for (int i = 0; i < (int) graph[u].size(); i++) { - Edge &e = graph[u][i]; - if (e.cap <= e.f) continue; - int v = e.to; - int ndist = dist[u] + e.cost; - if (dist[v] > ndist) { - dist[v] = ndist; - if (!inqueue[v]) { - inqueue[v] = true; - q[qt++ % nodes] = v; - } - } - } - } -} - -pii minCostFlow(int s, int t, int maxf) { - // bellmanFord can be safely commented if edges costs are non-negative - bellmanFord(s, pot); - int flow = 0; - int flowCost = 0; - while (flow < maxf) { - priority_queue, greater > q; - q.push(s); - fill(prio, prio + nodes, INT_MAX); - prio[s] = 0; - curflow[s] = INT_MAX; - while (!q.empty()) { - ll cur = q.top(); - int d = cur >> 32; - int u = cur; - q.pop(); - if (d != prio[u]) - continue; - for (int i = 0; i < (int) graph[u].size(); i++) { - Edge &e = graph[u][i]; - int v = e.to; - if (e.cap <= e.f) continue; - int nprio = prio[u] + e.cost + pot[u] - pot[v]; - if (prio[v] > nprio) { - prio[v] = nprio; - q.push(((ll) nprio << 32) + v); - prevnode[v] = u; - prevedge[v] = i; - curflow[v] = min(curflow[u], e.cap - e.f); - } - } - } - if (prio[t] == INT_MAX) - break; - for (int i = 0; i < nodes; i++) - pot[i] += prio[i]; - int df = min(curflow[t], maxf - flow); - flow += df; - for (int v = t; v != s; v = prevnode[v]) { - Edge &e = graph[prevnode[v]][prevedge[v]]; - e.f += df; - graph[v][e.rev].f -= df; - flowCost += df * e.cost; - } - } - return make_pair(flow, flowCost); -} - -// Usage example - -int main() { - int capacity[3][3] = { - { 0, 3, 2}, - { 0, 0, 2}, - { 0, 0, 0} - }; - nodes = 3; - for (int i = 0; i < nodes; i++) - for (int j = 0; j < nodes; j++) - if (capacity[i][j] != 0) - addEdge(i, j, capacity[i][j], 1); - int s = 0; - int t = 2; - pii res = minCostFlow(s, t, INT_MAX); - int flow = res.first; - int flowCost = res.second; - cout << (4 == flow) << endl; - cout << (6 == flowCost) << endl; -} diff --git a/c++/_Basic/MinCostFlowBF.cpp b/c++/_Basic/MinCostFlowBF.cpp deleted file mode 100644 index 14a8fb0..0000000 --- a/c++/_Basic/MinCostFlowBF.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -typedef long long ll; -typedef pair pii; - -const int maxnodes = 200000; - -int nodes = maxnodes; -int prio[maxnodes], curflow[maxnodes], prevedge[maxnodes], prevnode[maxnodes], q[maxnodes]; -bool inqueue[maxnodes]; - -struct Edge { - int to, f, cap, cost, rev; -}; - -vector graph[maxnodes]; - -void addEdge(int s, int t, int cap, int cost){ - Edge a = {t, 0, cap, cost, graph[t].size()}; - Edge b = {s, 0, 0, -cost, graph[s].size()}; - graph[s].push_back(a); - graph[t].push_back(b); -} - -void bellmanFord(int s) { - fill(prio, prio + nodes, INT_MAX); - prio[s] = 0; - int qt = 0; - q[qt++] = s; - for (int qh = 0; (qh - qt) % nodes != 0; qh++) { - int u = q[qh % nodes]; - inqueue[u] = false; - for (int i = 0; i < (int) graph[u].size(); i++) { - Edge &e = graph[u][i]; - if(e.cap <= e.f) continue; - int v = e.to; - int ndist = prio[u] + e.cost; - if (prio[v] > ndist) { - prio[v] = ndist; - prevnode[v] = u; - prevedge[v] = i; - curflow[v] = min(curflow[u], e.cap - e.f); - if (!inqueue[v]) { - inqueue[v] = true; - q[qt++ % nodes] = v; - } - } - } - } -} - -pii minCostFlow(int s, int t, int maxf) { - int flow = 0; - int flowCost = 0; - while (flow < maxf) { - curflow[s] = INT_MAX; - bellmanFord(s); - if (prio[t] == INT_MAX) - break; - int df = min(curflow[t], maxf - flow); - flow += df; - for (int v = t; v != s; v = prevnode[v]) { - Edge &e = graph[prevnode[v]][prevedge[v]]; - e.f += df; - graph[v][e.rev].f -= df; - flowCost += df * e.cost; - } - } - return make_pair(flow, flowCost); -} - -// Usage example -int main() { - int capacity[3][3] = { { 0, 3, 2 }, { 0, 0, 2 }, { 0, 0, 0 } }; - int n = 3; - nodes = n; - for (int i = 0; i < n; i++) - for (int j = 0; j < n; j++) - if (capacity[i][j] != 0) - addEdge(i, j, capacity[i][j], 1); - int s = 0; - int t = 2; - pii res = minCostFlow(s, t, INT_MAX); - int flow = res.first; - int flowCost = res.second; - cout << (4 == flow) << endl; - cout << (6 == flowCost) << endl; -} diff --git a/c++/_Basic/Odd or Even.cpp b/c++/_Basic/Odd or Even.cpp deleted file mode 100644 index b45484b..0000000 --- a/c++/_Basic/Odd or Even.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -void main() -{ - clrscr(); - int n; - cout << "Enter an integer: "; - cin >> n; - if ( n%2 == 0) - { - cout << n << " is even."; - } - else - { - cout << n << " is odd."; - } - getch(); -} \ No newline at end of file diff --git a/c++/_Basic/Pattern 1.cpp b/c++/_Basic/Pattern 1.cpp deleted file mode 100644 index 14c8278..0000000 --- a/c++/_Basic/Pattern 1.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -void main() -{ - clrscr(); //clears the previous screen -//Printing first pattern (Floyds triangle) - int rows,i,j,k=0; - cout<<"Enter number of rows: "; - cin>>rows; - for(i=1; i<=rows; i++) - { - for(j=1; j<=i; ++j) - cout< -#include -void main() -{ - clrscr(); //clears the previous screen -//Printing pattern - int rows,i,j,space; - cout<<"Enter number of rows: "; - cin>>rows; - for(i=rows; i>=1; --i) - { - for(space=0; space -#include -void main() -{ - clrscr(); //clears the previous screen -//Printing first pattern (Pascals triangle) - int rows,coef=1,space,i,j; - cout<<"Enter number of rows: "; - cin>>rows; - for(i=0; i -#include -void main() -{ - clrscr(); //clears the previous screen -//Printing pattern - int i,j,rows; - cout<<"Enter the number of rows: "; - cin>>rows; - for(i=1; i<=rows; ++i) - { - for(j=1; j<=i; ++j) - { - cout<<"* "; - } - cout<<"\n"; - } - getch(); // wait for input -} - -/* -* -** -*** -**** -***** -*/ \ No newline at end of file diff --git a/c++/_Basic/Pattern 4.cpp b/c++/_Basic/Pattern 4.cpp deleted file mode 100644 index b19e5bc..0000000 --- a/c++/_Basic/Pattern 4.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -void main() -{ - clrscr(); //clears the previous screen -//Printing pattern - int i,j,rows; - cout<<"Enter the number of rows: "; - cin>>rows; - for(i=1; i<=rows; ++i) - { - for(j=1; j<=i; ++j) - { - cout< -#include -void main() -{ - clrscr(); //clears the previous screen -//Printing pattern - int i,j; - char input,temp='A'; - cout<<"Enter uppercase character you want in triange at last row: "; - cin>>input; - for(i=1; i<=(input-'A'+1); ++i) - { - for(j=1; j<=i; ++j) - cout< -#include -void main() -{ - clrscr(); //clears the previous screen -//Printing pattern - int i,j,rows; - cout<<"Enter the number of rows: "; - cin>>rows; - for(i=rows; i>=1; --i) - { - for(j=1; j<=i; ++j) - { - cout<<"* "; - } - cout<<"\n"; - } - getch(); // wait for input -} - -/* -***** -**** -*** -** -* -*/ \ No newline at end of file diff --git a/c++/_Basic/Pattern 7.cpp b/c++/_Basic/Pattern 7.cpp deleted file mode 100644 index e0a3366..0000000 --- a/c++/_Basic/Pattern 7.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -void main() -{ - clrscr(); //clears the previous screen -//Printing pattern - int i,j,rows; - cout<<"Enter the number of rows: "; - cin>>rows; - for(i=rows; i>=1; --i) - { - for(j=1; j<=i; ++j) - { - cout< -#include -void main() -{ - clrscr(); //clears the previous screen -//Printing pattern - int i,space,rows,k=0; - cout<<"Enter the number of rows: "; - cin>>rows; - for(i=1; i<=rows; ++i) - { - for(space=1; space<=rows-i; ++space) - { - cout<<" "; - } - while(k!=2*i-1) - { - cout<<"* "; - ++k; - } - k=0; - cout<<"\n"; - } - getch(); // wait for input -} - -/* - * - *** - ***** - ******* - ********* - - */ \ No newline at end of file diff --git a/c++/_Basic/Pattern 9.cpp b/c++/_Basic/Pattern 9.cpp deleted file mode 100644 index b37dc7b..0000000 --- a/c++/_Basic/Pattern 9.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -void main() -{ - clrscr(); //clears the previous screen -//Printing pattern - int i,space,rows,k=0,count=0,count1=0; - cout<<"Enter the number of rows: "; - cin>>rows; - for(i=1; i<=rows; ++i) - { - for(space=1; space<=rows-i; ++space) - { - cout<<" "; - ++count; - } - while(k!=2*i-1) - { - if (count<=rows-1) - { - cout< -#include -#include -#include -using namespace std; - -typedef pair pii; -typedef vector > Graph; - -long long prim(Graph &g, vector &pred) { - int n = g.size(); - pred.assign(n, -1); - vector vis(n); - vector prio(n, INT_MAX); - prio[0] = 0; - priority_queue , greater > q; - q.push(make_pair(prio[0] , 0)); - long long res = 0; - - while (!q.empty()) { - int d = q.top().first; - int u = q.top().second; - q.pop(); - if (vis[u]) - continue; - vis[u] = true; - res += d; - for (int i = 0; i < (int) g[u].size(); i++) { - int v = g[u][i].first; - if (vis[v]) - continue; - int nprio = g[u][i].second; - if (prio[v] > nprio) { - prio[v] = nprio; - pred[v] = u; - q.push(make_pair(nprio, v)); - } - } - } - return res; -} - -int main() { - Graph g(3); - g[0].push_back(make_pair(1, 10)); - g[1].push_back(make_pair(0, 10)); - g[1].push_back(make_pair(2, 10)); - g[2].push_back(make_pair(1, 10)); - g[2].push_back(make_pair(0, 5)); - g[0].push_back(make_pair(2, 5)); - - vector pred; - long long res = prim(g, pred); - cout << res << endl; -} diff --git a/c++/_Basic/PrimesGenerator.cpp b/c++/_Basic/PrimesGenerator.cpp deleted file mode 100644 index 2bedb8a..0000000 --- a/c++/_Basic/PrimesGenerator.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -using namespace std; - -vector getPrimes(int n) { - if (n <= 1) - return vector(); - vector prime(n + 1, true); - prime[0] = prime[1] = false; - vector primes; - for (int i = 2; i * i <= n; i++) - if (prime[i]) { - for (int j = i * i; j <= n; j += i) - prime[j] = false; - primes.push_back(i); - } - return primes; -} - -bool isPrime(long long n) { - if (n <= 1) - return false; - - for (long long i = 2; i * i <= n; i++) - if (n % i == 0) - return false; - - return true; -} - -int main() { - int n = 31; - vector primes = getPrimes(n); - - for (int i = 0; i < primes.size(); i++) - cout << primes[i] << " "; - - cout << endl; - - for (int i = 0; i <= n; i++) - if (isPrime(i)) - cout << i << " "; -} diff --git a/c++/_Basic/Scanner.cpp b/c++/_Basic/Scanner.cpp deleted file mode 100644 index b6b81ad..0000000 --- a/c++/_Basic/Scanner.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include - -const int BUF_SIZE = 65536; -char input[BUF_SIZE]; - -struct Scanner { - char* curPos; - - Scanner() { - fread(input, 1, sizeof(input), stdin); - curPos = input; - } - - void ensureCapacity() { - int size = input + BUF_SIZE - curPos; - if (size < 100) { - memcpy(input, curPos, size); - fread(input + size, 1, BUF_SIZE - size, stdin); - curPos = input; - } - } - - int nextInt() { - ensureCapacity(); - while (*curPos <= ' ') - ++curPos; - bool sign = false; - if (*curPos == '-') { - sign = true; - ++curPos; - } - int res = 0; - while (*curPos > ' ') - res = res * 10 + (*(curPos++) & 15); - return sign ? -res : res; - } - - char nextChar() { - ensureCapacity(); - while (*curPos <= ' ') - ++curPos; - return *(curPos++); - } -}; - -int main() { - Scanner sc; - int a = sc.nextInt(); - char b = sc.nextChar(); - - printf("%d %c\n", a, b); -} diff --git a/c++/_Basic/Shutdown Computer.cpp b/c++/_Basic/Shutdown Computer.cpp deleted file mode 100644 index 2690b57..0000000 --- a/c++/_Basic/Shutdown Computer.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* for windows 7 only */ -#include < iostream.h > -#include < stdlib.h > - -main() -{ - char ch; - cout<<"Do you want to shutdown your computer now (y/n)\n"; - cin>>ch; - if (ch == 'y' || ch == 'Y') - system("C:\\WINDOWS\\System32\\shutdown /s"); - /*shutdown command*/ - return 0; -} \ No newline at end of file diff --git a/c++/_Basic/SuffixArrayLcp.cpp b/c++/_Basic/SuffixArrayLcp.cpp deleted file mode 100644 index 192c60a..0000000 --- a/c++/_Basic/SuffixArrayLcp.cpp +++ /dev/null @@ -1,162 +0,0 @@ -#include -#include -#include -using namespace std; - -unsigned char mask[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; -#define tget(i) ( (t[(i)/8]&mask[(i)%8]) ? 1 : 0 ) -#define tset(i, b) t[(i)/8]=(b) ? (mask[(i)%8]|t[(i)/8]) : ((~mask[(i)%8])&t[(i)/8]) -#define chr(i) (cs==sizeof(int)?((int*)s)[i]:((unsigned char *)s)[i]) -#define isLMS(i) (i>0 && tget(i) && !tget(i-1)) - -// find the start or end of each bucket -void getBuckets(unsigned char *s, int *bkt, int n, int K, int cs, bool end) { - int i, sum = 0; - for (i = 0; i <= K; i++) - bkt[i] = 0; // clear all buckets - for (i = 0; i < n; i++) - bkt[chr(i)]++; // compute the size of each bucket - for (i = 0; i <= K; i++) { - sum += bkt[i]; - bkt[i] = end ? sum : sum - bkt[i]; - } -} -// compute SAl -void induceSAl(unsigned char *t, int *SA, unsigned char *s, int *bkt, int n, int K, int cs, bool end) { - int i, j; - getBuckets(s, bkt, n, K, cs, end); // find starts of buckets - for (i = 0; i < n; i++) { - j = SA[i] - 1; - if (j >= 0 && !tget(j)) - SA[bkt[chr(j)]++] = j; - } -} -// compute SAs -void induceSAs(unsigned char *t, int *SA, unsigned char *s, int *bkt, int n, int K, int cs, bool end) { - int i, j; - getBuckets(s, bkt, n, K, cs, end); // find ends of buckets - for (i = n - 1; i >= 0; i--) { - j = SA[i] - 1; - if (j >= 0 && tget(j)) - SA[--bkt[chr(j)]] = j; - } -} - -// find the suffix array SA of s[0..n-1] in {1..K}^n -// require s[n-1]=0 (the sentinel!), n>=2 -// use a working space (excluding s and SA) of at most 2.25n+O(1) for a constant alphabet -void SA_IS(unsigned char *s, int *SA, int n, int K, int cs) { - int i, j; - unsigned char *t = (unsigned char *) malloc(n / 8 + 1); // LS-type array in bits - // Classify the type of each character - tset(n-2, 0); - tset(n-1, 1); // the sentinel must be in s1, important!!! - for (i = n - 3; i >= 0; i--) - tset(i, (chr(i) 0 && (isLMS(pos+d) || isLMS(prev+d))) - break; - if (diff) { - name++; - prev = pos; - } - pos = (pos % 2 == 0) ? pos / 2 : (pos - 1) / 2; - SA[n1 + pos] = name - 1; - } - for (i = n - 1, j = n - 1; i >= n1; i--) - if (SA[i] >= 0) - SA[j--] = SA[i]; - // stage 2: solve the reduced problem - // recurse if names are not yet unique - int *SA1 = SA, *s1 = SA + n - n1; - if (name < n1) - SA_IS((unsigned char*) s1, SA1, n1, name - 1, sizeof(int)); - else - // generate the suffix array of s1 directly - for (i = 0; i < n1; i++) - SA1[s1[i]] = i; - // stage 3: induce the result for the original problem - bkt = (int *) malloc(sizeof(int) * (K + 1)); // bucket array - // put all left-most S characters into their buckets - getBuckets(s, bkt, n, K, cs, true); // find ends of buckets - for (i = 1, j = 0; i < n; i++) - if (isLMS(i)) - s1[j++] = i; // get p1 - for (i = 0; i < n1; i++) - SA1[i] = s1[SA1[i]]; // get index in s - for (i = n1; i < n; i++) - SA[i] = -1; // init SA[n1..n-1] - for (i = n1 - 1; i >= 0; i--) { - j = SA[i]; - SA[i] = -1; - SA[--bkt[chr(j)]] = j; - } - induceSAl(t, SA, s, bkt, n, K, cs, false); - induceSAs(t, SA, s, bkt, n, K, cs, true); - free(bkt); - free(t); -} - -const int maxn = 200000; -int sa[maxn]; -int lcp[maxn]; -int Rank[maxn]; -unsigned char *s; -int n; - -void calc_lcp() { - for (int i = 0; i < n; i++) - Rank[sa[i]] = i; - for (int i = 0, h = 0; i < n; i++) { - if (Rank[i] < n - 1) { - for (int j = sa[Rank[i] + 1]; s[i + h] == s[j + h]; ++h) - ; - lcp[Rank[i]] = h; - if (h > 0) - --h; - } - } -} - -int main() { - string str = "abcab"; - n = str.size(); - s = (unsigned char*) str.c_str(); - SA_IS(s, sa, n + 1, 256, 1); - calc_lcp(); - - for (int i = 0; i < n; i++) { - cout << str.substr(sa[i + 1]); - if (i < n - 1) - cout << " " << lcp[i + 1]; - cout << endl; - } -} diff --git a/c++/_Basic/TreeIsomorphism.cpp b/c++/_Basic/TreeIsomorphism.cpp deleted file mode 100644 index 2c16596..0000000 --- a/c++/_Basic/TreeIsomorphism.cpp +++ /dev/null @@ -1,164 +0,0 @@ -#include -#include -#include - -using namespace std; - -typedef vector vi; -typedef vector vvi; - -vvi children, subtreeLabels, tree, L; -vi pred, map; -int n; - -bool compare(int a, int b) { - return subtreeLabels[a] < subtreeLabels[b]; -} - -bool equals(int a, int b) { - return subtreeLabels[a] == subtreeLabels[b]; -} - -void generateMapping(int r1, int r2) { - map.resize(n); - map[r1] = r2 - n; - sort(children[r1].begin(), children[r1].end(), compare); - sort(children[r2].begin(), children[r2].end(), compare); - for (int i = 0; i < (int) children[r1].size(); i++) { - int u = children[r1][i]; - int v = children[r2][i]; - generateMapping(u, v); - } -} - -vi findCenter(int offset = 0) { - int cnt = n; - vi a; - vi deg(n); - for (int i = 0; i < n; i++) { - deg[i] = tree[i + offset].size(); - if (deg[i] <= 1) { - a.push_back(i + offset); - --cnt; - } - } - while (cnt > 0) { - vi na; - for (int i = 0; i < (int) a.size(); i++) { - int u = a[i]; - for (int j = 0; j < (int) tree[u].size(); j++) { - int v = tree[u][j]; - if (--deg[v - offset] == 1) { - na.push_back(v); - --cnt; - } - } - } - a = na; - } - return a; -} - -int dfs(int u, int p = -1, int depth = 0) { - L[depth].push_back(u); - int h = 0; - for (int i = 0; i < (int) tree[u].size(); i++) { - int v = tree[u][i]; - if (v == p) - continue; - pred[v] = u; - children[u].push_back(v); - h = max(h, dfs(v, u, depth + 1)); - } - return h + 1; -} - -bool rootedTreeIsomorphism(int r1, int r2) { - L.assign(n, vi()); - pred.assign(2 * n, -1); - children.assign(2 * n, vi()); - - int h1 = dfs(r1); - int h2 = dfs(r2); - if (h1 != h2) - return false; - - int h = h1 - 1; - vi label(2 * n); - subtreeLabels.assign(2 * n, vi()); - - for (int i = h - 1; i >= 0; i--) { - for (int j = 0; j < (int) L[i + 1].size(); j++) { - int v = L[i + 1][j]; - subtreeLabels[pred[v]].push_back(label[v]); - } - - sort(L[i].begin(), L[i].end(), compare); - - for (int j = 0, cnt = 0; j < (int) L[i].size(); j++) { - if (j && !equals(L[i][j], L[i][j - 1])) - ++cnt; - label[L[i][j]] = cnt; - } - } - - if (!equals(r1, r2)) - return false; - - generateMapping(r1, r2); - return true; -} - -bool treeIsomorphism() { - vi c1 = findCenter(); - vi c2 = findCenter(n); - if (c1.size() == c2.size()) { - if (rootedTreeIsomorphism(c1[0], c2[0])) - return true; - else if (c1.size() > 1) - return rootedTreeIsomorphism(c1[1], c2[0]); - } - return false; -} - -int main() { - n = 5; - vvi t1(n); - t1[0].push_back(1); - t1[1].push_back(0); - t1[1].push_back(2); - t1[2].push_back(1); - t1[1].push_back(3); - t1[3].push_back(1); - t1[0].push_back(4); - t1[4].push_back(0); - - vvi t2(n); - t2[0].push_back(1); - t2[1].push_back(0); - t2[0].push_back(4); - t2[4].push_back(0); - t2[4].push_back(3); - t2[3].push_back(4); - t2[4].push_back(2); - t2[2].push_back(4); - - tree.assign(2 * n, vi()); - for (int u = 0; u < n; u++) { - for (int i = 0; i < t1[u].size(); i++) { - int v = t1[u][i]; - tree[u].push_back(v); - } - for (int i = 0; i < t2[u].size(); i++) { - int v = t2[u][i]; - tree[u + n].push_back(v + n); - } - } - - bool res = treeIsomorphism(); - cout << res << endl; - - if (res) - for (int i = 0; i < n; i++) - cout << map[i] << endl; -} diff --git a/c++/_Basic/bigint-full.cpp b/c++/_Basic/bigint-full.cpp deleted file mode 100644 index ce1798a..0000000 --- a/c++/_Basic/bigint-full.cpp +++ /dev/null @@ -1,506 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -// base and base_digits must be consistent -const int base = 1000000000; -const int base_digits = 9; - -struct bigint { - vector a; - int sign; - - bigint() : - sign(1) { - } - - bigint(long long v) { - *this = v; - } - - bigint(const string &s) { - read(s); - } - - void operator=(const bigint &v) { - sign = v.sign; - a = v.a; - } - - void operator=(long long v) { - sign = 1; - if (v < 0) - sign = -1, v = -v; - a.clear(); - for (; v > 0; v = v / base) - a.push_back(v % base); - } - - bigint operator+(const bigint &v) const { - if (sign == v.sign) { - bigint res = v; - - for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) { - if (i == (int) res.a.size()) - res.a.push_back(0); - res.a[i] += carry + (i < (int) a.size() ? a[i] : 0); - carry = res.a[i] >= base; - if (carry) - res.a[i] -= base; - } - return res; - } - return *this - (-v); - } - - bigint operator-(const bigint &v) const { - if (sign == v.sign) { - if (abs() >= v.abs()) { - bigint res = *this; - for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) { - res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0); - carry = res.a[i] < 0; - if (carry) - res.a[i] += base; - } - res.trim(); - return res; - } - return -(v - *this); - } - return *this + (-v); - } - - void operator*=(int v) { - if (v < 0) - sign = -sign, v = -v; - for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) { - if (i == (int) a.size()) - a.push_back(0); - long long cur = a[i] * (long long) v + carry; - carry = (int) (cur / base); - a[i] = (int) (cur % base); - //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base)); - /* - int val; - __asm { - lea esi, cur - mov eax, [esi] - mov edx, [esi+4] - mov ecx, base - div ecx - mov carry, eax - mov val, edx; - } - a[i] = val; - */ - } - trim(); - } - - bigint operator*(int v) const { - bigint res = *this; - res *= v; - return res; - } - - friend pair divmod(const bigint &a1, const bigint &b1) { - int norm = base / (b1.a.back() + 1); - bigint a = a1.abs() * norm; - bigint b = b1.abs() * norm; - bigint q, r; - q.a.resize(a.a.size()); - - for (int i = a.a.size() - 1; i >= 0; i--) { - r *= base; - r += a.a[i]; - int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()]; - int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1]; - int d = ((long long) base * s1 + s2) / b.a.back(); - r -= b * d; - while (r < 0) - r += b, --d; - q.a[i] = d; - } - - q.sign = a1.sign * b1.sign; - r.sign = a1.sign; - q.trim(); - r.trim(); - return make_pair(q, r / norm); - } - - bigint operator/(const bigint &v) const { - return divmod(*this, v).first; - } - - bigint operator%(const bigint &v) const { - return divmod(*this, v).second; - } - - void operator/=(int v) { - if (v < 0) - sign = -sign, v = -v; - for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) { - long long cur = a[i] + rem * (long long) base; - a[i] = (int) (cur / v); - rem = (int) (cur % v); - } - trim(); - } - - bigint operator/(int v) const { - bigint res = *this; - res /= v; - return res; - } - - int operator%(int v) const { - if (v < 0) - v = -v; - int m = 0; - for (int i = a.size() - 1; i >= 0; --i) - m = (a[i] + m * (long long) base) % v; - return m * sign; - } - - void operator+=(const bigint &v) { - *this = *this + v; - } - void operator-=(const bigint &v) { - *this = *this - v; - } - void operator*=(const bigint &v) { - *this = *this * v; - } - void operator/=(const bigint &v) { - *this = *this / v; - } - - bool operator<(const bigint &v) const { - if (sign != v.sign) - return sign < v.sign; - if (a.size() != v.a.size()) - return a.size() * sign < v.a.size() * v.sign; - for (int i = a.size() - 1; i >= 0; i--) - if (a[i] != v.a[i]) - return a[i] * sign < v.a[i] * sign; - return false; - } - - bool operator>(const bigint &v) const { - return v < *this; - } - bool operator<=(const bigint &v) const { - return !(v < *this); - } - bool operator>=(const bigint &v) const { - return !(*this < v); - } - bool operator==(const bigint &v) const { - return !(*this < v) && !(v < *this); - } - bool operator!=(const bigint &v) const { - return *this < v || v < *this; - } - - void trim() { - while (!a.empty() && a.back() == 0) - a.pop_back(); - if (a.empty()) - sign = 1; - } - - bool isZero() const { - return a.empty() || (a.size() == 1 && !a[0]); - } - - bigint operator-() const { - bigint res = *this; - res.sign = -sign; - return res; - } - - bigint abs() const { - bigint res = *this; - res.sign *= res.sign; - return res; - } - - long long longValue() const { - long long res = 0; - for (int i = a.size() - 1; i >= 0; i--) - res = res * base + a[i]; - return res * sign; - } - - friend bigint gcd(const bigint &a, const bigint &b) { - return b.isZero() ? a : gcd(b, a % b); - } - friend bigint lcm(const bigint &a, const bigint &b) { - return a / gcd(a, b) * b; - } - - void read(const string &s) { - sign = 1; - a.clear(); - int pos = 0; - while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) { - if (s[pos] == '-') - sign = -sign; - ++pos; - } - for (int i = s.size() - 1; i >= pos; i -= base_digits) { - int x = 0; - for (int j = max(pos, i - base_digits + 1); j <= i; j++) - x = x * 10 + s[j] - '0'; - a.push_back(x); - } - trim(); - } - - friend istream& operator>>(istream &stream, bigint &v) { - string s; - stream >> s; - v.read(s); - return stream; - } - - friend ostream& operator<<(ostream &stream, const bigint &v) { - if (v.sign == -1) - stream << '-'; - stream << (v.a.empty() ? 0 : v.a.back()); - for (int i = (int) v.a.size() - 2; i >= 0; --i) - stream << setw(base_digits) << setfill('0') << v.a[i]; - return stream; - } - - static vector convert_base(const vector &a, int old_digits, int new_digits) { - vector p(max(old_digits, new_digits) + 1); - p[0] = 1; - for (int i = 1; i < (int) p.size(); i++) - p[i] = p[i - 1] * 10; - vector res; - long long cur = 0; - int cur_digits = 0; - for (int i = 0; i < (int) a.size(); i++) { - cur += a[i] * p[cur_digits]; - cur_digits += old_digits; - while (cur_digits >= new_digits) { - res.push_back(int(cur % p[new_digits])); - cur /= p[new_digits]; - cur_digits -= new_digits; - } - } - res.push_back((int) cur); - while (!res.empty() && res.back() == 0) - res.pop_back(); - return res; - } - - void fft(vector > & a, bool invert) const { - int n = (int) a.size(); - - for (int i = 1, j = 0; i < n; ++i) { - int bit = n >> 1; - for (; j >= bit; bit >>= 1) - j -= bit; - j += bit; - if (i < j) - swap(a[i], a[j]); - } - - for (int len = 2; len <= n; len <<= 1) { - double ang = 2 * 3.14159265358979323846 / len * (invert ? -1 : 1); - complex wlen(cos(ang), sin(ang)); - for (int i = 0; i < n; i += len) { - complex w(1); - for (int j = 0; j < len / 2; ++j) { - complex u = a[i + j]; - complex v = a[i + j + len / 2] * w; - a[i + j] = u + v; - a[i + j + len / 2] = u - v; - w *= wlen; - } - } - } - if (invert) - for (int i = 0; i < n; ++i) - a[i] /= n; - } - - void multiply_fft(const vector &a, const vector &b, vector &res) const { - vector > fa(a.begin(), a.end()); - vector > fb(b.begin(), b.end()); - int n = 1; - while (n < (int) max(a.size(), b.size())) - n <<= 1; - n <<= 1; - fa.resize(n); - fb.resize(n); - - fft(fa, false); - fft(fb, false); - for (int i = 0; i < n; ++i) - fa[i] *= fb[i]; - fft(fa, true); - - res.resize(n); - for (int i = 0, carry = 0; i < n; ++i) { - res[i] = int(fa[i].real() + 0.5) + carry; - carry = res[i] / 1000; - res[i] %= 1000; - } - } - - bigint operator*(const bigint &v) const { - bigint res; - res.sign = sign * v.sign; - multiply_fft(convert_base(a, base_digits, 3), convert_base(v.a, base_digits, 3), res.a); - res.a = convert_base(res.a, 3, base_digits); - res.trim(); - return res; - } - - bigint mul_simple(const bigint &v) const { - bigint res; - res.sign = sign * v.sign; - res.a.resize(a.size() + v.a.size()); - for (int i = 0; i < (int) a.size(); ++i) - if (a[i]) - for (int j = 0, carry = 0; j < (int) v.a.size() || carry; ++j) { - long long cur = res.a[i + j] + (long long) a[i] * (j < (int) v.a.size() ? v.a[j] : 0) + carry; - carry = (int) (cur / base); - res.a[i + j] = (int) (cur % base); - } - res.trim(); - return res; - } - - typedef vector vll; - - static vll karatsubaMultiply(const vll &a, const vll &b) { - int n = a.size(); - vll res(n + n); - if (n <= 32) { - for (int i = 0; i < n; i++) - for (int j = 0; j < n; j++) - res[i + j] += a[i] * b[j]; - return res; - } - - int k = n >> 1; - vll a1(a.begin(), a.begin() + k); - vll a2(a.begin() + k, a.end()); - vll b1(b.begin(), b.begin() + k); - vll b2(b.begin() + k, b.end()); - - vll a1b1 = karatsubaMultiply(a1, b1); - vll a2b2 = karatsubaMultiply(a2, b2); - - for (int i = 0; i < k; i++) - a2[i] += a1[i]; - for (int i = 0; i < k; i++) - b2[i] += b1[i]; - - vll r = karatsubaMultiply(a2, b2); - for (int i = 0; i < (int) a1b1.size(); i++) - r[i] -= a1b1[i]; - for (int i = 0; i < (int) a2b2.size(); i++) - r[i] -= a2b2[i]; - - for (int i = 0; i < (int) r.size(); i++) - res[i + k] += r[i]; - for (int i = 0; i < (int) a1b1.size(); i++) - res[i] += a1b1[i]; - for (int i = 0; i < (int) a2b2.size(); i++) - res[i + n] += a2b2[i]; - return res; - } - - bigint mul_karatsuba(const bigint &v) const { - vector a6 = convert_base(this->a, base_digits, 6); - vector b6 = convert_base(v.a, base_digits, 6); - vll a(a6.begin(), a6.end()); - vll b(b6.begin(), b6.end()); - while (a.size() < b.size()) - a.push_back(0); - while (b.size() < a.size()) - b.push_back(0); - while (a.size() & (a.size() - 1)) - a.push_back(0), b.push_back(0); - vll c = karatsubaMultiply(a, b); - bigint res; - res.sign = sign * v.sign; - for (int i = 0, carry = 0; i < (int) c.size(); i++) { - long long cur = c[i] + carry; - res.a.push_back((int) (cur % 1000000)); - carry = (int) (cur / 1000000); - } - res.a = convert_base(res.a, 6, base_digits); - res.trim(); - return res; - } -}; - -bigint getRandomBigint(int len) { - string s; - for (int i = 0; i < len; i++) - s += rand() % 10 + '0'; - return bigint(s); -} - -int main() { - srand(1); - bigint a("99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"); - bigint b("19999999999999999999999999999999999999999999999999999999999999999999999999999999999999998"); - cout << a * b << endl; - cout << a.mul_karatsuba(b) << endl; - cout << a / b << endl; - - for (int step = 0; step < 100; step++) { - bigint a = getRandomBigint(1000); - bigint b = getRandomBigint(1000); - - bigint x = a * b; - bigint y = a.mul_simple(b); - bigint z = a.mul_karatsuba(b); - - if (x != y || x != z) { - cout << a << " " << b << " " << x << " " << y << " " << z << endl; - } - } - - int steps = 1; - vector x(steps), y(steps); - for (int i = 0; i < steps; i++) { - x[i] = getRandomBigint(60000); - y[i] = getRandomBigint(60000); - } - - clock_t start = clock(); - for (int i = 0; i < steps; i++) - bigint z = x[i] * y[i]; - fprintf(stderr, "time=%.3lfsec\n", 0.001 * (clock() - start)); - - start = clock(); - for (int i = 0; i < steps; i++) - bigint z = x[i].mul_karatsuba(y[i]); - fprintf(stderr, "time=%.3lfsec\n", 0.001 * (clock() - start)); - - a = getRandomBigint(10000); - b = getRandomBigint(2000); - start = clock(); - bigint c = a / b; - fprintf(stderr, "time=%.3lfsec\n", 0.001 * (clock() - start)); - - bigint z = 5; - z = 6; - cout << z << endl; -} diff --git a/c++/_Basic/bigint.cpp b/c++/_Basic/bigint.cpp deleted file mode 100644 index 4eaed78..0000000 --- a/c++/_Basic/bigint.cpp +++ /dev/null @@ -1,446 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -// base and base_digits must be consistent -const int base = 1000000000; -const int base_digits = 9; - -struct bigint { - vector z; - int sign; - - bigint() : - sign(1) { - } - - bigint(long long v) { - *this = v; - } - - bigint(const string &s) { - read(s); - } - - void operator=(const bigint &v) { - sign = v.sign; - z = v.z; - } - - void operator=(long long v) { - sign = 1; - if (v < 0) - sign = -1, v = -v; - z.clear(); - for (; v > 0; v = v / base) - z.push_back(v % base); - } - - bigint operator+(const bigint &v) const { - if (sign == v.sign) { - bigint res = v; - - for (int i = 0, carry = 0; i < (int) max(z.size(), v.z.size()) || carry; ++i) { - if (i == (int) res.z.size()) - res.z.push_back(0); - res.z[i] += carry + (i < (int) z.size() ? z[i] : 0); - carry = res.z[i] >= base; - if (carry) - res.z[i] -= base; - } - return res; - } - return *this - (-v); - } - - bigint operator-(const bigint &v) const { - if (sign == v.sign) { - if (abs() >= v.abs()) { - bigint res = *this; - for (int i = 0, carry = 0; i < (int) v.z.size() || carry; ++i) { - res.z[i] -= carry + (i < (int) v.z.size() ? v.z[i] : 0); - carry = res.z[i] < 0; - if (carry) - res.z[i] += base; - } - res.trim(); - return res; - } - return -(v - *this); - } - return *this + (-v); - } - - void operator*=(int v) { - if (v < 0) - sign = -sign, v = -v; - for (int i = 0, carry = 0; i < (int) z.size() || carry; ++i) { - if (i == (int) z.size()) - z.push_back(0); - long long cur = z[i] * (long long) v + carry; - carry = (int) (cur / base); - z[i] = (int) (cur % base); - //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base)); - } - trim(); - } - - bigint operator*(int v) const { - bigint res = *this; - res *= v; - return res; - } - - friend pair divmod(const bigint &a1, const bigint &b1) { - int norm = base / (b1.z.back() + 1); - bigint a = a1.abs() * norm; - bigint b = b1.abs() * norm; - bigint q, r; - q.z.resize(a.z.size()); - - for (int i = a.z.size() - 1; i >= 0; i--) { - r *= base; - r += a.z[i]; - int s1 = b.z.size() < r.z.size() ? r.z[b.z.size()] : 0; - int s2 = b.z.size() - 1 < r.z.size() ? r.z[b.z.size() - 1] : 0; - int d = ((long long) s1 * base + s2) / b.z.back(); - r -= b * d; - while (r < 0) - r += b, --d; - q.z[i] = d; - } - - q.sign = a1.sign * b1.sign; - r.sign = a1.sign; - q.trim(); - r.trim(); - return make_pair(q, r / norm); - } - - friend bigint sqrt(const bigint &a1) { - bigint a = a1; - while (a.z.empty() || a.z.size() % 2 == 1) - a.z.push_back(0); - - int n = a.z.size(); - - int firstDigit = (int) sqrt((double) a.z[n - 1] * base + a.z[n - 2]); - int norm = base / (firstDigit + 1); - a *= norm; - a *= norm; - while (a.z.empty() || a.z.size() % 2 == 1) - a.z.push_back(0); - - bigint r = (long long) a.z[n - 1] * base + a.z[n - 2]; - firstDigit = (int) sqrt((double) a.z[n - 1] * base + a.z[n - 2]); - int q = firstDigit; - bigint res; - - for(int j = n / 2 - 1; j >= 0; j--) { - for(; ; --q) { - bigint r1 = (r - (res * 2 * base + q) * q) * base * base + (j > 0 ? (long long) a.z[2 * j - 1] * base + a.z[2 * j - 2] : 0); - if (r1 >= 0) { - r = r1; - break; - } - } - res *= base; - res += q; - - if (j > 0) { - int d1 = res.z.size() + 2 < r.z.size() ? r.z[res.z.size() + 2] : 0; - int d2 = res.z.size() + 1 < r.z.size() ? r.z[res.z.size() + 1] : 0; - int d3 = res.z.size() < r.z.size() ? r.z[res.z.size()] : 0; - q = ((long long) d1 * base * base + (long long) d2 * base + d3) / (firstDigit * 2); - } - } - - res.trim(); - return res / norm; - } - - bigint operator/(const bigint &v) const { - return divmod(*this, v).first; - } - - bigint operator%(const bigint &v) const { - return divmod(*this, v).second; - } - - void operator/=(int v) { - if (v < 0) - sign = -sign, v = -v; - for (int i = (int) z.size() - 1, rem = 0; i >= 0; --i) { - long long cur = z[i] + rem * (long long) base; - z[i] = (int) (cur / v); - rem = (int) (cur % v); - } - trim(); - } - - bigint operator/(int v) const { - bigint res = *this; - res /= v; - return res; - } - - int operator%(int v) const { - if (v < 0) - v = -v; - int m = 0; - for (int i = z.size() - 1; i >= 0; --i) - m = (z[i] + m * (long long) base) % v; - return m * sign; - } - - void operator+=(const bigint &v) { - *this = *this + v; - } - void operator-=(const bigint &v) { - *this = *this - v; - } - void operator*=(const bigint &v) { - *this = *this * v; - } - void operator/=(const bigint &v) { - *this = *this / v; - } - - bool operator<(const bigint &v) const { - if (sign != v.sign) - return sign < v.sign; - if (z.size() != v.z.size()) - return z.size() * sign < v.z.size() * v.sign; - for (int i = z.size() - 1; i >= 0; i--) - if (z[i] != v.z[i]) - return z[i] * sign < v.z[i] * sign; - return false; - } - - bool operator>(const bigint &v) const { - return v < *this; - } - bool operator<=(const bigint &v) const { - return !(v < *this); - } - bool operator>=(const bigint &v) const { - return !(*this < v); - } - bool operator==(const bigint &v) const { - return !(*this < v) && !(v < *this); - } - bool operator!=(const bigint &v) const { - return *this < v || v < *this; - } - - void trim() { - while (!z.empty() && z.back() == 0) - z.pop_back(); - if (z.empty()) - sign = 1; - } - - bool isZero() const { - return z.empty() || (z.size() == 1 && !z[0]); - } - - bigint operator-() const { - bigint res = *this; - res.sign = -sign; - return res; - } - - bigint abs() const { - bigint res = *this; - res.sign *= res.sign; - return res; - } - - long long longValue() const { - long long res = 0; - for (int i = z.size() - 1; i >= 0; i--) - res = res * base + z[i]; - return res * sign; - } - - friend bigint gcd(const bigint &a, const bigint &b) { - return b.isZero() ? a : gcd(b, a % b); - } - friend bigint lcm(const bigint &a, const bigint &b) { - return a / gcd(a, b) * b; - } - - void read(const string &s) { - sign = 1; - z.clear(); - int pos = 0; - while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) { - if (s[pos] == '-') - sign = -sign; - ++pos; - } - for (int i = s.size() - 1; i >= pos; i -= base_digits) { - int x = 0; - for (int j = max(pos, i - base_digits + 1); j <= i; j++) - x = x * 10 + s[j] - '0'; - z.push_back(x); - } - trim(); - } - - friend istream& operator>>(istream &stream, bigint &v) { - string s; - stream >> s; - v.read(s); - return stream; - } - - friend ostream& operator<<(ostream &stream, const bigint &v) { - if (v.sign == -1) - stream << '-'; - stream << (v.z.empty() ? 0 : v.z.back()); - for (int i = (int) v.z.size() - 2; i >= 0; --i) - stream << setw(base_digits) << setfill('0') << v.z[i]; - return stream; - } - - static vector convert_base(const vector &a, int old_digits, int new_digits) { - vector p(max(old_digits, new_digits) + 1); - p[0] = 1; - for (int i = 1; i < (int) p.size(); i++) - p[i] = p[i - 1] * 10; - vector res; - long long cur = 0; - int cur_digits = 0; - for (int i = 0; i < (int) a.size(); i++) { - cur += a[i] * p[cur_digits]; - cur_digits += old_digits; - while (cur_digits >= new_digits) { - res.push_back(int(cur % p[new_digits])); - cur /= p[new_digits]; - cur_digits -= new_digits; - } - } - res.push_back((int) cur); - while (!res.empty() && res.back() == 0) - res.pop_back(); - return res; - } - - typedef vector vll; - - static vll karatsubaMultiply(const vll &a, const vll &b) { - int n = a.size(); - vll res(n + n); - if (n <= 32) { - for (int i = 0; i < n; i++) - for (int j = 0; j < n; j++) - res[i + j] += a[i] * b[j]; - return res; - } - - int k = n >> 1; - vll a1(a.begin(), a.begin() + k); - vll a2(a.begin() + k, a.end()); - vll b1(b.begin(), b.begin() + k); - vll b2(b.begin() + k, b.end()); - - vll a1b1 = karatsubaMultiply(a1, b1); - vll a2b2 = karatsubaMultiply(a2, b2); - - for (int i = 0; i < k; i++) - a2[i] += a1[i]; - for (int i = 0; i < k; i++) - b2[i] += b1[i]; - - vll r = karatsubaMultiply(a2, b2); - for (int i = 0; i < (int) a1b1.size(); i++) - r[i] -= a1b1[i]; - for (int i = 0; i < (int) a2b2.size(); i++) - r[i] -= a2b2[i]; - - for (int i = 0; i < (int) r.size(); i++) - res[i + k] += r[i]; - for (int i = 0; i < (int) a1b1.size(); i++) - res[i] += a1b1[i]; - for (int i = 0; i < (int) a2b2.size(); i++) - res[i + n] += a2b2[i]; - return res; - } - - bigint operator*(const bigint &v) const { - vector a6 = convert_base(this->z, base_digits, 6); - vector b6 = convert_base(v.z, base_digits, 6); - vll a(a6.begin(), a6.end()); - vll b(b6.begin(), b6.end()); - while (a.size() < b.size()) - a.push_back(0); - while (b.size() < a.size()) - b.push_back(0); - while (a.size() & (a.size() - 1)) - a.push_back(0), b.push_back(0); - vll c = karatsubaMultiply(a, b); - bigint res; - res.sign = sign * v.sign; - for (int i = 0, carry = 0; i < (int) c.size(); i++) { - long long cur = c[i] + carry; - res.z.push_back((int) (cur % 1000000)); - carry = (int) (cur / 1000000); - } - res.z = convert_base(res.z, 6, base_digits); - res.trim(); - return res; - } -}; - -bigint random_bigint(int n) { - string s; - for (int i = 0; i < n; i++) { - s += rand() % 10 + '0'; - } - return bigint(s); -} - -// random tests -int main() { - for(int i = 0; i < 1000; i++) { - cout << i << endl; - int n = rand() % 100 + 1; - bigint a = random_bigint(n); - bigint res = sqrt(a); - bigint xx = res * res; - bigint yy = (res + 1) * (res + 1); - - if (xx > a || yy <= a) { - cout << a << " " << res << endl; - break; - } - - int m = rand() % n + 1; - bigint b = random_bigint(m) + 1; - res = a / b; - xx = res * b; - yy = b * (res + 1); - - if (xx > a || yy <= a) { - cout << a << " " << b << " " << res << endl; - break; - } - } - - bigint a = random_bigint(10000); - bigint b = random_bigint(2000); - clock_t start = clock(); - bigint c = a / b; - fprintf(stdout, "time=%.3lfsec\n", 0.001 * (clock() - start)); - - bigint x = 5; - x = 6; - cout << x << endl; -} diff --git a/c++/_Basic/nCr & nPr.cpp b/c++/_Basic/nCr & nPr.cpp deleted file mode 100644 index 63754e3..0000000 --- a/c++/_Basic/nCr & nPr.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include < iostream.h > - -long factorial(int); -long find_ncr(int, int); -long find_npr(int, int); - -main() -{ - int n, r; - long ncr, npr; - cout<<"Enter the value of n and r\n"; - cin>>n>>r; - ncr = find_ncr(n, r); - npr = find_npr(n, r); - cout< -#include -#include -#include -using namespace std; - -typedef complex cdouble; -typedef vector poly; - -pair horner(const poly &a, cdouble x0) { - int n = a.size(); - poly b = poly(max(1, n - 1)); - - for(int i = n - 1; i > 0; i--) - b[i - 1] = a[i] + (i < n - 1 ? b[i] * x0 : 0); - return make_pair(b, a[0] + b[0] * x0); -} - -cdouble eval(const poly &p, cdouble x) { - return horner(p, x).second; -} - -poly derivative(const poly &p) { - int n = p.size(); - poly r = poly(max(1, n - 1)); - for(int i = 1; i < n; i++) - r[i - 1] = p[i] * cdouble(i); - return r; -} - -const double EPS = 1e-9; - -int cmp(cdouble x, cdouble y) { - double diff = abs(x) - abs(y); - return diff < -EPS ? -1 : (diff > EPS ? 1 : 0); -} - -cdouble find_one_root(const poly &p0, cdouble x) { - int n = p0.size() - 1; - poly p1 = derivative(p0); - poly p2 = derivative(p1); - for (int step = 0; step < 10000; step++) { - cdouble y0 = eval(p0, x); - if (cmp(y0, 0) == 0) break; - cdouble G = eval(p1, x) / y0; - cdouble H = G * G - eval(p2, x) - y0; - cdouble R = sqrt(cdouble(n - 1) * (H * cdouble(n) - G * G)); - cdouble D1 = G + R; - cdouble D2 = G - R; - cdouble a = cdouble(n) / (cmp(D1, D2) > 0 ? D1 : D2); - x -= a; - if (cmp(a, 0) == 0) break; - } - return x; -} - -vector find_all_roots(const poly &p) { - vector res; - poly q = p; - while (q.size() > 2) { - cdouble z(rand() / double(RAND_MAX), rand() / double(RAND_MAX)); - z = find_one_root(q, z); - z = find_one_root(p, z); - q = horner(q, z).first; - res.push_back(z); - } - res.push_back(-q[0] / q[1]); - return res; -} - -int main( int argc, char* argv[] ) { - poly p; - // x^3 - 8x^2 - 13x + 140 = (x+4)(x-5)(x-7) - p.push_back(140); - p.push_back(-13); - p.push_back(-8); - p.push_back(1); - - vector roots = find_all_roots(p); - - for(size_t i = 0; i < roots.size(); i++) { - if (abs(roots[i].real()) < EPS) roots[i] -= cdouble(roots[i].real(), 0); - if (abs(roots[i].imag()) < EPS) roots[i] -= cdouble(0, roots[i].imag()); - cout << setprecision(3) << roots[i] << endl; - } - - return 0; -} diff --git a/c-sharp/_Basic/C# Program to Accept a Number from the user and Display it if it is Positive.cs b/c-sharp/_Basic/C# Program to Accept a Number from the user and Display it if it is Positive.cs deleted file mode 100644 index 95685b9..0000000 --- a/c-sharp/_Basic/C# Program to Accept a Number from the user and Display it if it is Positive.cs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * C# Program to Accept a Number from the user and Display it - * if it is Positive - */ -using System; -class program -{ - public static void Main(string[] args) - { - Console.WriteLine("Enter a number: "); - int number = Convert.ToInt32(Console.ReadLine()); - if (number > 0) - { - Console.WriteLine("Number is positive"); - } - else if (number == 0) - { - Console.WriteLine("Number is 0"); - } - else - { - Console.WriteLine("Number is negative"); - } - Console.ReadLine(); - } -} - -/* -Enter a Number : -4 -Number is Negative \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Accept the Height of a Person & Categorize as Tall, Dwarf or Average.cs b/c-sharp/_Basic/C# Program to Accept the Height of a Person & Categorize as Tall, Dwarf or Average.cs deleted file mode 100644 index 43eaf08..0000000 --- a/c-sharp/_Basic/C# Program to Accept the Height of a Person & Categorize as Tall, Dwarf or Average.cs +++ /dev/null @@ -1,27 +0,0 @@ -/* - * C# Program to Accept the Height of a Person & Categorize as - * Tall, Dwarf or Average - */ -using System; -class program -{ - public static void Main() - { - float height; - Console.WriteLine("Enter the Height (in centimeters) \n"); - height = int.Parse(Console.ReadLine()); - if (height < 150.0) - Console.WriteLine("Dwarf \n"); - else if ((height >= 150.0) && (height <= 165.0)) - Console.WriteLine(" Average Height \n"); - else if ((height >= 165.0) && (height <= 195.0)) - Console.WriteLine("Taller \n"); - else - Console.WriteLine("Abnormal height \n"); - } -} - -/* -Enter the Height (in centimeters) -165 - Average Height \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Calculate Acceleration.cs b/c-sharp/_Basic/C# Program to Calculate Acceleration.cs deleted file mode 100644 index 25719e7..0000000 --- a/c-sharp/_Basic/C# Program to Calculate Acceleration.cs +++ /dev/null @@ -1,23 +0,0 @@ -/* - * C# Program to Calculate Acceleration -using System; -class program -{ - static void Main(string[] args) - { - int v, t, acc; - Console.WriteLine("Enter the Velocity : "); - v = int.Parse(Console.ReadLine()); - Console.WriteLine("Enter the Time : "); - t = int.Parse(Console.ReadLine()); - acc = v / t; - Console.WriteLine("Acceleration : {0}", acc); - } -} - -/* -Enter the Velocity : -10 -Enter the Time : -2 -Acceleration : 5 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Check Whether the Entered Year is a Leap Year or Not.cs b/c-sharp/_Basic/C# Program to Check Whether the Entered Year is a Leap Year or Not.cs deleted file mode 100644 index d0220a2..0000000 --- a/c-sharp/_Basic/C# Program to Check Whether the Entered Year is a Leap Year or Not.cs +++ /dev/null @@ -1,42 +0,0 @@ -/* - * C# Program to Check Whether the Entered Year is a Leap Year or Not - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Program -{ -class leapyear -{ - static void Main(string[] args) - { - leapyear obj = new leapyear(); - obj.readdata(); - obj.leap(); - } - int y; - public void readdata() - { - Console.WriteLine("Enter the Year in Four Digits : "); - y = Convert.ToInt32(Console.ReadLine()); - } - public void leap() - { - if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) - { - Console.WriteLine("{0} is a Leap Year", y); - } - else - { - Console.WriteLine("{0} is not a Leap Year", y); - } - Console.ReadLine(); - } -} -} - -/* -Enter the Year in Four Digits : 1004 -1004 is a Leap Year \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Check whether the Entered Number is Even or Odd.cs b/c-sharp/_Basic/C# Program to Check whether the Entered Number is Even or Odd.cs deleted file mode 100644 index ccfb25d..0000000 --- a/c-sharp/_Basic/C# Program to Check whether the Entered Number is Even or Odd.cs +++ /dev/null @@ -1,34 +0,0 @@ -/* - * C# Program to Check whether the Entered Number is Even or Odd - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace check1 -{ -class Program -{ - static void Main(string[] args) - { - int i; - Console.Write("Enter a Number : "); - i = int.Parse(Console.ReadLine()); - if (i % 2 == 0) - { - Console.Write("Entered Number is an Even Number"); - Console.Read(); - } - else - { - Console.Write("Entered Number is an Odd Number"); - Console.Read(); - } - } -} -} - -/* -Enter a Number : 25 -Entered Number is an Odd Number \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Check whether the given Integer has an Alternate Pattern.cs b/c-sharp/_Basic/C# Program to Check whether the given Integer has an Alternate Pattern.cs deleted file mode 100644 index 0f19804..0000000 --- a/c-sharp/_Basic/C# Program to Check whether the given Integer has an Alternate Pattern.cs +++ /dev/null @@ -1,45 +0,0 @@ -/* - * C# Program to Check whether the given Integer has an - * Alternate Pattern - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -class program -{ - public static void Main() - { - int num, x, y, count = 0; - Console.WriteLine("Enter the Number:"); - num = int.Parse(Console.ReadLine()); - x = num << 1; - y = x ^ num; - y = y + 1; - while ((y / 2) != 0) - { - if (y % 2 != 0) - { - count++; - break; - } - else - { - y = y / 2; - } - } - if (count == 1) - { - Console.WriteLine("false"); - } - else - { - Console.WriteLine("true"); - } - Console.Read(); - } -} - -/* -Enter the Number: 100 -false \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Compare Two Dates.cs b/c-sharp/_Basic/C# Program to Compare Two Dates.cs deleted file mode 100644 index ab6a902..0000000 --- a/c-sharp/_Basic/C# Program to Compare Two Dates.cs +++ /dev/null @@ -1,26 +0,0 @@ -/* - * C# Program to Campare Two Dates - */ -using System; -namespace DateAndTime -{ -class Program -{ - static int Main() - { - DateTime sd = new DateTime(2010, 10, 12); - Console.WriteLine("Starting Date : {0}", sd); - DateTime ed = sd.AddDays(10); - Console.WriteLine("Ending Date : {0}", ed); - if (sd < ed) - Console.WriteLine("{0} Occurs Before {1}", sd, ed); - Console.Read(); - return 0; - } -} -} - -/* -Starting Date : 10/11/2010 12:00:00 AM -Ending Date : 10/21/2010 12:00:00 AM -10/11/2010 12:00:00 Am Occurs Before 10/21/2010 12:00:00 AM \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Compute Average for the Set of Values.cs b/c-sharp/_Basic/C# Program to Compute Average for the Set of Values.cs deleted file mode 100644 index 026f551..0000000 --- a/c-sharp/_Basic/C# Program to Compute Average for the Set of Values.cs +++ /dev/null @@ -1,35 +0,0 @@ -/* - * C# Program to Compute Average for the Set of Values - */ -using System; -class program -{ - public static void Main() - { - int m, i, sum = 0, avg = 0; - Console.WriteLine("Enter the Number of Terms in the Array "); - m = int.Parse(Console.ReadLine()); - int[] a = new int[m]; - Console.WriteLine("Enter the Array Elements "); - for (i = 0; i < m; i++) - { - a[i] = int.Parse(Console.ReadLine()); - } - for (i = 0; i < m; i++) - { - sum += a[i]; - } - avg = sum / m; - Console.WriteLine("Average is {0}", avg); - Console.ReadLine(); - } -} - -/* -Enter the Number of Terms in the Array : 4 -Enter the Elements -1 -2 -3 -4 -Average is 2 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Count the Number of 1’s in the Entered Number.cs b/c-sharp/_Basic/C# Program to Count the Number of 1’s in the Entered Number.cs deleted file mode 100644 index 60c4b5c..0000000 --- a/c-sharp/_Basic/C# Program to Count the Number of 1’s in the Entered Number.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * C# Program to Count the Number of 1's in the Entered Number - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ConsoleApplication16 -{ -class Program -{ - static void Main(string[] args) - { - int m, count = 0; - Console.WriteLine("Enter the Limit : "); - m = int.Parse(Console.ReadLine()); - int[] a = new int[m]; - Console.WriteLine("Enter the Numbers :"); - for (int i = 0; i < m; i++) - { - a[i] = Convert.ToInt32(Console.ReadLine()); - } - foreach (int o in a) - { - if (o == 1) - { - count++; - } - } - Console.WriteLine("Number of 1's in the Entered Number : "); - Console.WriteLine(count); - Console.ReadLine(); - } -} -} - -/* -Enter the Limit : 5 -Enter the Numbers : -1 -2 -1 -4 -1 -Number of 1's in the Entered Number : 3 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Create Sealed Class.cs b/c-sharp/_Basic/C# Program to Create Sealed Class.cs deleted file mode 100644 index 6dd6481..0000000 --- a/c-sharp/_Basic/C# Program to Create Sealed Class.cs +++ /dev/null @@ -1,24 +0,0 @@ -/* - * C# Program to Create Sealed Class - */ -using System; -sealed class SealedClass -{ - public int x; - public int y; -} - -class SealedTest -{ - static void Main() - { - SealedClass sc = new SealedClass(); - sc.x = 100; - sc.y = 180; - Console.WriteLine("x = {0}, y = {1}", sc.x, sc.y); - Console.ReadLine(); - } -} - -/* -x = 100 ,y = 180 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Display All the Prime Numbers Between 1 to 100.cs b/c-sharp/_Basic/C# Program to Display All the Prime Numbers Between 1 to 100.cs deleted file mode 100644 index 64c7c9a..0000000 --- a/c-sharp/_Basic/C# Program to Display All the Prime Numbers Between 1 to 100.cs +++ /dev/null @@ -1,41 +0,0 @@ -/* - * C# Program to Display All the Prime Numbers Between 1 to 100 - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -namespace PrimeNumber -{ -class Program -{ - static void Main(string[] args) - { - bool isPrime = true; - Console.WriteLine("Prime Numbers : "); - for (int i = 2; i <= 100; i++) - { - for (int j = 2; j <= 100; j++) - { - if (i != j && i % j == 0) - { - isPrime = false; - break; - } - } - if (isPrime) - { - Console.Write("\t" +i); - } - isPrime = true; - } - Console.ReadKey(); - } -} -} - -/* -Prime Numbers : - 2 3 5 7 11 13 17 19 23 29 -31 37 41 43 47 53 59 61 67 71 -73 79 83 89 97 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Display Numbers in the form of Triangle.cs b/c-sharp/_Basic/C# Program to Display Numbers in the form of Triangle.cs deleted file mode 100644 index 3f3c88e..0000000 --- a/c-sharp/_Basic/C# Program to Display Numbers in the form of Triangle.cs +++ /dev/null @@ -1,42 +0,0 @@ -/* - * C# Program to Display Numbers in the form of Triangle - */ -using System; -class Pascal -{ - public static void Main() - { - int[,] arr = new int[8, 8]; - for (int i = 0; i < 8; i++) - { - for (int k = 7; k > i; k--) - { - //For loop to print spaces - Console.Write(" "); - } - for (int j = 0; j < i; j++) - { - if (j == 0 || i == j) - { - arr[i, j] = 1; - } - else - { - arr[i, j] = arr[i - 1, j] + arr[i - 1, j - 1]; - } - Console.Write(arr[i, j] + " "); - } - Console.WriteLine(); - } - Console.ReadLine(); - } -} - -/* - 1 - 1 1 - 1 2 1 - 1 3 3 1 - 1 4 6 4 1 - 1 5 10 10 5 1 -1 6 15 20 15 6 1 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Display Squarefeet of a House.cs b/c-sharp/_Basic/C# Program to Display Squarefeet of a House.cs deleted file mode 100644 index 41418c6..0000000 --- a/c-sharp/_Basic/C# Program to Display Squarefeet of a House.cs +++ /dev/null @@ -1,23 +0,0 @@ -/* - * C# Program to Display Squarefeet of a House - */ -using System; -class pgm -{ - public static void Main() - { - int length, width, area; - Console.Write ("Enter length of room in feet: "); - length = Convert.ToInt32 (Console.ReadLine()); - Console.Write ( "Enter width of room in feet:"); - width = Convert.ToInt32(Console.ReadLine()); - area = length * width; - Console.WriteLine ("Floor is " + area + " square feet."); - Console.ReadLine(); - } -} - -/* -Enter Length of Room in Feet : 20 -Enter width of Room in Feet : 20 -Floor is 400 square feet. \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Display the ATM Transaction.cs b/c-sharp/_Basic/C# Program to Display the ATM Transaction.cs deleted file mode 100644 index 12e1bed..0000000 --- a/c-sharp/_Basic/C# Program to Display the ATM Transaction.cs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * C# Program to Display the ATM Transaction - */ -using System; -class program -{ - public static void Main() - { - int amount = 1000, deposit, withdraw; - int choice, pin = 0, x = 0; - Console.WriteLine("Enter Your Pin Number "); - pin = int.Parse(Console.ReadLine()); - while (true) - { - Console.WriteLine("********Welcome to ATM Service**************\n"); - Console.WriteLine("1. Check Balance\n"); - Console.WriteLine("2. Withdraw Cash\n"); - Console.WriteLine("3. Deposit Cash\n"); - Console.WriteLine("4. Quit\n"); - Console.WriteLine("*********************************************\n\n"); - Console.WriteLine("Enter your choice: "); - choice = int.Parse(Console.ReadLine()); - switch (choice) - { - case 1: - Console.WriteLine("\n YOUR BALANCE IN Rs : {0} ", amount); - break; - case 2: - Console.WriteLine("\n ENTER THE AMOUNT TO WITHDRAW: "); - withdraw = int.Parse(Console.ReadLine()); - if (withdraw % 100 != 0) - { - Console.WriteLine("\n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100"); - } - else if (withdraw > (amount - 500)) - { - Console.WriteLine("\n INSUFFICENT BALANCE"); - } - else - { - amount = amount - withdraw; - Console.WriteLine("\n\n PLEASE COLLECT CASH"); - Console.WriteLine("\n YOUR CURRENT BALANCE IS {0}", amount); - } - break; - case 3: - Console.WriteLine("\n ENTER THE AMOUNT TO DEPOSIT"); - deposit = int.Parse(Console.ReadLine()); - amount = amount + deposit; - Console.WriteLine("YOUR BALANCE IS {0}", amount); - break; - case 4: - Console.WriteLine("\n THANK U USING ATM"); - break; - } - } - Console.WriteLine("\n\n THANKS FOR USING OUT ATM SERVICE"); - } -} - -/* -Enter Your Pin Number -123 -********Welcome to ATM Service************** - -1. Check Balance - -2. Withdraw Cash - -3. Deposit Cash - -4. Quit - -********************************************* -Enter your choice: -1 -YOUR BALANCE IN Rs : 1000 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Display the Date in Various Formats.cs b/c-sharp/_Basic/C# Program to Display the Date in Various Formats.cs deleted file mode 100644 index 3d3e761..0000000 --- a/c-sharp/_Basic/C# Program to Display the Date in Various Formats.cs +++ /dev/null @@ -1,36 +0,0 @@ -/* - * C# Program to Display the Date in Various Formats - */ -using System; -namespace DateAndTime -{ -class Program -{ - static int Main() - { - DateTime date = new DateTime(2013,6, 23); - Console.WriteLine("Some Date Formats : "); - Console.WriteLine("Date and Time: {0}", date); - Console.WriteLine(date.ToString("yyyy-MM-dd")); - Console.WriteLine(date.ToString("dd-MMM-yy")); - Console.WriteLine(date.ToString("M/d/yyyy")); - Console.WriteLine(date.ToString("M/d/yy")); - Console.WriteLine(date.ToString("MM/dd/yyyy")); - Console.WriteLine(date.ToString("MM/dd/yy")); - Console.WriteLine(date.ToString("yy/MM/dd")); - Console.Read(); - return 0; - } -} -} - -/* -Some Date Formats : -Date and Time : 6/23/2013 12:00:00 AM -2013-06-23 -23-Jun-13 -6/23/2013 -6/23/13 -06/23/2013 -06/23/13 -13/06/23 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Find Greatest among 2 numbers.cs b/c-sharp/_Basic/C# Program to Find Greatest among 2 numbers.cs deleted file mode 100644 index bb4e35e..0000000 --- a/c-sharp/_Basic/C# Program to Find Greatest among 2 numbers.cs +++ /dev/null @@ -1,29 +0,0 @@ -/* - * C# Program to Find Greatest among 2 numbers - */ -using System; -class prog -{ - public static void Main() - { - int a, b; - Console.WriteLine("Enter the Two Numbers : "); - a = Convert.ToInt32(Console.ReadLine()); - b = Convert.ToInt32(Console.ReadLine()); - if (a > b) - { - Console.WriteLine("{0} is the Greatest Number", a); - } - else - { - Console.WriteLine("{0} is the Greatest Number ", b); - } - Console.ReadLine(); - } -} - -/* -Enter the Two Numbers : -24 -34 -34 is the Greatest Number \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Find Magnitude of Integer.cs b/c-sharp/_Basic/C# Program to Find Magnitude of Integer.cs deleted file mode 100644 index 003239c..0000000 --- a/c-sharp/_Basic/C# Program to Find Magnitude of Integer.cs +++ /dev/null @@ -1,26 +0,0 @@ -/* - * C# Program to Find Magnitude of Integer - */ -using System; -public class Program -{ - public static void Main() - { - int num, mag=0; - Console.WriteLine("Enter the Number : "); - num = int.Parse(Console.ReadLine()); - Console.WriteLine("Number: " + num); - while (num > 0) - { - mag++; - num = num / 10; - }; - Console.WriteLine("Magnitude: " + mag); - Console.Read(); - } -} - -/* -Enter the Number : 3145678 -Number : 3145678 -Magnitude : 7 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Find a Number using Pythagoras Theorem.cs b/c-sharp/_Basic/C# Program to Find a Number using Pythagoras Theorem.cs deleted file mode 100644 index 6122fcf..0000000 --- a/c-sharp/_Basic/C# Program to Find a Number using Pythagoras Theorem.cs +++ /dev/null @@ -1,28 +0,0 @@ -/* - * C# Program to Find a Number using Pythagoras Theorem - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -class Program -{ - static void Main(string[] args) - { - double a, b, c; - Console.WriteLine("Enter the First Value "); - a = double.Parse(Console.ReadLine()); - Console.WriteLine("Enter the Second Value "); - b = double.Parse(Console.ReadLine()); - c = Math.Sqrt(a * a + b * b); - Console.WriteLine("The Other Number is : {0}", c); - Console.ReadLine(); - } -} - -/* -Enter the First Value -3 -Enter the Second Value -4 -The Other Number is : 5 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Generate Random Numbers.cs b/c-sharp/_Basic/C# Program to Generate Random Numbers.cs deleted file mode 100644 index ec53c24..0000000 --- a/c-sharp/_Basic/C# Program to Generate Random Numbers.cs +++ /dev/null @@ -1,34 +0,0 @@ -/* - * C# Program to Generate Random Numbers - */ -using System; -class Program -{ - static void Main() - { - Console.WriteLine("Some Random Numbers that are generated are : "); - for (int i = 1; i < 10; i++) - { - Randfunc(); - } - } - static Random r = new Random(); - static void Randfunc() - { - int n = r.Next(); - Console.WriteLine(n); - Console.ReadLine(); - } -} - -/* -Some Random Numbers that are generated are : -1234567 -8754352 -9864930 -8352048 -1920472 -2846104 -7649207 -4928756 -9261746 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Get a Number and Display the Number with its Reverse.cs b/c-sharp/_Basic/C# Program to Get a Number and Display the Number with its Reverse.cs deleted file mode 100644 index c8e6b06..0000000 --- a/c-sharp/_Basic/C# Program to Get a Number and Display the Number with its Reverse.cs +++ /dev/null @@ -1,31 +0,0 @@ -/* - * C# Program to Get a Number and Display the Number with its Reverse - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Program -{ -class Program -{ - static void Main(string[] args) - { - int num, reverse = 0; - Console.WriteLine("Enter a Number : "); - num = int.Parse(Console.ReadLine()); - while (num != 0) - { - reverse = reverse * 10; - reverse = reverse + num % 10; - num = num / 10; - } - Console.WriteLine("Reverse of Entered Number is : "+reverse); - Console.ReadLine(); - } -} -} - -Enter a Number : 123 -Reverse of Entered Number : 321 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Get a Number and Display the Sum of the Digits.cs b/c-sharp/_Basic/C# Program to Get a Number and Display the Sum of the Digits.cs deleted file mode 100644 index 07f7583..0000000 --- a/c-sharp/_Basic/C# Program to Get a Number and Display the Sum of the Digits.cs +++ /dev/null @@ -1,31 +0,0 @@ -/* - * C# Program to Get a Number and Display the Sum of the Digits - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Program -{ -class Program -{ - static void Main(string[] args) - { - int num, sum = 0, r; - Console.WriteLine("Enter a Number : "); - num = int.Parse(Console.ReadLine()); - while (num != 0) - { - r = num % 10; - num = num / 10; - sum = sum + r; - } - Console.WriteLine("Sum of Digits of the Number : "+sum); - Console.ReadLine(); - } -} -} - -Enter a Number : 123 -Sum of Digits of the Number : 6 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Illustrate LeftShift Operations.cs b/c-sharp/_Basic/C# Program to Illustrate LeftShift Operations.cs deleted file mode 100644 index 08779a7..0000000 --- a/c-sharp/_Basic/C# Program to Illustrate LeftShift Operations.cs +++ /dev/null @@ -1,28 +0,0 @@ -/* - * C# Program to Illustrate LeftShift Operations - */ -using System; -class sample -{ - public static void Main() - { - int x = 1024 * 1024 * 1024; - uint p = 1024 * 1024 * 1024; - int y = -42; - Console.WriteLine("LEFT SHIFT OPERATIONS :"); - Console.WriteLine("{0},{1},{2}", x, x * 2, x << 1); - Console.WriteLine("{0},{1},{2}", p, p * 2, p << 1); - Console.WriteLine("{0},{1},{2}", x, x * 4, x << 2); - Console.WriteLine("{0},{1},{2}", p, p * 4, p << 2); - Console.WriteLine("{0},{1},{2}", y, y * 1024 * 1024 * 64, x << 26); - Console.ReadLine(); - } -} - -/* -LEFT SHIFT OPERATIONS : -1073741824,-2147483648,-2147483648 -1073741824,2147483648,2147483648 -1073741824,0,0 -1073741824,0,0 --42,1476395008,0 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Illustrate the Use of Access Specifiers.cs b/c-sharp/_Basic/C# Program to Illustrate the Use of Access Specifiers.cs deleted file mode 100644 index d7d0479..0000000 --- a/c-sharp/_Basic/C# Program to Illustrate the Use of Access Specifiers.cs +++ /dev/null @@ -1,48 +0,0 @@ -/* - * C# Program to Illustrate the Use of Access Specifiers - */ -using System; -namespace accessspecifier -{ -class Program -{ - static void Main(string[] args) - { - two B = new two(); - B.show(); - } -} -class one -{ - private int x; - protected int y; - internal int z; - public int a; - protected internal int b; -} -class two : one -{ - public void show() - { - Console.WriteLine("Values are : "); - //x=10; - y = 20; - z = 30; - a = 40; - b = 50; - // Console.WriteLine(+x); // Error x is not accessible - Console.WriteLine(y); - Console.WriteLine(z); - Console.WriteLine(a); - Console.WriteLine(b); - Console.ReadLine(); - } -} -} - -/* -Values are : -20 -30 -40 -50 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Implement PhoneBook.cs b/c-sharp/_Basic/C# Program to Implement PhoneBook.cs deleted file mode 100644 index ed3cda3..0000000 --- a/c-sharp/_Basic/C# Program to Implement PhoneBook.cs +++ /dev/null @@ -1,52 +0,0 @@ -/* - * C# Program to Implement PhoneBook - */ -using System; -using System.Collections; -using System.IO; -class PhoneBook -{ - - static void Main(string[] arg) - { - Hashtable tab = new Hashtable(); - string fileName; - if - { - (arg.Length > 0) fileName = arg[0]; - } - else - { - fileName = "phoneBook.txt"; - } - StreamReader r = File.OpenText(fileName); - string line = r.ReadLine(); - while (line != null) - { - int pos = line.IndexOf('='); - string name = line.Substring(0, pos).Trim(); - long phone = Convert.ToInt64(line.Substring(pos + 1)); - tab[name] = phone; - line = r.ReadLine(); - } - r.Close(); - for (; ; ) - { - Console.Write("Name : "); - string name = Console.ReadLine().Trim(); - if (name == "") - break; - object phone = tab[name]; - if (phone == null) - Console.WriteLine("-- Not Found in Phone Book"); - else - Console.WriteLine(phone); - } - } -} - -/* -Name : Ram -9999945670 -Name : Raj --- Not Found in Phone Book \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Implement for-each in Inteface.cs b/c-sharp/_Basic/C# Program to Implement for-each in Inteface.cs deleted file mode 100644 index 8637230..0000000 --- a/c-sharp/_Basic/C# Program to Implement for-each in Inteface.cs +++ /dev/null @@ -1,85 +0,0 @@ -/* - * C# Program to Implement for-each in Inteface - */ -using System; -using System.Collections; -class GrowableArray : IEnumerable -{ - object[] a; - public GrowableArray(int size) - { - a = new object[size]; - } - public GrowableArray() : this(8) {} - void Grow() - { - object[] b = new object[2 * a.Length]; - Array.Copy(a, b, a.Length); - a = b; - } - public object this[int i] - { - set - { - if (i >= a.Length) Grow(); - a[i] = value; - } - get - { - if (i >= a.Length) Grow(); - return a[i]; - } - } - public IEnumerator GetEnumerator() - { - return new GAEnumerator(a); - } - class GAEnumerator : IEnumerator - { - object[] a; - int i = -1; - public GAEnumerator(object[] a) - { - this.a = a; - } - public object Current - { - get - { - return a[i]; - } - } - public void Reset() - { - i = -1; - } - public bool MoveNext() - { - do i++; - while (i < a.Length && a[i] == null); - if (i == a.Length) - return false; - else return true; - } - } - -} -class Test -{ - public static void Main() - { - GrowableArray a = new GrowableArray(2); - a[0] = 0; - a[1] = 1; - a[3] = 3; - foreach (object x in a) Console.Write(" " + x); - } - - /* - Demonstrating foreach Interface by Displaying Numbers from 100 to 105 : - 100 - 101 - 102 - 103 - 104 - 105 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Perform Division of Exponents of Same Base.cs b/c-sharp/_Basic/C# Program to Perform Division of Exponents of Same Base.cs deleted file mode 100644 index 64c5bde..0000000 --- a/c-sharp/_Basic/C# Program to Perform Division of Exponents of Same Base.cs +++ /dev/null @@ -1,29 +0,0 @@ -/* - * C# Program to Perform Division of Exponents of Same Base - */ -using System; -class Program -{ - static void Main() - { - Console.WriteLine("Enter the Base : "); - double num = double.Parse(Console.ReadLine()); - Console.WriteLine("Enter the First Exponent :"); - double exp1 = double.Parse(Console.ReadLine()); - Console.WriteLine("Enter the Second Exponent :"); - double exp2 = double.Parse(Console.ReadLine()); - double div; - div = exp1 - exp2; - Console.WriteLine("Result is : {0}^{1} : {2}", num, div, Math.Pow(num, div)); - Console.ReadLine(); - } -} - -/* -Enter the Base : -2 -Enter the First Exponent : -4 -Enter the Second Exponent : -3 -Result is : 2^1 : 2 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Perform Unboxing Operation.cs b/c-sharp/_Basic/C# Program to Perform Unboxing Operation.cs deleted file mode 100644 index cd2d9ca..0000000 --- a/c-sharp/_Basic/C# Program to Perform Unboxing Operation.cs +++ /dev/null @@ -1,29 +0,0 @@ -/* - * C# Program to Perform Unboxing Operation - */ -using System; -class sample -{ - int data; - void insert(object x) - { - data = (int)x * 5; - } - object delete() - { - data=0; - return (object)data; - } - public static void Main() - { - sample s = new sample(); - s.insert(10); - Console.WriteLine("Data : {0}", s.data); - Console.WriteLine("Data : {0}", s.delete()); - Console.ReadLine(); - } -} - -/* -Data : 50 -Data : 0 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Print a BinaryTriangle.cs b/c-sharp/_Basic/C# Program to Print a BinaryTriangle.cs deleted file mode 100644 index d8e3c5a..0000000 --- a/c-sharp/_Basic/C# Program to Print a BinaryTriangle.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * C# Program to Print a BinaryTriangle - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Program -{ -class Program -{ - public static void Main(String[] args) - { - int p, lastInt = 0, input; - Console.WriteLine("Enter the Number of Rows : "); - input = int.Parse(Console.ReadLine()); - for (int i = 1; i <= input; i++) - { - for (p = 1; p <= i; p++) - { - if (lastInt == 1) - { - Console.Write("0"); - lastInt = 0; - } - else if (lastInt == 0) - { - Console.Write("1"); - lastInt = 1; - } - } - Console.Write("\n"); - } - Console.ReadLine(); - } -} -} - -/* -Enter the Number of Rows : 5 -1 -01 -010 -1010 -10101 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Print a Diamond Using Nested Loop.cs b/c-sharp/_Basic/C# Program to Print a Diamond Using Nested Loop.cs deleted file mode 100644 index e8f0c68..0000000 --- a/c-sharp/_Basic/C# Program to Print a Diamond Using Nested Loop.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* - * C# Program to Print the Sum of all the Multiples of 3 and 5 - */ -using System; -class program -{ - public static void Main() - { - int number, i, k, count = 1; - Console.Write("Enter number of rows\n"); - number = int.Parse(Console.ReadLine()); - count = number - 1; - for (k = 1; k <= number; k++) - { - for (i = 1; i <= count; i++) - Console.Write(" "); - count--; - for (i = 1; i <= 2 * k - 1; i++) - Console.Write("*"); - Console.WriteLine(); - } - count = 1; - for (k = 1; k <= number - 1; k++) - { - for (i = 1; i <= count; i++) - Console.Write(" "); - count++; - for (i = 1; i <= 2 * (number - k) - 1; i++) - Console.Write("*"); - Console.WriteLine(); - } - Console.ReadLine(); - } -} - -/* -Enter number of rows -3 - * - *** -***** - *** - * \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Read a Grade & Display the Equivalent Description.cs b/c-sharp/_Basic/C# Program to Read a Grade & Display the Equivalent Description.cs deleted file mode 100644 index da509b5..0000000 --- a/c-sharp/_Basic/C# Program to Read a Grade & Display the Equivalent Description.cs +++ /dev/null @@ -1,41 +0,0 @@ -/* - * C# Program to Read a Grade & Display the Equivalent Description - */ -using System; -using System.IO; -class program -{ - public static void Main() - { - char grade; - Console.WriteLine("Enter the Grade in UpperCase \n"); - grade = Convert.ToChar(Console.ReadLine()); - switch (grade) - { - case 'S': - Console.WriteLine(" SUPER"); - break; - case 'A': - Console.WriteLine(" VERY GOOD"); - break; - case 'B': - Console.WriteLine(" FAIR"); - break; - case 'Y': - Console.WriteLine(" ABSENT"); - break; - case 'F': - Console.WriteLine(" FAIL"); - break; - default: - Console.WriteLine("ERROR IN GRADE \n"); - break; - Console.ReadLine(); - } - } -} - -/* -Enter the Grade in UpperCase -A - VERY GOOD \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Swap 2 Numbers.cs b/c-sharp/_Basic/C# Program to Swap 2 Numbers.cs deleted file mode 100644 index 2f24378..0000000 --- a/c-sharp/_Basic/C# Program to Swap 2 Numbers.cs +++ /dev/null @@ -1,35 +0,0 @@ -/* - * C# Program to Swap two Numbers - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -namespace Program -{ -class Program -{ - static void Main(string[] args) - { - int num1, num2, temp; - Console.Write("\nEnter the First Number : "); - num1 = int.Parse(Console.ReadLine()); - Console.Write("\nEnter the Second Number : "); - num2 = int.Parse(Console.ReadLine()); - temp = num1; - num1 = num2; - num2 = temp; - Console.Write("\nAfter Swapping : "); - Console.Write("\nFirst Number : "+num1); - Console.Write("\nSecond Number : "+num2); - Console.Read(); - } -} -} - -/* -Enter the First Number : 23 -Enter the Second Number : 25 -After Swapping : -First Number : 25 -Second Number : 23 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Program to Swap the Contents of two Numbers using Bitwise XOR Operation.cs b/c-sharp/_Basic/C# Program to Swap the Contents of two Numbers using Bitwise XOR Operation.cs deleted file mode 100644 index 61483e1..0000000 --- a/c-sharp/_Basic/C# Program to Swap the Contents of two Numbers using Bitwise XOR Operation.cs +++ /dev/null @@ -1,27 +0,0 @@ -/* - * C# Program to Swap the Contents of two Numbers using Bitwise XOR Operation - */ -using System; -class program -{ - public static void Main() - { - int i, k; - Console.WriteLine("Enter two integers \n"); - i = int.Parse(Console.ReadLine()); - k = int.Parse(Console.ReadLine()); - Console.WriteLine("\n Before swapping i= {0} and k = {1}", i, k); - i = i ^ k; - k = i ^ k; - i = i ^ k; - Console.WriteLine("\n After swapping i= {0} and k = {1}", i, k); - Console.ReadLine(); - } -} - -/* -Enter two integers -23 -34 -Before swapping i= 23 and k = 34 -After swapping i= 34 and k = 23 \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program that takes a number as input and print its multiplication table.cs b/c-sharp/_Basic/C# Sharp program that takes a number as input and print its multiplication table.cs deleted file mode 100644 index 52241fe..0000000 --- a/c-sharp/_Basic/C# Sharp program that takes a number as input and print its multiplication table.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -public class Exercise8 -{ - public static void Main() - { - int x; - int result; - Console.WriteLine("Enter a number:"); - x = Convert.ToInt32(Console.ReadLine() ); - result = x * 1; - Console.WriteLine("The table is : {0} x {1} = {2}", x, 1, result); - result = x * 2; - Console.WriteLine(" : {0} x {1} = {2}", x, 2, result); - result = x * 3; - Console.WriteLine(" : {0} x {1} = {2}", x, 3, result); - result = x * 4; - Console.WriteLine(" : {0} x {1} = {2}", x, 4, result); - result = x * 5; - Console.WriteLine(" : {0} x {1} = {2}", x, 5, result); - result = x * 6; - Console.WriteLine(" : {0} x {1} = {2}", x, 6, result); - result = x * 7; - Console.WriteLine(" : {0} x {1} = {2}", x, 7, result); - result = x * 8; - Console.WriteLine(" : {0} x {1} = {2}", x, 8, result); - result = x * 9; - Console.WriteLine(" : {0} x {1} = {2}", x, 9, result); - result = x * 10; - Console.WriteLine(" : {0} x {1} = {2}", x, 10, result); - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program that takes an age (for example 20) as input and prints something as.cs b/c-sharp/_Basic/C# Sharp program that takes an age (for example 20) as input and prints something as.cs deleted file mode 100644 index cc0178b..0000000 --- a/c-sharp/_Basic/C# Sharp program that takes an age (for example 20) as input and prints something as.cs +++ /dev/null @@ -1,13 +0,0 @@ -C# Sharp program that takes an age (for example 20) as input and prints something as "You look older than 20. - - using System; -public class Exercise11 -{ - public static void Main() - { - int age; - Console.Write("Enter your age "); - age = Convert.ToInt32(Console.ReadLine()); - Console.Write("You look younger than {0} ",age); - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program that takes four numbers as input to calculate and print the average.cs b/c-sharp/_Basic/C# Sharp program that takes four numbers as input to calculate and print the average.cs deleted file mode 100644 index 38f0a9b..0000000 --- a/c-sharp/_Basic/C# Sharp program that takes four numbers as input to calculate and print the average.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -public class Exercise9 -{ - public static void Main() - { - int number1,number2,number3,number4; - Console.Write("Enter the First number: "); - number1 = Convert.ToInt32(Console.ReadLine()); - Console.Write("Enter the Second number: "); - number2 = Convert.ToInt32(Console.ReadLine()); - Console.Write("Enter the third number: "); - number3 = Convert.ToInt32(Console.ReadLine()); - Console.Write("Enter the four number: "); - number4 = Convert.ToInt32(Console.ReadLine()); - int result = (number1 + number2 + number3 + number4) / 4; - Console.WriteLine("The average of {0} , {1} , {2} , {3} is: {4} ", - number1, number2, number3, number4, result); - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program to convert from celsius degrees to Kelvin and Fahrenheit.cs b/c-sharp/_Basic/C# Sharp program to convert from celsius degrees to Kelvin and Fahrenheit.cs deleted file mode 100644 index 5faec92..0000000 --- a/c-sharp/_Basic/C# Sharp program to convert from celsius degrees to Kelvin and Fahrenheit.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -public class Exercise14 -{ - public static void Main( ) - { - Console.Write("Enter the amount of celsius: "); - int celsius = Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("Kelvin = {0}", celsius + 273); - Console.WriteLine("Fahrenheit = {0}", celsius * 18 / 10 + 32); - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program to print Hello and your name in a separate line.cs b/c-sharp/_Basic/C# Sharp program to print Hello and your name in a separate line.cs deleted file mode 100644 index d18d03b..0000000 --- a/c-sharp/_Basic/C# Sharp program to print Hello and your name in a separate line.cs +++ /dev/null @@ -1,12 +0,0 @@ -public class Exercise1 -{ - public static void Main( ) - { - System.Console.WriteLine("Hello"); - System.Console.WriteLine("Alexandra Abramov!"); - } -} -Output : - -Hello -Alexandra Abramov \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program to print on screen the output of adding, subtracting, multiplying and dividing of two numbers which will be entered by the user.cs b/c-sharp/_Basic/C# Sharp program to print on screen the output of adding, subtracting, multiplying and dividing of two numbers which will be entered by the user.cs deleted file mode 100644 index b1679f5..0000000 --- a/c-sharp/_Basic/C# Sharp program to print on screen the output of adding, subtracting, multiplying and dividing of two numbers which will be entered by the user.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -public class Exercise7 -{ - public static void Main() - { - Console.Write("Enter a number: "); - int num1= Convert.ToInt32(Console.ReadLine()); - Console.Write("Enter another number: "); - int num2= Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("{0} + {1} = {2}", num1, num2, num1+num2); - Console.WriteLine("{0} - {1} = {2}", num1, num2, num1-num2); - Console.WriteLine("{0} x {1} = {2}", num1, num2, num1*num2); - Console.WriteLine("{0} / {1} = {2}", num1, num2, num1/num2); - Console.WriteLine("{0} mod {1} = {2}", num1, num2, num1%num2); - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program to print the output of multiplication of three numbers which will be entered by the user.cs b/c-sharp/_Basic/C# Sharp program to print the output of multiplication of three numbers which will be entered by the user.cs deleted file mode 100644 index 3b54feb..0000000 --- a/c-sharp/_Basic/C# Sharp program to print the output of multiplication of three numbers which will be entered by the user.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -public class Exercise6 -{ - public static void Main() - { - int num1, num2, num3; - Console.Write("Input the first number to multiply: "); - num1 = Convert.ToInt32(Console.ReadLine()); - Console.Write("Input the second number to multiply: "); - num2 = Convert.ToInt32(Console.ReadLine()); - Console.Write("Input the third number to multiply: "); - num3 = Convert.ToInt32(Console.ReadLine()); - int result = num1 * num2 * num3; - Console.WriteLine("Output: {0} x {1} x {2} = {3}", - num1, num2, num3, result); - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program to print the result of dividing two numbers.cs b/c-sharp/_Basic/C# Sharp program to print the result of dividing two numbers.cs deleted file mode 100644 index 8a6df63..0000000 --- a/c-sharp/_Basic/C# Sharp program to print the result of dividing two numbers.cs +++ /dev/null @@ -1,7 +0,0 @@ -public class Exercise3 -{ - public static void Main() - { - System.Console.WriteLine(36/6); - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program to print the result of the specified operations.cs b/c-sharp/_Basic/C# Sharp program to print the result of the specified operations.cs deleted file mode 100644 index 618c43d..0000000 --- a/c-sharp/_Basic/C# Sharp program to print the result of the specified operations.cs +++ /dev/null @@ -1,32 +0,0 @@ -/* - -Write a C# Sharp program to print the result of the specified operations. - -Test data: -• -1 + 4 * 6 -• ( 35+ 5 ) % 7 -• 14 + -4 * 6 / 11 -• 2 + 15 / 6 * 1 - 7 % 2 -Expected Output: - -23 -5 -12 -3 - -*/ - -public class Exercise4 -{ - public static void Main() - { - System.Console.WriteLine(-1+4*6); - //-1 + 24 = 23 - System.Console.WriteLine((35+5)%7); - //40 % 7 = 5 (remainder of 40/7) - System.Console.WriteLine(14+-4*6/11); - //14 - (24/11)= 14 - 2 = 12 - System.Console.WriteLine(2+15/6*1-7%2); - //2 + (15/6) - remainder of (7/2) = 2 + 2 - 1 = 4 - 1 = 3 - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program to print the sum of two numbers.cs b/c-sharp/_Basic/C# Sharp program to print the sum of two numbers.cs deleted file mode 100644 index 997157f..0000000 --- a/c-sharp/_Basic/C# Sharp program to print the sum of two numbers.cs +++ /dev/null @@ -1,7 +0,0 @@ -public class Exercise2 -{ - public static void Main() - { - System.Console.WriteLine(15+17); - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program to swap two numbers.cs b/c-sharp/_Basic/C# Sharp program to swap two numbers.cs deleted file mode 100644 index 4478a67..0000000 --- a/c-sharp/_Basic/C# Sharp program to swap two numbers.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -public class Exercise5 -{ - public static void Main(string[] args) - { - int number1, number2, temp; - Console.Write("\nInput the First Number : "); - number1 = int.Parse(Console.ReadLine()); - Console.Write("\nInput the Second Number : "); - number2 = int.Parse(Console.ReadLine()); - temp = number1; - number1 = number2; - number2 = temp; - Console.Write("\nAfter Swapping : "); - Console.Write("\nFirst Number : "+number1); - Console.Write("\nSecond Number : "+number2); - Console.Read(); - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# Sharp program to that takes three numbers(x,y,z) as input and print the output of (x+y)úz and xúy + yúz.cs b/c-sharp/_Basic/C# Sharp program to that takes three numbers(x,y,z) as input and print the output of (x+y)úz and xúy + yúz.cs deleted file mode 100644 index 378744e..0000000 --- a/c-sharp/_Basic/C# Sharp program to that takes three numbers(x,y,z) as input and print the output of (x+y)úz and xúy + yúz.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -public class Exercise10 -{ - public static void Main() - { - int number1, number2, number3; - Console.Write("Enter first number - "); - number1 = Convert.ToInt32(Console.ReadLine()); - Console.Write("Enter second number - "); - number2 = Convert.ToInt32(Console.ReadLine()); - Console.Write("Enter third number - "); - number3 = Convert.ToInt32(Console.ReadLine()); - Console.Write("Result of specified numbers {0}, {1} and {2}, (x+y)·z is {3} and x·y + y·z is {4}\n\n", - number1, number2, number3, ((number1+number2)*number3), (number1*number2+number2*number3)); - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# program that takes a number as input and then displays a rectangle of 3 columns wide and 5 rows tall using that digit.cs b/c-sharp/_Basic/C# program that takes a number as input and then displays a rectangle of 3 columns wide and 5 rows tall using that digit.cs deleted file mode 100644 index e3b753c..0000000 --- a/c-sharp/_Basic/C# program that takes a number as input and then displays a rectangle of 3 columns wide and 5 rows tall using that digit.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -public class Exercise13 -{ - public static void Main() - { - int x; - Console.Write("Enter a number: "); - x=Convert.ToInt32(Console.ReadLine()); - Console.WriteLine("{0}{0}{0}",x); - Console.WriteLine("{0} {0}",x); - Console.WriteLine("{0} {0}",x); - Console.WriteLine("{0} {0}",x); - Console.WriteLine("{0}{0}{0}",x); - } -} \ No newline at end of file diff --git a/c-sharp/_Basic/C# program to that takes a number as input and display it four times in a row (separated by blank spaces), and then four times in the next row, with no separation.cs b/c-sharp/_Basic/C# program to that takes a number as input and display it four times in a row (separated by blank spaces), and then four times in the next row, with no separation.cs deleted file mode 100644 index 9726806..0000000 --- a/c-sharp/_Basic/C# program to that takes a number as input and display it four times in a row (separated by blank spaces), and then four times in the next row, with no separation.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -public class Exercise12 -{ - public static void Main() - { - int num; - Console.WriteLine("Enter a digit: "); - num = Convert.ToInt32( Console.ReadLine() ); - // Part A: "num num num num" using Write - Console.Write( num ); - Console.Write(" "); - Console.Write( num ); - Console.Write(" "); - Console.Write( num ); - Console.Write(" "); - Console.Write( num ); - Console.WriteLine(); - // Part B: "numnumnumnum" using Write - Console.Write( num ); - Console.Write( num ); - Console.Write( num ); - Console.WriteLine( num ); - Console.WriteLine(); - // Part C: "num num num num" using {0} - Console.WriteLine("{0} {0} {0} {0}", num); - // Part D: "numnumnumnum" using {0} - Console.WriteLine("{0}{0}{0}{0}", num); - } -} \ No newline at end of file diff --git a/c/_Basic/Accessing an array using pointers.c b/c/_Basic/Accessing an array using pointers.c deleted file mode 100644 index 295fd2c..0000000 --- a/c/_Basic/Accessing an array using pointers.c +++ /dev/null @@ -1,17 +0,0 @@ - #include - - main(){ - int a[5]; - int i; - for(i = 0;i<5;i++){ - a[i]=i; - } - - int *b; - - b=a; - for(i = 0;i<5;i++){ - printf("value in array %d and address is %16lu\n",*b,b); - b=b+2; - } - } \ No newline at end of file diff --git a/c/_Basic/C Program to Accept the Height of a Person & Categorize as Taller, Dwarf & Average.c b/c/_Basic/C Program to Accept the Height of a Person & Categorize as Taller, Dwarf & Average.c deleted file mode 100644 index 053b281..0000000 --- a/c/_Basic/C Program to Accept the Height of a Person & Categorize as Taller, Dwarf & Average.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * C program to accept the height of a person in centimeter and - * categorize the person based on height as taller, dwarf and - * average height person - */ - -#include -void main() -{ - float height; - printf("Enter the Height (in centimetres) \n"); - scanf("%f", &height); - if (height < 150.0) - printf("Dwarf \n"); - else if ((height >= 150.0) && (height <= 165.0)) - printf(" Average Height \n"); - else if ((height >= 165.0) && (height <= 195.0)) - printf("Taller \n"); - else - printf("Abnormal height \n"); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Accept two Integers and Check if they are Equal.c b/c/_Basic/C Program to Accept two Integers and Check if they are Equal.c deleted file mode 100644 index 5d06c95..0000000 --- a/c/_Basic/C Program to Accept two Integers and Check if they are Equal.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * C program to accept two integers and check if they are equal - */ -#include -void main() -{ - int m, n; - printf("Enter the values for M and N\n"); - scanf("%d %d", &m, &n); - if (m == n) - printf("M and N are equal\n"); - else - printf("M and N are not equal\n"); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Add two Complex Numbers.c b/c/_Basic/C Program to Add two Complex Numbers.c deleted file mode 100644 index ee35c48..0000000 --- a/c/_Basic/C Program to Add two Complex Numbers.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * C Program to Add two Complex Numbers - */ -#include - -struct complex -{ - int realpart, imaginary; -}; - -main() -{ - struct complex a, b, c; - printf("Enter value of a and b complex number a + ib.\n"); - printf("value of complex number a is = "); - scanf("%d", &a.realpart); - printf("value of complex number b is = "); - scanf("%d", &a.imaginary); - printf("Enter value of c and d complex number c + id.\n"); - printf("value of complex number c is = "); - scanf("%d", &b.realpart); - printf("value of complex number d is = "); - scanf("%d", &b.imaginary); - c.realpart = a.realpart + b.realpart; - c.imaginary = a.imaginary + b.imaginary; - if (c.imaginary >= 0) - printf("complex numbers sum is = %d + %di\n", c.realpart, c.imaginary); - else - printf("complex numbers sum = %d %di\n", c.realpart, c.imaginary); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Calculate the Sum of Odd & Even Numbers.c b/c/_Basic/C Program to Calculate the Sum of Odd & Even Numbers.c deleted file mode 100644 index 4db9d47..0000000 --- a/c/_Basic/C Program to Calculate the Sum of Odd & Even Numbers.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * C program to find the sum of odd and even numbers from 1 to N - */ -#include - -void main() -{ - int i, num, odd_sum = 0, even_sum = 0; - printf("Enter the value of num\n"); - scanf("%d", &num); - for (i = 1; i <= num; i++) - { - if (i % 2 == 0) - even_sum = even_sum + i; - else - odd_sum = odd_sum + i; - } - printf("Sum of all odd numbers = %d\n", odd_sum); - printf("Sum of all even numbers = %d\n", even_sum); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Check if a given Integer is Odd or Even.c b/c/_Basic/C Program to Check if a given Integer is Odd or Even.c deleted file mode 100644 index e48ef5b..0000000 --- a/c/_Basic/C Program to Check if a given Integer is Odd or Even.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * C program to check whether a given integer is odd or even - */ -#include - -void main() -{ - int ival, remainder; - printf("Enter an integer : "); - scanf("%d", &ival); - remainder = ival % 2; - if (remainder == 0) - printf("%d is an even integer\n", ival); - else - printf("%d is an odd integer\n", ival); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Check if a given Integer is Positive or Negative.c b/c/_Basic/C Program to Check if a given Integer is Positive or Negative.c deleted file mode 100644 index 7c8d8cd..0000000 --- a/c/_Basic/C Program to Check if a given Integer is Positive or Negative.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * C program to check whether a given integer is positive - * or negative - */ -#include - -void main() -{ - int number; - printf("Enter a number \n"); - scanf("%d", &number); - if (number >= 0) - printf("%d is a positive number \n", number); - else - printf("%d is a negative number \n", number); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Check whether a given Number is Armstrong.c b/c/_Basic/C Program to Check whether a given Number is Armstrong.c deleted file mode 100644 index 30d0649..0000000 --- a/c/_Basic/C Program to Check whether a given Number is Armstrong.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * C Program to Check whether a given Number is Armstrong - */ -#include -#include - -void main() -{ - int number, sum = 0, rem = 0, cube = 0, temp; - printf ("enter a number"); - scanf("%d", &number); - temp = number; - while (number != 0) - { - rem = number % 10; - cube = pow(rem, 3); - sum = sum + cube; - number = number / 10; - } - if (sum == temp) - printf ("The given no is armstrong no"); - else - printf ("The given no is not a armstrong no"); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Check whether a given Number is Perfect Number.c b/c/_Basic/C Program to Check whether a given Number is Perfect Number.c deleted file mode 100644 index 491af60..0000000 --- a/c/_Basic/C Program to Check whether a given Number is Perfect Number.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * C Program to Check whether a given Number is Perfect Number - */ -#include - -int main() -{ - int number, rem, sum = 0, i; - printf("Enter a Number\n"); - scanf("%d", &number); - for (i = 1; i <= (number - 1); i++) - { - rem = number % i; - if (rem == 0) - { - sum = sum + i; - } - } - if (sum == number) - printf("Entered Number is perfect number"); - else - printf("Entered Number is not a perfect number"); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Check whether the given Number is Palindrome or not using Bitwise Operator.c b/c/_Basic/C Program to Check whether the given Number is Palindrome or not using Bitwise Operator.c deleted file mode 100644 index 4b9fe81..0000000 --- a/c/_Basic/C Program to Check whether the given Number is Palindrome or not using Bitwise Operator.c +++ /dev/null @@ -1,70 +0,0 @@ -/* -* C Program to Check whether the given Number is Palindrome -* or not using Bitwise Operator -*/ -#include -#include -#define SIZE 8 -/* Function Prototype */ -int is_palindrome(unsigned char[]); - -void main() -{ - int num, num1 = 0, i = 0, j = SIZE - 1, res; - unsigned char c[SIZE]; - printf("Enter a number(max 255)"); - scanf("%d", &num); - num1 = num; - while (num != 0) - { - c[j] = num&1; - j--; - num = num>>1; /* Shifting right the given number by 1 bit */ - } - printf("The number %d in binary is:", num1); - for (i = 0; i < SIZE; i++) - { - printf("%d", c[i]); - } - res = is_palindrome(c); /* Calling Function */ - if (res == 0) - { - printf(" - NUMBER IS PALINDROME - "); - } - else - { - printf(" - NUMBER IS NOT PALINDROME - "); - } -} - -/* Code to check if the number is palindrome or not */ -int is_palindrome(unsigned char c[]) -{ - char temp[SIZE]; - int i, j, flag = 0; - for (i = 0, j = SIZE - 1; i < SIZE, j >= 0; i++, j--) - { - temp[j] = c[i]; - } - for (i = 0; i < SIZE; i++) - { - if (temp[i] != c[i]) - { - flag = 1; - } - } - return flag; -} - - - -Enter a number(max 255)153 -The number 153 in binary is:10011001 -NUMBER IS PALINDROME -Enter a number(max 255)24 -The number 24 in binary is:00011000 -NUMBER IS PALINDROME \ No newline at end of file diff --git a/c/_Basic/C Program to Compute First N Fibonacci Numbers using Command Line Arguments.c b/c/_Basic/C Program to Compute First N Fibonacci Numbers using Command Line Arguments.c deleted file mode 100644 index 0c6340b..0000000 --- a/c/_Basic/C Program to Compute First N Fibonacci Numbers using Command Line Arguments.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * C Program to Compute First N Fibonacci Numbers using Command Line Arguments - */ -#include - -/* Global Variable Declaration */ -int first = 0; -int second = 1; -int third; -/* Function Prototype */ -void rec_fibonacci(int); - -void main(int argc, char *argv[])/* Command line Arguments*/ -{ - int number = atoi(argv[1]); - printf("%d\t%d", first, second); /* To print first and second number of fibonacci series */ - rec_fibonacci(number); - printf("\n"); -} - -/* Code to print fibonacci series using recursive function */ -void rec_fibonacci(int num) -{ - if (num == 2) /* To exit the function as the first two numbers are already printed */ - { - return; - } - third = first + second; - printf("\t%d", third); - first = second; - second = third; - num--; - rec_fibonacci(num); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Compute the Sum of Digits in a given Integer.c b/c/_Basic/C Program to Compute the Sum of Digits in a given Integer.c deleted file mode 100644 index 4c981a3..0000000 --- a/c/_Basic/C Program to Compute the Sum of Digits in a given Integer.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * C program to accept an integer & find the sum of its digits - */ -#include - -void main() -{ - long num, temp, digit, sum = 0; - printf("Enter the number \n"); - scanf("%ld", &num); - temp = num; - while (num > 0) - { - digit = num % 10; - sum = sum + digit; - num /= 10; - } - printf("Given number = %ld\n", temp); - printf("Sum of the digits %ld = %ld\n", temp, sum); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Convert Binary Code of a Number into its Equivalent Gray’s Code using Recursion.c b/c/_Basic/C Program to Convert Binary Code of a Number into its Equivalent Gray’s Code using Recursion.c deleted file mode 100644 index 152e79a..0000000 --- a/c/_Basic/C Program to Convert Binary Code of a Number into its Equivalent Gray’s Code using Recursion.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * C Program to Convert Binary Code of a Number into its Equivalent - * Gray's Code using Recursion - */ -#include - -int bintogray(int); - -int main () -{ - int bin, gray; - printf("Enter a binary number: "); - scanf("%d", &bin); - gray = bintogray(bin); - printf("The gray code of %d is %d\n", bin, gray); - return 0; -} - -int bintogray(int bin) -{ - int a, b, result = 0, i = 0; - if (!bin) - { - return 0; - } - else - { - a = bin % 10; - bin = bin / 10; - b = bin % 10; - if ((a && !b) || (!a && b)) - { - return (1 + 10 * bintogray(bin)); - } - else - { - return (10 * bintogray(bin)); - } - } -} \ No newline at end of file diff --git a/c/_Basic/C Program to Convert Binary Code of a Number into its Equivalent Gray’s Code without using Recursion.c b/c/_Basic/C Program to Convert Binary Code of a Number into its Equivalent Gray’s Code without using Recursion.c deleted file mode 100644 index 020d700..0000000 --- a/c/_Basic/C Program to Convert Binary Code of a Number into its Equivalent Gray’s Code without using Recursion.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * C Program to Convert Binary Code of a Number into its Equivalent - * Gray's Code without using Recursion - */ -#include -#include - -int bintogray(int); - -int main () -{ - int bin, gray; - printf("Enter a binary number: "); - scanf("%d", &bin); - gray = bintogray(bin); - printf("The gray code of %d is %d\n", bin, gray); - return 0; -} - -int bintogray(int bin) -{ - int a, b, result = 0, i = 0; - while (bin != 0) - { - a = bin % 10; - bin = bin / 10; - b = bin % 10; - if ((a && !b) || (!a && b)) - { - result = result + pow(10, i); - } - i++; - } - return result; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Convert Binary to Hexadecimal.c b/c/_Basic/C Program to Convert Binary to Hexadecimal.c deleted file mode 100644 index 1b19012..0000000 --- a/c/_Basic/C Program to Convert Binary to Hexadecimal.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * C Program to Convert Binary to Hexadecimal - */ -#include - -int main() -{ - long int binaryval, hexadecimalval = 0, i = 1, remainder; - printf("Enter the binary number: "); - scanf("%ld", &binaryval); - while (binaryval != 0) - { - remainder = binaryval % 10; - hexadecimalval = hexadecimalval + remainder * i; - i = i * 2; - binaryval = binaryval / 10; - } - printf("Equivalent hexadecimal value: %lX", hexadecimalval); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Convert Binary to Octal.c b/c/_Basic/C Program to Convert Binary to Octal.c deleted file mode 100644 index 6c38d56..0000000 --- a/c/_Basic/C Program to Convert Binary to Octal.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * C Program to Convert Binary to Octal - */ -#include - -int main() -{ - long int binarynum, octalnum = 0, j = 1, remainder; - printf("Enter the value for binary number: "); - scanf("%ld", &binarynum); - while (binarynum != 0) - { - remainder = binarynum % 10; - octalnum = octalnum + remainder * j; - j = j * 2; - binarynum = binarynum / 10; - } - printf("Equivalent octal value: %lo", octalnum); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Convert Hexadecimal to Binary.c b/c/_Basic/C Program to Convert Hexadecimal to Binary.c deleted file mode 100644 index 890a63d..0000000 --- a/c/_Basic/C Program to Convert Hexadecimal to Binary.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * C Program to Convert Hexadecimal to Binary - */ -#include -#define MAX 1000 - -int main() -{ - char binarynum[MAX], hexa[MAX]; - long int i = 0; - printf("Enter the value for hexadecimal "); - scanf("%s", hexa); - printf("\n Equivalent binary value: "); - while (hexa[i]) - { - switch (hexa[i]) - { - case '0': - printf("0000"); - break; - case '1': - printf("0001"); - break; - case '2': - printf("0010"); - break; - case '3': - printf("0011"); - break; - case '4': - printf("0100"); - break; - case '5': - printf("0101"); - break; - case '6': - printf("0110"); - break; - case '7': - printf("0111"); - break; - case '8': - printf("1000"); - break; - case '9': - printf("1001"); - break; - case 'A': - printf("1010"); - break; - case 'B': - printf("1011"); - break; - case 'C': - printf("1100"); - break; - case 'D': - printf("1101"); - break; - case 'E': - printf("1110"); - break; - case 'F': - printf("1111"); - break; - case 'a': - printf("1010"); - break; - case 'b': - printf("1011"); - break; - case 'c': - printf("1100"); - break; - case 'd': - printf("1101"); - break; - case 'e': - printf("1110"); - break; - case 'f': - printf("1111"); - break; - default: - printf("\n Invalid hexa digit %c ", hexa[i]); - return 0; - } - i++; - } - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Convert Numbers to Roman Numerals.c b/c/_Basic/C Program to Convert Numbers to Roman Numerals.c deleted file mode 100644 index b7f7f4f..0000000 --- a/c/_Basic/C Program to Convert Numbers to Roman Numerals.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * C Program to Convert Numbers to Roman Numerals - */ -#include - -void predigit(char num1, char num2); -void postdigit(char c, int n); - -char romanval[1000]; -int i = 0; -int main() -{ - int j; - long number; - printf("Enter the number: "); - scanf("%d", &number); - if (number <= 0) - { - printf("Invalid number"); - return 0; - } - while (number != 0) - { - if (number >= 1000) - { - postdigit('M', number / 1000); - number = number - (number / 1000) * 1000; - } - else if (number >= 500) - { - if (number < (500 + 4 * 100)) - { - postdigit('D', number / 500); - number = number - (number / 500) * 500; - } - else - { - predigit('C','M'); - number = number - (1000-100); - } - } - else if (number >= 100) - { - if (number < (100 + 3 * 100)) - { - postdigit('C', number / 100); - number = number - (number / 100) * 100; - } - else - { - predigit('L', 'D'); - number = number - (500 - 100); - } - } - else if (number >= 50 ) - { - if (number < (50 + 4 * 10)) - { - postdigit('L', number / 50); - number = number - (number / 50) * 50; - } - else - { - predigit('X','C'); - number = number - (100-10); - } - } - else if (number >= 10) - { - if (number < (10 + 3 * 10)) - { - postdigit('X', number / 10); - number = number - (number / 10) * 10; - } - else - { - predigit('X','L'); - number = number - (50 - 10); - } - } - else if (number >= 5) - { - if (number < (5 + 4 * 1)) - { - postdigit('V', number / 5); - number = number - (number / 5) * 5; - } - else - { - predigit('I', 'X'); - number = number - (10 - 1); - } - } - else if (number >= 1) - { - if (number < 4) - { - postdigit('I', number / 1); - number = number - (number / 1) * 1; - } - else - { - predigit('I', 'V'); - number = number - (5 - 1); - } - } - } - printf("Roman number is: "); - for(j = 0; j < i; j++) - printf("%c", romanval[j]); - return 0; -} - -void predigit(char num1, char num2) -{ - romanval[i++] = num1; - romanval[i++] = num2; -} - -void postdigit(char c, int n) -{ - int j; - for (j = 0; j < n; j++) - romanval[i++] = c; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Convert Octal to Binary.c b/c/_Basic/C Program to Convert Octal to Binary.c deleted file mode 100644 index 2894f21..0000000 --- a/c/_Basic/C Program to Convert Octal to Binary.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * C Program to Convert Octal to Binary - */ -#include -#define MAX 1000 - -int main() -{ - char octalnum[MAX]; - long i = 0; - printf("Enter any octal number: "); - scanf("%s", octalnum); - printf("Equivalent binary value: "); - while (octalnum[i]) - { - switch (octalnum[i]) - { - case '0': - printf("000"); - break; - case '1': - printf("001"); - break; - case '2': - printf("010"); - break; - case '3': - printf("011"); - break; - case '4': - printf("100"); - break; - case '5': - printf("101"); - break; - case '6': - printf("110"); - break; - case '7': - printf("111"); - break; - default: - printf("\n Invalid octal digit %c ", octalnum[i]); - return 0; - } - i++; - } - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Convert Octal to Decimal.c b/c/_Basic/C Program to Convert Octal to Decimal.c deleted file mode 100644 index a9da073..0000000 --- a/c/_Basic/C Program to Convert Octal to Decimal.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * C Program to Convert Octal to Decimal - */ -#include -#include - -int main() -{ - long int octal, decimal = 0; - int i = 0; - printf("Enter any octal number: "); - scanf("%ld", &octal); - while (octal != 0) - { - decimal = decimal +(octal % 10)* pow(8, i++); - octal = octal / 10; - } - printf("Equivalent decimal value: %ld",decimal); - return 0; -} diff --git a/c/_Basic/C Program to Convert Roman Number to Decimal Number.c b/c/_Basic/C Program to Convert Roman Number to Decimal Number.c deleted file mode 100644 index 3c942e8..0000000 --- a/c/_Basic/C Program to Convert Roman Number to Decimal Number.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * C Program to Convert Roman Number to Decimal Number - */ -#include -#include - -int digit(char); - -int main() -{ - char romanval[1000]; - int i = 0; - long int number = 0; - printf("Enter roman num (Valid digits are I, V, X, L, C, D, M):\n"); - scanf("%s", romanval); - while (romanval[i]) - { - if (digit(romanval[i]) 2) - { - if (digit(romanval[i]) = digit(romanval[i+1])) - number = number + digit(romanval[i]); - else - { - number = number + (digit(romanval[i + 1]) - - digit(romanval[i])); - i++; - } - i++; - } - printf("Its decimal value is : %ld", number); - return 0; - } - int digit(char c) - { - int value = 0; - switch (c) - { - case 'I': - value = 1; - break; - case 'V': - value = 5; - break; - case 'X': - value = 10; - break; - case 'L': - value = 50; - break; - case 'C': - value = 100; - break; - case 'D': - value = 500; - break; - case 'M': - value = 1000; - break; - case '0': - value = 0; - break; - default: - value = -1; - } - return value; - } \ No newline at end of file diff --git a/c/_Basic/C Program to Convert a Decimal Number to Binary & Count the Number of 1s.c b/c/_Basic/C Program to Convert a Decimal Number to Binary & Count the Number of 1s.c deleted file mode 100644 index c595704..0000000 --- a/c/_Basic/C Program to Convert a Decimal Number to Binary & Count the Number of 1s.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * C program to accept a decimal number and convert it to binary - * and count the number of 1's in the binary number - */ -#include - -void main() -{ - long num, decimal_num, remainder, base = 1, binary = 0, no_of_1s = 0; - printf("Enter a decimal integer \n"); - scanf("%ld", &num); - decimal_num = num; - while (num > 0) - { - remainder = num % 2; - /* To count no.of 1s */ - if (remainder == 1) - { - no_of_1s++; - } - binary = binary + remainder * base; - num = num / 2; - base = base * 10; - } - printf("Input number is = %d\n", decimal_num); - printf("Its binary equivalent is = %ld\n", binary); - printf("No.of 1's in the binary number is = %d\n", no_of_1s); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Convert a Given Number of Days in terms of Years, Weeks & Days.c b/c/_Basic/C Program to Convert a Given Number of Days in terms of Years, Weeks & Days.c deleted file mode 100644 index 7eac27f..0000000 --- a/c/_Basic/C Program to Convert a Given Number of Days in terms of Years, Weeks & Days.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * C program to convert given number of days to a measure of time given - * in years, weeks and days. For example 375 days is equal to 1 year - * 1 week and 3 days (ignore leap year) - */ -#include -#define DAYSINWEEK 7 - -void main() -{ - int ndays, year, week, days; - printf("Enter the number of daysn"); - scanf("%d", &ndays); - year = ndays / 365; - week =(ndays % 365) / DAYSINWEEK; - days =(ndays % 365) % DAYSINWEEK; - printf ("%d is equivalent to %d years, %d weeks and %d daysn", - ndays, year, week, days); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Convert a Number Decimal System to Binary System using Recursion.c b/c/_Basic/C Program to Convert a Number Decimal System to Binary System using Recursion.c deleted file mode 100644 index 3301a55..0000000 --- a/c/_Basic/C Program to Convert a Number Decimal System to Binary System using Recursion.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * C Program to Convert a Number Decimal System to Binary System using Recursion - */ -#include - -int convert(int); - -int main() -{ - int dec, bin; - printf("Enter a decimal number: "); - scanf("%d", &dec); - bin = convert(dec); - printf("The binary equivalent of %d is %d.\n", dec, bin); - return 0; -} - -int convert(int dec) -{ - if (dec == 0) - { - return 0; - } - else - { - return (dec % 2 + 10 * convert(dec / 2)); - } -} \ No newline at end of file diff --git a/c/_Basic/C Program to Convert the given Binary Number into Decimal.c b/c/_Basic/C Program to Convert the given Binary Number into Decimal.c deleted file mode 100644 index 866c02d..0000000 --- a/c/_Basic/C Program to Convert the given Binary Number into Decimal.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * C program to convert the given binary number into decimal - */ -#include - -void main() -{ - int num, binary_val, decimal_val = 0, base = 1, rem; - printf("Enter a binary number(1s and 0s) \n"); - scanf("%d", &num); /* maximum five digits */ - binary_val = num; - while (num > 0) - { - rem = num % 10; - decimal_val = decimal_val + rem * base; - num = num / 10 ; - base = base * 2; - } - printf("The Binary number is = %d \n", binary_val); - printf("Its decimal equivalent is = %d \n", decimal_val); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Count Number of Words in a given Text Or Sentence.c b/c/_Basic/C Program to Count Number of Words in a given Text Or Sentence.c deleted file mode 100644 index 9bd05de..0000000 --- a/c/_Basic/C Program to Count Number of Words in a given Text Or Sentence.c +++ /dev/null @@ -1,27 +0,0 @@ -/* -* C Program to Count Number of Words in a given Text Or Sentence -*/ -#include -#include - -void main() -{ - char s[200]; - int count = 0, i; - printf("enter the string - "); - scanf("%[^ - ]s", s); - for (i = 0; s[i] != ''; i++) - { - if (s[i] == ' ') - count++; - } - printf("number of words in given string are: %d - ", count + 1); -} - - -enter the string -welcome to illuminate's c-programming app! -number of words in given string are: 5 \ No newline at end of file diff --git a/c/_Basic/C Program to Count the Number of Occurrence of each Character Ignoring the Case of Alphabets & Display them.c b/c/_Basic/C Program to Count the Number of Occurrence of each Character Ignoring the Case of Alphabets & Display them.c deleted file mode 100644 index 9c729d9..0000000 --- a/c/_Basic/C Program to Count the Number of Occurrence of each Character Ignoring the Case of Alphabets & Display them.c +++ /dev/null @@ -1,86 +0,0 @@ -/* -* C Program to Count the Number of Occurrence of -* each Character Ignoring the Case of Alphabets -* & Display them -*/ -#include -#include -#include - -struct detail -{ - char c; - int freq; -}; -int main() -{ - struct detail s[26]; - char string[100], c; - int i = 0, index; - for (i = 0; i < 26; i++) - { - s[i].c = i + 'a'; - s[i].freq = 0; - } - printf("Enter string: "); - i = 0; - do - { - fflush(stdin); - c = getchar(); - string[i++] = c; - if (c == ' - ') - { - break; - } - c = tolower(c); - index = c - 'a'; - s[index].freq++; - } -while (1); - string[i - 1] = ''; - printf("The string entered is: %s - ", string); - printf("************************* - Character Frequency - ************************* - "); - for (i = 0; i < 26; i++) - { - if (s[i].freq) - { - printf(" %c %d - ", s[i].c, s[i].freq); - } - } - return - 0; -} - - -Enter string: -A quIck brOwn fox JumpEd over a lazy dOg -The string entered is: -A quIck brOwn fox JumpEd over a lazy dOg -************************* -Character Frequency -********************* -a 3 -b 1 -c 1 -d 2 -e 2 -f 1 -g 1 -i 1 -j 1 -k 1 -l 1 -m 1 -n 1 -o 4 -p 1 -q 1 -r 2 -u 2 v 1 w 1 x 1 y 1 z 1 \ No newline at end of file diff --git a/c/_Basic/C Program to Count the Number of Unique Words.c b/c/_Basic/C Program to Count the Number of Unique Words.c deleted file mode 100644 index aaf0ba5..0000000 --- a/c/_Basic/C Program to Count the Number of Unique Words.c +++ /dev/null @@ -1,65 +0,0 @@ -/* -* C Program to Count the Number of Unique Words -*/ -#include -#include -#include -int main() -{ - int i = 0, e, j, d, k, space = 0; - char a[50], b[15][20], c[15][20]; - printf("Read a string: - "); - fflush(stdin); - scanf("%[^ - ]s", a); - for (i = 0; a[i] != ''; i++) //loop to count no of words - { - if (a[i] = = ' ') - space++; - } - i = 0; - for (j = 0; j<(space + 1); i++, j++) //loop to store each word into an 2D array - { - k = 0; - while (a[i] != '') - { - if (a[i] == ' ') - { - break; - } - else - { - b[j][k++] = a[i]; - i++; - } - } - b[j][k] = ''; - } - i = 0; - strcpy(c[i], b[i]); - for (e = 1; e <= j; e++) //loop to check whether the string is already present in the 2D array or not - { - for (d = 0; d <= i; d++) - { - if (strcmp(c[i], b[e]) == 0) - break; - else - { - i++; - strcpy(c[i], b[e]); - break; - } - } - } - printf(" - Number of unique words in %s are:%d", a, i); - return 0; -} - - -Read a string: -Welcome to Illuminate's C-programming class, Welcome again to C class! -The length of input string is:70 - -Number of unique words in Welcome to ILLuminate's C-programming class, Welcome again to C class! are:12 \ No newline at end of file diff --git a/c/_Basic/C Program to Count the Occurrences of each C Keyword using Array Structure.c b/c/_Basic/C Program to Count the Occurrences of each C Keyword using Array Structure.c deleted file mode 100644 index dc4f61b..0000000 --- a/c/_Basic/C Program to Count the Occurrences of each C Keyword using Array Structure.c +++ /dev/null @@ -1,104 +0,0 @@ -/* -* C Program to Count the Occurrences of each C Keyword -* using Array Structure -*/ -#include -#include -#include -#define KEYMAX 32 - -struct keyword -{ - char word[10]; - int occur; -}; - -int binarysearch(char [], struct keyword[]); - -int main() -{ - int i = 0, j = 0, pos; - char string[100], unit[20], c; - struct keyword key[32] = {"auto", 0, "break", 0, "case", 0, - "char", 0, "const", 0, "continue", 0, - "default", 0, "do", 0, "double", 0, - "else", 0, "enum", 0, "extern", 0, - "float", 0, "for", 0, "goto", 0, - "if", 0, "int", 0, "long", 0, - "register", 0, "return", 0, "short", 0, - "signed", 0, "sizeof", 0, "static", 0, - "struct", 0, "switch", 0, "typedef", 0, - "union", 0, "unsigned", 0, "void", 0, - "volatile", 0, "while", 0, - }; - printf("Enter string: "); - do - { - fflush(stdin); - c = getchar(); - string[i++] = c; - } - while (c != ' - '); - string[i - 1] = ''; - printf("The string entered is: %s - ", string); - for (i = 0; i < strlen(string); i++) - { - while (i < strlen(string) && string[i] != ' ' && isalpha(string[i])) - { - unit[j++] = tolower(string[i++]); - } - if (j != 0) - { - unit[j] = ''; - pos = binarysearch(unit, key); - j = 0; - if (pos != -1) - { - key[pos].occur++; - } - } - } - printf("*********************** - Keyword Count - *********************** - "); - for (i = 0; i < KEYMAX; i++) - { - if (key[i].occur) - { - printf(" %s %d - ", key[i].word, key[i].occur); } - } - return 0; - } - int binarysearch(char *word, struct keyword key[]) - { - int low, high, mid; - low = 0; - high = KEYMAX - 1; - while (low <= high) - { - mid = (low + high) / 2; - if (strcmp(word, key[mid].word) < 0) - { - high = mid - 1; - } - else if (strcmp(word, key[mid].word) > 0) - { - low = mid + 1; - } - else - { - return mid; - } - } - return -1; - } - Enter string: break, float and double are c keywords. float and double are primitive data types. The string entered is: break, float and double are c keywords. float and double are primitive data types. *********************** - Keyword Count - *********************** - break 1 - double 2 - float 2 \ No newline at end of file diff --git a/c/_Basic/C Program to Display Function without using the Main Function.c b/c/_Basic/C Program to Display Function without using the Main Function.c deleted file mode 100644 index 341a41b..0000000 --- a/c/_Basic/C Program to Display Function without using the Main Function.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * C Program to display function without using the Main Function - */ -#include -#define decode(s,t,u,m,p,e,d) m##s##u##t -#define begin decode(a,n,i,m,a,t,e) - -int begin() -{ - printf(" helloworld "); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Display its own Source Code as its Output.c b/c/_Basic/C Program to Display its own Source Code as its Output.c deleted file mode 100644 index 3761ab8..0000000 --- a/c/_Basic/C Program to Display its own Source Code as its Output.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * C Program to Display its own Source Code as its Output - */ -#include - -int main() -{ - FILE *fp; - char ch; - fp = fopen(__FILE__,"r"); - do - { - ch = getc(fp); - putchar(ch); - } - while (ch != EOF); - fclose(fp); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Display the ATM Transaction.c b/c/_Basic/C Program to Display the ATM Transaction.c deleted file mode 100644 index 5bf2c56..0000000 --- a/c/_Basic/C Program to Display the ATM Transaction.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * C Program to Display the ATM Transaction - */ -#include - -unsigned long amount=1000, deposit, withdraw; -int choice, pin, k; -char transaction ='y'; - -void main() -{ - while (pin != 1520) - { - printf("ENTER YOUR SECRET PIN NUMBER:"); - scanf("%d", &pin); - if (pin != 1520) - printf("PLEASE ENTER VALID PASSWORD\n"); - } - do - { - printf("********Welcome to ATM Service**************\n"); - printf("1. Check Balance\n"); - printf("2. Withdraw Cash\n"); - printf("3. Deposit Cash\n"); - printf("4. Quit\n"); - printf("******************?**************************?*\n\n"); - printf("Enter your choice: "); - scanf("%d", &choice); - switch (choice) - { - case 1: - printf("\n YOUR BALANCE IN Rs : %lu ", amount); - break; - case 2: - printf("\n ENTER THE AMOUNT TO WITHDRAW: "); - scanf("%lu", &withdraw); - if (withdraw % 100 != 0) - { - printf("\n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100"); - } - else if (withdraw >(amount - 500)) - { - printf("\n INSUFFICENT BALANCE"); - } - else - { - amount = amount - withdraw; - printf("\n\n PLEASE COLLECT CASH"); - printf("\n YOUR CURRENT BALANCE IS%lu", amount); - } - break; - case 3: - printf("\n ENTER THE AMOUNT TO DEPOSIT"); - scanf("%lu", &deposit); - amount = amount + deposit; - printf("YOUR BALANCE IS %lu", amount); - break; - case 4: - printf("\n THANK U USING ATM"); - break; - default: - printf("\n INVALID CHOICE"); - } - printf("\n\n\n DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): \n"); - fflush(stdin); - scanf("%c", &transaction); - if (transaction == 'n'|| transaction == 'N') - k = 1; - } - while (!k); - printf("\n\n THANKS FOR USING OUT ATM SERVICE"); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Display the IP Address of the System.c b/c/_Basic/C Program to Display the IP Address of the System.c deleted file mode 100644 index cd17094..0000000 --- a/c/_Basic/C Program to Display the IP Address of the System.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * C Program to Get IP Address - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int main() -{ - int n; - struct ifreq ifr; - char array[] = "eth0"; - n = socket(AF_INET, SOCK_DGRAM, 0); - //Type of address to retrieve - IPv4 IP address - ifr.ifr_addr.sa_family = AF_INET; - //Copy the interface name in the ifreq structure - strncpy(ifr.ifr_name, array, IFNAMSIZ - 1); - ioctl(n, SIOCGIFADDR, &ifr); - close(n); - //display result - printf("IP Address is %s - %s\n", array, inet_ntoa(( (struct sockaddr_in *)&ifr.ifr_addr )->sin_addr) ); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Display the Inventory of Items in a Store.c b/c/_Basic/C Program to Display the Inventory of Items in a Store.c deleted file mode 100644 index 2743de2..0000000 --- a/c/_Basic/C Program to Display the Inventory of Items in a Store.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * C program to display the inventory of items in a store / shop - * The inventory maintains details such as name, price, quantity - * and manufacturing date of each item. - */ -#include - -void main() -{ - struct date - { - int day; - int month; - int year; - }; - struct details - { - char name[20]; - int price; - int code; - int qty; - struct date mfg; - }; - struct details item[50]; - int n, i; - printf("Enter number of items:"); - scanf("%d", &n); - fflush(stdin); - for (i = 0; i < n; i++) - { - fflush(stdin); - printf("Item name: \n"); - scanf("%s", item[i].name); - fflush(stdin); - printf("Item code: \n"); - scanf("%d", &item[i].code); - fflush(stdin); - printf("Quantity: \n"); - scanf("%d", &item[i].qty); - fflush(stdin); - printf("price: \n"); - scanf("%d", &item[i].price); - fflush(stdin); - printf("Manufacturing date(dd-mm-yyyy): \n"); - scanf("%d-%d-%d", &item[i].mfg.day, - &item[i].mfg.month, &item[i].mfg.year); - } - printf(" ***** INVENTORY ***** \n"); - printf("--------------------------------------------------------- - ---------\n"); - printf("S.N.| NAME | CODE | QUANTITY | PRICE - | MFG.DATE \n"); - printf("--------------------------------------------------------- - ---------\n"); - for (i = 0; i < n; i++) - printf("%d %-15s %-d %-5d %-5d - %d/%d/%d \n", i + 1, item[i].name, item[i].code, item[i].qty, - item[i].price, item[i].mfg.day, item[i].mfg.month, - item[i].mfg.year); - printf("--------------------------------------------------------- - ---------\n"); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Extract Last two Digits of a given Year.c b/c/_Basic/C Program to Extract Last two Digits of a given Year.c deleted file mode 100644 index 264433f..0000000 --- a/c/_Basic/C Program to Extract Last two Digits of a given Year.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * C Program to Extract Last two Digits of a given Year - */ -#include - -int main() -{ - int year, yr; - printf("Enter the year "); - scanf("%d", &year); - yr = year % 100; - printf("Last two digits of year is: %02d", yr); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Find Multiplication of two Binary Numbers.c b/c/_Basic/C Program to Find Multiplication of two Binary Numbers.c deleted file mode 100644 index ee3c77e..0000000 --- a/c/_Basic/C Program to Find Multiplication of two Binary Numbers.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * C Program to Find Multiplication of two Binary Numbers - */ -#include - -int binaryproduct(int, int); - -int main() -{ - long binary1, binary2, multiply = 0; - int digit, factor = 1; - printf("Enter the first binary number: "); - scanf("%ld", &binary1); - printf("Enter the second binary number: "); - scanf("%ld", &binary2); - while (binary2 != 0) - { - digit = binary2 % 10; - if (digit == 1) - { - binary1 = binary1 * factor; - multiply = binaryproduct(binary1, multiply); - } - else - binary1 = binary1 * factor; - binary2 = binary2 / 10; - factor = 10; - } - printf("Product of two binary numbers: %ld", multiply); - return 0; -} - -int binaryproduct(int binary1, int binary2) -{ - int i = 0, remainder = 0, sum[20]; - int binaryprod = 0; - while (binary1 != 0 || binary2 != 0) - { - sum[i++] =(binary1 % 10 + binary2 % 10 + remainder) % 2; - remainder =(binary1 % 10 + binary2 % 10 + remainder) / 2; - binary1 = binary1 / 10; - binary2 = binary2 / 10; - } - if (remainder != 0) - sum[i++] = remainder; - --i; - while (i >= 0) - binaryprod = binaryprod * 10 + sum[i--]; - return binaryprod; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Find Product of 2 Numbers without using Recursion.c b/c/_Basic/C Program to Find Product of 2 Numbers without using Recursion.c deleted file mode 100644 index dbfc6c0..0000000 --- a/c/_Basic/C Program to Find Product of 2 Numbers without using Recursion.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * C Program to find Product of 2 Numbers without using Recursion - */ - -#include - -int product(int, int); - -int main() -{ - int a, b, result; - printf("Enter two numbers to find their product: "); - scanf("%d%d", &a, &b); - result = product(a, b); - printf("Product of %d and %d is %d\n", a, b, result); - return 0; -} - -int product(int a, int b) -{ - int temp = 0; - while (b != 0) - { - temp += a; - b--; - } - return temp; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Find Sum of Digits of a Number using Recursion.c b/c/_Basic/C Program to Find Sum of Digits of a Number using Recursion.c deleted file mode 100644 index 69b3469..0000000 --- a/c/_Basic/C Program to Find Sum of Digits of a Number using Recursion.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * C Program to find Sum of Digits of a Number using Recursion - */ -#include - -int sum (int a); - -int main() -{ - int num, result; - printf("Enter the number: "); - scanf("%d", &num); - result = sum(num); - printf("Sum of digits in %d is %d\n", num, result); - return 0; -} - -int sum (int num) -{ - if (num != 0) - { - return (num % 10 + sum (num / 10)); - } - else - { - return 0; - } -} \ No newline at end of file diff --git a/c/_Basic/C Program to Find if a given Year is a Leap Year.c b/c/_Basic/C Program to Find if a given Year is a Leap Year.c deleted file mode 100644 index ca70afa..0000000 --- a/c/_Basic/C Program to Find if a given Year is a Leap Year.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * C program to find whether a given year is leap year or not - */ -void main() -{ - int year; - printf("Enter a year \n"); - scanf("%d", &year); - if ((year % 400) == 0) - printf("%d is a leap year \n", year); - else if ((year % 100) == 0) - printf("%d is a not leap year \n", year); - else if ((year % 4) == 0) - printf("%d is a leap year \n", year); - else - printf("%d is not a leap year \n", year); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Find the Biggest of 3 Numbers.c b/c/_Basic/C Program to Find the Biggest of 3 Numbers.c deleted file mode 100644 index ae98224..0000000 --- a/c/_Basic/C Program to Find the Biggest of 3 Numbers.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * C program to find the biggest of three numbers - */ -#include - -void main() -{ - int num1, num2, num3; - printf("Enter the values of num1, num2 and num3\n"); - scanf("%d %d %d", &num1, &num2, &num3); - printf("num1 = %d\tnum2 = %d\tnum3 = %d\n", num1, num2, num3); - if (num1 > num2) - { - if (num1 > num3) - { - printf("num1 is the greatest among three \n"); - } - else - { - printf("num3 is the greatest among three \n"); - } - } - else if (num2 > num3) - printf("num2 is the greatest among three \n"); - else - printf("num3 is the greatest among three \n"); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Find the First Occurence of the any Character of String2 in string1 & also its Position.c b/c/_Basic/C Program to Find the First Occurence of the any Character of String2 in string1 & also its Position.c deleted file mode 100644 index 1f35305..0000000 --- a/c/_Basic/C Program to Find the First Occurence of the any Character of String2 in string1 & also its Position.c +++ /dev/null @@ -1,51 +0,0 @@ -/* -/* -* C Program to Find the First Occurence of the any Character of -* String2 in string1 & also its Position -*/ -#include - -void main() -{ - char s1[50], s2[10]; - int i, flag = 0; - char *ptr1, *ptr2; - printf(" - enter the string1:"); - scanf(" %[^ - ]s", s1); - printf(" - enter the string2:"); - scanf(" %[^ - ]s", s2); - /*COMPARING THE STRING1 CHARACTER BY CHARACTER WITH ALL CHARACTERS OF STRING1*/ - for (i = 0, ptr1 = s1; *ptr1 != ''; ptr1++) - { - i++; - for (ptr2 = s2; *ptr2 != ''; ptr2++) - { - if (*ptr1 == *ptr2) - { - flag = 1; - break; - } - } - if (flag == 1) - break; - } - if (flag == 1) - printf(" - first occurance of character of string2 in string1 is at position:%d and character is %c", i, *ptr2); - else - printf(" - none of the characters of string1 match with mone of characters of string2"); - } - - - enter the string1: - C Programming Class - - enter the string2: - rnp - - first occurance of character of string2 in string1 is at position:3 and character is p \ No newline at end of file diff --git a/c/_Basic/C Program to Find the Number of Integers Divisible by 5.c b/c/_Basic/C Program to Find the Number of Integers Divisible by 5.c deleted file mode 100644 index fb186f5..0000000 --- a/c/_Basic/C Program to Find the Number of Integers Divisible by 5.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * C program to find the number of integers divisible by - * 5 between the given range num1 and num2, where num1 < num2. - * - * Also find the sum of all these integer numbers which are divisible - * by 5 and display the total. - */ -#include - -void main() -{ - int i, num1, num2, count = 0, sum = 0; - printf("Enter the value of num1 and num2 \n"); - scanf("%d %d", &num1, &num2); - /* Count the number and compute their sum*/ - printf("Integers divisible by 5 are \n"); - for (i = num1; i < num2; i++) - { - if (i % 5 == 0) - { - printf("%3d,", i); - count++; - sum = sum + i; - } - } - printf("\n Number of integers divisible by 5 between %d and %d = - %d\n", num1, num2, count); - printf("Sum of all integers that are divisible by 5 = %d\n", sum); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Find the Size of a Union.c b/c/_Basic/C Program to Find the Size of a Union.c deleted file mode 100644 index c7b8b4e..0000000 --- a/c/_Basic/C Program to Find the Size of a Union.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * C program to find the size of a union - */ -#include - -void main() -{ - union sample - { - int m; - float n; - char ch; - }; - union sample u; - printf("The size of union = %d\n", sizeof(u)); - /* initialization */ - u.m = 25; - printf("%d %f %c\n", u.m, u.n, u.ch); - u.n = 0.2; - printf("%d %f %c\n", u.m, u.n, u.ch); - u.ch = 'p'; - printf("%d %f %c\n", u.m, u.n, u.ch); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Find the Sum of first 50 Natural Numbers using For Loop.c b/c/_Basic/C Program to Find the Sum of first 50 Natural Numbers using For Loop.c deleted file mode 100644 index 90405f7..0000000 --- a/c/_Basic/C Program to Find the Sum of first 50 Natural Numbers using For Loop.c +++ /dev/null @@ -1,15 +0,0 @@ -/* - * C program to find the sum of first 50 natural numbers - * using for loop - */ -#include - -void main() -{ - int num, sum = 0; - for (num = 1; num <= 50; num++) - { - sum = sum + num; - } - printf("Sum = %4d\n", sum); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Find the Sum of two Binary Numbers.c b/c/_Basic/C Program to Find the Sum of two Binary Numbers.c deleted file mode 100644 index b21c4f3..0000000 --- a/c/_Basic/C Program to Find the Sum of two Binary Numbers.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * C Program to Find the Sum of two Binary Numbers - */ -#include - -int main() -{ - long binary1, binary2; - int i = 0, remainder = 0, sum[20]; - printf("Enter the first binary number: "); - scanf("%ld", &binary1); - printf("Enter the second binary number: "); - scanf("%ld", &binary2); - while (binary1 != 0 || binary2 != 0) - { - sum[i++] =(binary1 % 10 + binary2 % 10 + remainder) % 2; - remainder =(binary1 % 10 + binary2 % 10 + remainder) / 2; - binary1 = binary1 / 10; - binary2 = binary2 / 10; - } - if (remainder != 0) - sum[i++] = remainder; - --i; - printf("Sum of two binary numbers: "); - while (i >= 0) - printf("%d", sum[i--]); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Find whether a Number is Prime or Not using Recursion.c b/c/_Basic/C Program to Find whether a Number is Prime or Not using Recursion.c deleted file mode 100644 index 42f2d56..0000000 --- a/c/_Basic/C Program to Find whether a Number is Prime or Not using Recursion.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * C Program to find whether a Number is Prime or Not using Recursion - */ -#include - -int primeno(int, int); - -int main() -{ - int num, check; - printf("Enter a number: "); - scanf("%d", &num); - check = primeno(num, num / 2); - if (check == 1) - { - printf("%d is a prime number\n", num); - } - else - { - printf("%d is not a prime number\n", num); - } - return 0; -} - -int primeno(int num, int i) -{ - if (i == 1) - { - return 1; - } - else - { - if (num % i == 0) - { - return 0; - } - else - { - return primeno(num, i - 1); - } - } -} \ No newline at end of file diff --git a/c/_Basic/C Program to Generate Fibonacci Series.c b/c/_Basic/C Program to Generate Fibonacci Series.c deleted file mode 100644 index 4a41836..0000000 --- a/c/_Basic/C Program to Generate Fibonacci Series.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * C program to generate Fibonacci Series. Fibonacci Series - * is 0 1 1 2 3 5 8 13 21 ... - */ -#include - -void main() -{ - int fib1 = 0, fib2 = 1, fib3, limit, count = 0; - printf("Enter the limit to generate the Fibonacci Series \n"); - scanf("%d", &limit); - printf("Fibonacci Series is ...\n"); - printf("%d\n", fib1); - printf("%d\n", fib2); - count = 2; - while (count < limit) - { - fib3 = fib1 + fib2; - count++; - printf("%d\n", fib3); - fib1 = fib2; - fib2 = fib3; - } -} \ No newline at end of file diff --git a/c/_Basic/C Program to Illustrate Pass by Reference.c b/c/_Basic/C Program to Illustrate Pass by Reference.c deleted file mode 100644 index 9606030..0000000 --- a/c/_Basic/C Program to Illustrate Pass by Reference.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * C Program to Illustrate Pass by Reference - */ -#include - -void cube( int *x); - -int main() -{ - int num = 10; - cube(&num); - printf("the cube of the given number is %d", num); - return 0; -} - -void cube(int *x) -{ - *x = (*x) * (*x) * (*x); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Illustrate Pass by Value.c b/c/_Basic/C Program to Illustrate Pass by Value.c deleted file mode 100644 index 943bc16..0000000 --- a/c/_Basic/C Program to Illustrate Pass by Value.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * C Program to Illustrate Pass by Value. - */ -#include - -void swap(int a, int b) -{ - int temp; - temp = a; - a = b; - b = temp; -} - -int main() -{ - int num1 = 10, num2 = 20; - printf("Before swapping num1 = %d num2 = %d\n", num1, num2); - swap(num1, num2); - printf("After swapping num1 = %d num2 = %d \n", num2, num1); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Illustrate how User Authentication is Done.c b/c/_Basic/C Program to Illustrate how User Authentication is Done.c deleted file mode 100644 index a860cb5..0000000 --- a/c/_Basic/C Program to Illustrate how User Authentication is Done.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * C program is to illustrate how user authentication is done. - * Program asks for the user name and password and displays - * the password as '*' character - */ -#include - -void main() -{ - char password[10], username[10], ch; - int i; - printf("Enter User name: "); - gets(username); - printf("Enter the password < any 8 characters>: "); - for (i = 0; i < 8; i++) - { - ch = getchar(); - password[i] = ch; - ch = '*' ; - printf("%c", ch); - } - password[i] = '\0'; - /* Original password can be printed, if needed */ - printf("\n Your password is :"); - for (i = 0; i < 8; i++) - { - printf("%c", password[i]); - } -} \ No newline at end of file diff --git a/c/_Basic/C Program to Illustrate the Concept of Unions.c b/c/_Basic/C Program to Illustrate the Concept of Unions.c deleted file mode 100644 index 3902e90..0000000 --- a/c/_Basic/C Program to Illustrate the Concept of Unions.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * C program to illustrate the concept of unions - */ -#include - -void main() -{ - union number - { - int n1; - float n2; - }; - union number x; - printf("Enter the value of n1: "); - scanf("%d", &x.n1); - printf("Value of n1 = %d", x.n1); - printf("\nEnter the value of n2: "); - scanf("%f", &x.n2); - printf("Value of n2 = %f\n", x.n2); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Implements Regular Expression Matching.c b/c/_Basic/C Program to Implements Regular Expression Matching.c deleted file mode 100644 index e6e5a26..0000000 --- a/c/_Basic/C Program to Implements Regular Expression Matching.c +++ /dev/null @@ -1,295 +0,0 @@ -/* -* C Program to Implements Regular Expression Matching -*/ -#include -#include -#define MATCH printf(" -The Text Matches The Regular Expression"); -#define NOTMATCH printf(" -The Text Doesn't match the Regular Expression"); - -char reg[20], text[20]; -int main() -{ - int i, rlen, tlen, f = 0; - char ans; - do - { - printf(" - Enter the Regular Expression - "); - scanf(" %[^ - ]s", reg); - for (rlen = 0; reg[rlen] != ''; rlen++); - printf(" - Enter the text - "); - scanf(" %[^ - ]s", text); - for (tlen = 0; text[tlen] != '' ; tlen++); - if (reg[0] == '*') - { - printf(" - Invalid regular expression"); - } - /* - *If the regular expression starts with Alphabet - */ - if ((reg[0] >= 65 && reg[0] <= 90) || (reg[0] >= 97 && reg[0] <=122)) - { - if (reg[0] == text [0]) - { - switch (reg[1]) - { - case '.' : - switch (reg[2]) - { - case '*': - if (tlen != 1) - { - if (reg[3] == text[tlen-1]) - { - MATCH; - } - else - { - NOTMATCH; - } - } - else - { - NOTMATCH; - } - break; - case '+': - if (text[1] != reg[3]) - { - if (reg[3] == text[tlen - 1]) - { - MATCH; - } - else - { - NOTMATCH; - } - } - break; - case '?': - if (text[1] == reg[3] || text[2] == reg[3]) - { - if (text[1] == reg[3] || text[2] == reg[3]) - { - MATCH; - } - else - { - NOTMATCH; - } - } - else - { - NOTMATCH; - } - break; - } - break; - case '*': - if (reg[rlen-1] == text[tlen-1]) - { - for (i = 0; i <= tlen-2; i++) - { - if(text[i] == reg[0]) - { - f = 1; - } - else - { - f = 0; - } - } - if ( f == 1) - { - MATCH; - } - else - { - NOTMATCH; - } - } - else - { - NOTMATCH; - } - break; - case '+' : - if (tlen <= 2) - { - NOTMATCH; - } - else if (reg[rlen-1] == text[tlen-1]) - { - for (i = 0; i < tlen-2; i++) - { - if (text[i] == reg[0]) - { - f = 1; - } - else - { - f = 0; - } - } - if (f == 1) - { - MATCH; - } - else - { - NOTMATCH; - } - } - break; - case '?': - if (reg[rlen -1] == text[tlen-1]) - { - MATCH; - } - else - { - NOTMATCH; - } - break; - } - } - else - printf("Does not match"); - } - /* - *If Regular Expression starts with '^' - */ - else if (reg[0] == '^') - { - if (reg[1] == text[0]) - { - MATCH; - } - else - { - NOTMATCH; - } - } - /* - *If Regular Expression Ends with '$' - */ - else if (reg[rlen-1] == '$') - { - if (reg[rlen-2] == text[rlen-1]) - { - MATCH; - } - else - { - NOTMATCH; - } - } - else - printf("Not Implemented"); - printf(" - Do you want to continue?(Y/N)"); - scanf(" %c", &ans); - } - while (ans == 'Y' || ans == 'y'); -} - - -Enter the Regular Expression -C.*g - -Enter the text -Cprogramming - -The Text Matches The Regular Expression -Do you want to continue?(Y/N)y - -Enter the Regular Expression -C*g - -Enter the text -Cprogramming - -The Text Doesn't match the Regular Expression -Do you want to continue?(Y/N)y - -Enter the Regular Expression -C?.*g - -Enter the text -Cprogramming - -The Text Matches The Regular Expression -Do you want to continue?(Y/N)y - -Enter the Regular Expression -C.?g - -Enter the text -Cprogramming - -The Text Doesn't match the Regular Expression -Do you want to continue?(Y/N)y - -Enter the Regular Expression -C.+g - -Enter the text -Cprogramming - -The Text Matches The Regular Expression -Do you want to continue?(Y/N)y - -Enter the Regular Expression -C+g - -Enter the text -Cprogramming - -The Text Doesn't match the Regular Expression -Do you want to continue?(Y/N)y - -Enter the Regular Expression - -^C.* - -Enter the text -Cprogramming - - -The Text Matches The Regular Expression -Do you want to continue?(Y/N)y - -Enter the Regular Expression -^p.* - -Enter the text -Cprogramming - -The Text Doesn't match the Regular Expression -Do you want to continue?(Y/N)y - -Enter the Regular Expression -C.*g$ - -Enter the text -Cprogramming - -The Text Matches The Regular Expression -Do you want to continue?(Y/N)y - -Enter the Regular Expression -C.*n$- -Enter the text -Cprogramming - -The Text Doesn't match the Regular Expression -Do you want to continue?(Y/N)n \ No newline at end of file diff --git a/c/_Basic/C Program to Input 2 Binary Strings and Print their Binary Sum.c b/c/_Basic/C Program to Input 2 Binary Strings and Print their Binary Sum.c deleted file mode 100644 index 0ad47e1..0000000 --- a/c/_Basic/C Program to Input 2 Binary Strings and Print their Binary Sum.c +++ /dev/null @@ -1,117 +0,0 @@ -/* -* C Program to Input 2 Binary Strings and Print their Binary -* Sum -*/ -#include -#include -#include - -int bin_verify(char []); -void sum(char [], char [], char []); - -int main() -{ - char bin1[33], bin2[33], result[33]; - int len1, len2, check; - printf("Enter binary number 1: "); - scanf("%s", bin1); - printf("Enter binary number 2: "); - scanf("%s", bin2); - check = bin_verify(bin1); - if (check) - { - printf("Invalid binary number %s. - ", bin1); - exit(0); - } - check = bin_verify(bin2); - if (check) - { - printf("Invalid binary number %s. - ", bin2); - exit(0); - } - sum(bin1, bin2, result); - printf("%s + %s = %s - ", bin1, bin2, result); - return 0; -} - -int bin_verify(char str[]) -{ - int i; - for (i = 0; i < strlen(str); i++) - { - if ((str[i] - '0' != 1 ) && (str[i] - '0' != 0)) - { - return 1; - } - } - return 0; -} - -void sum(char bin1[], char bin2[], char result[]) -{ - int i = strlen(bin1) - 1; - int j = strlen(bin2) - 1; - int carry = 0, temp, num1, num2; - while (i > -1 && j > -1) - { - num1 = bin1[i] - '0'; - num2 = bin2[j] - '0'; - temp = num1 + num2 + carry; - if (temp / 2 == 1) - { - carry = 1; - temp %= 2; - } - if (i > j) - { - result[i + 1] = temp + '0'; - result[strlen(bin1) + 1] = ''; - } - else - { - result[j +1] = temp + '0'; - result[strlen(bin2) + 1] = ''; - } - i--; - j--; - } - while (i > -1) - { - temp = bin1[i] + carry - '0'; - if (temp / 2 == 1) - { - carry = 1; - temp %= 2; - } - result[i + 1] = temp + '0'; - i--; - } - while (j > -1) - { - temp = bin2[j] + carry - '0'; - if (temp / 2 == 1) - { - carry = 1; - temp %= 2; - } - result[j + 1] = temp + '0'; - j--; - } - if (carry) - { - result[0] = '1'; - } - else - { - result[0] = '0'; - } -} - - - -Enter binary number 1: 0110 -Enter binary number 2: 1011 -0110 + 1011 = 10001 diff --git a/c/_Basic/C Program to Input 3 Arguments and Operate Appropriately on the Numbers.c b/c/_Basic/C Program to Input 3 Arguments and Operate Appropriately on the Numbers.c deleted file mode 100644 index 7ef0d69..0000000 --- a/c/_Basic/C Program to Input 3 Arguments and Operate Appropriately on the Numbers.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * C Program to Input 3 Arguments and Operate Appropriately on the - * Numbers - */ -#include - -void main(int argc, char * argv[]) -{ - int a, b, result; - char ch; - printf("arguments entered: \n"); - a = atoi(argv[1]); - b = atoi(argv[2]); - ch = *argv[3]; - printf("%d %d %c", a, b, ch); - switch (ch) - { - case '+': - result = a + b; - break; - case '-': - result = a - b; - break; - case 'x': - result = a * b; - break; - case '/': - result = a / b; - break; - default: - printf("Enter a valid choice"); - } - printf("\nThe result of the operation is %d", result); - printf("\n"); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Maintain an Inventory of items in Online Store.c b/c/_Basic/C Program to Maintain an Inventory of items in Online Store.c deleted file mode 100644 index 478d584..0000000 --- a/c/_Basic/C Program to Maintain an Inventory of items in Online Store.c +++ /dev/null @@ -1,47 +0,0 @@ - #include - #include - void main() { - struct date { - int day; - int month; - int year; - }; - struct details { - char name[20]; - int price; - int code; - int qty; - struct date mfg; - }; - struct details item[50]; - int n,i; - clrscr(); - printf("Enter number of items:"); - scanf("%d",&n); - fflush(stdin); - for (i=0;i - -void main() -{ - long number, tempnum; - printf("Enter an integer \n"); - scanf("%ld", &number); - tempnum = number; - /* left shift by two bits */ - number = number << 2; - printf("%ld x 4 = %ld\n", tempnum, number); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Print Armstrong Number from 1 to 1000.c b/c/_Basic/C Program to Print Armstrong Number from 1 to 1000.c deleted file mode 100644 index 263eb55..0000000 --- a/c/_Basic/C Program to Print Armstrong Number from 1 to 1000.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * C Program to Print Armstrong Number from 1 to 1000 - */ -#include - -main() -{ - int number, temp, digit1, digit2, digit3; - printf("Print all Armstrong numbers between 1 and 1000:\n"); - number = 001; - while (number <= 900) - { - digit1 = number - ((number / 10) * 10); - digit2 = (number / 10) - ((number / 100) * 10); - digit3 = (number / 100) - ((number / 1000) * 10); - temp = (digit1 * digit1 * digit1) + (digit2 * digit2 * digit2) + (digit3 * digit3 * digit3); - if (temp == number) - { - printf("\n Armstrong no is:%d", temp); - } - number++; - } -} \ No newline at end of file diff --git a/c/_Basic/C Program to Print Binary Equivalent of an Integer using Recursion.c b/c/_Basic/C Program to Print Binary Equivalent of an Integer using Recursion.c deleted file mode 100644 index 5e26e51..0000000 --- a/c/_Basic/C Program to Print Binary Equivalent of an Integer using Recursion.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * C Program to Print Binary Equivalent of an Integer using Recursion - */ -#include - -int binary_conversion(int); - -int main() -{ - int num, bin; - printf("Enter a decimal number: "); - scanf("%d", &num); - bin = binary_conversion(num); - printf("The binary equivalent of %d is %d\n", num, bin); -} - -int binary_conversion(int num) -{ - if (num == 0) - { - return 0; - } - else - { - return (num % 2) + 10 * binary_conversion(num / 2); - } -} -} \ No newline at end of file diff --git a/c/_Basic/C Program to Print Combination of two Words of two given Strings without any Repetition.c b/c/_Basic/C Program to Print Combination of two Words of two given Strings without any Repetition.c deleted file mode 100644 index ea4b4f0..0000000 --- a/c/_Basic/C Program to Print Combination of two Words of two given Strings without any Repetition.c +++ /dev/null @@ -1,48 +0,0 @@ -/* -* C Program to Print Combination of two Words of two -* given Strings without any Repetition -*/ -#include -#include - -void main() -{ - char string[100], str[10], c[10]; - int z, occ = 0, i = 0, j = 0, count = 0, len = 0; - printf("Enter a string:"); - scanf("%[^ - ]s", string); - printf("Enter the word to check its occurence:"); - scanf("%s", str); - len = strlen(str); - for (i = 0; string[i] != ''; i++) - { - count = 0; - for (j = 0, z = i; j < len; j++, z++) - { - c[j] = string[z]; - if (c[j] == str[j]) - { - count++; /* Incrementing the count if the characters of the main string match with the characters of the given word */ - } - } - if (count == len && string[z] == ' ') - { - occ++; /* Incrementing the occ if word matches completely and next character in string is space */ - } - } - printf("The number of occ is %d - ", occ); -} - -Enter a string: -welcome to illumin8's c programming class, welcome again to c class -Enter the word to check its occurence: -welcome -The number of occ is 2 - -Enter a string: -welcome to illumin8's c programming class, welcome again to c class -Enter the word to check its occurence: -c -The number of occ is 2 diff --git a/c/_Basic/C Program to Print Diamond Pattern.c b/c/_Basic/C Program to Print Diamond Pattern.c deleted file mode 100644 index 1687a5d..0000000 --- a/c/_Basic/C Program to Print Diamond Pattern.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * C Program to Print Diamond Pattern - */ -#include - -int main() -{ - int number, i, k, count = 1; - printf("Enter number of rows\n"); - scanf("%d", &number); - count = number - 1; - for (k = 1; k <= number; k++) - { - for (i = 1; i <= count; i++) - printf(" "); - count--; - for (i = 1; i <= 2 * k - 1; i++) - printf("*"); - printf("\n"); - } - count = 1; - for (k = 1; k <= number - 1; k++) - { - for (i = 1; i <= count; i++) - printf(" "); - count++; - for (i = 1 ; i <= 2 *(number - k)- 1; i++) - printf("*"); - printf("\n"); - } - return 0; -} - -/* - * - *** - ***** - ******* -********* - ******* - ***** - *** \ No newline at end of file diff --git a/c/_Basic/C Program to Print a Semicolon without using a Semicolon anywhere in the Code.c b/c/_Basic/C Program to Print a Semicolon without using a Semicolon anywhere in the Code.c deleted file mode 100644 index 6bb4f8d..0000000 --- a/c/_Basic/C Program to Print a Semicolon without using a Semicolon anywhere in the Code.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * C Program to Print a Semicolon without using a Semicolon - * anywhere in the code - */ -#include - -int main(void) -{ - //59 is the ascii value of semicolumn - if (printf("%c ", 59)) - { - } - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Print any Print Statement without using Semicolon.c b/c/_Basic/C Program to Print any Print Statement without using Semicolon.c deleted file mode 100644 index 1c6472d..0000000 --- a/c/_Basic/C Program to Print any Print Statement without using Semicolon.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * C Program to Print any Print Statement without using Semicolon - */ -#include - -void main() -{ - if(printf("Hi.. Welcome to sanfoundry")) - { - } -} \ No newline at end of file diff --git a/c/_Basic/C Program to Print the Program Name and All its Arguments.c b/c/_Basic/C Program to Print the Program Name and All its Arguments.c deleted file mode 100644 index af6f1cd..0000000 --- a/c/_Basic/C Program to Print the Program Name and All its Arguments.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * C Program to Print the Program Name and All its Arguments - */ -#include - -void main(int argc, char *argv[]) /* command line Arguments */ -{ - int i; - for (i = 0; i < argc; i++) - { - printf("%s ", argv[i]); /* Printing the string */ - } - printf("\n"); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Print the Words Ending with Letter S.c b/c/_Basic/C Program to Print the Words Ending with Letter S.c deleted file mode 100644 index 46a8dc3..0000000 --- a/c/_Basic/C Program to Print the Words Ending with Letter S.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * C Program to Print the Words Ending with Letter S -*/ -#include -#include - -char str[100]; - -void main() -{ - int i, t, j, len; - printf("Enter a string : "); - scanf("%[^ - ]s", str); - len = strlen(str); - str[len] = ' '; - for (t = 0, i = 0; i < strlen(str); i++) - { - if ((str[i] == ' ') && (str[i - 1] == 's')) - { - for (j = t; j < i; j++) - printf("%c", str[j]); - t = i + 1; - printf(" - "); - } - else - { - if (str[i] == ' ') - { - t = i + 1; - } - } - } -} - -Enter a string : -Welcome to Illumin8's C Programming Class, Welcome Again to C Class ! Illumin8's Class \ No newline at end of file diff --git a/c/_Basic/C Program to Read Two Integers M and N & Swap their Values.c b/c/_Basic/C Program to Read Two Integers M and N & Swap their Values.c deleted file mode 100644 index 715268e..0000000 --- a/c/_Basic/C Program to Read Two Integers M and N & Swap their Values.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * C program to read two integers M and N and to swap their values. - * Use a user-defined function for swapping. Output the values of M - * and N before and after swapping. - */ -#include -void swap(float *ptr1, float *ptr2); - -void main() -{ - float m, n; - printf("Enter the values of M and N \n"); - scanf("%f %f", &m, &n); - printf("Before Swapping:M = %5.2ftN = %5.2f\n", m, n); - swap(&m, &n); - printf("After Swapping:M = %5.2ftN = %5.2f\n", m, n); -} -/* Function swap - to interchanges the contents of two items */ -void swap(float *ptr1, float *ptr2) -{ - float temp; - temp = *ptr1; - *ptr1 = *ptr2; - *ptr2 = temp; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Read a Grade & Display the Equivalent Description.c b/c/_Basic/C Program to Read a Grade & Display the Equivalent Description.c deleted file mode 100644 index 04a4516..0000000 --- a/c/_Basic/C Program to Read a Grade & Display the Equivalent Description.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * C Program to accept a grade and declare the equivalent description - * if code is S, then print SUPER - * if code is A, then print VERY GOOD - * if code is B, then print FAIR - * if code is Y, then print ABSENT - * if code is F, then print FAILS - */ -#include -#include -#include - -void main() -{ - char remark[15]; - char grade; - printf("Enter the grade \n"); - scanf("%c", &grade); - /* lower case letter to upper case */ - grade = toupper(grade); - switch(grade) - { - case 'S': - strcpy(remark, " SUPER"); - break; - case 'A': - strcpy(remark, " VERY GOOD"); - break; - case 'B': - strcpy(remark, " FAIR"); - break; - case 'Y': - strcpy(remark, " ABSENT"); - break; - case 'F': - strcpy(remark, " FAILS"); - break; - default : - strcpy(remark, "ERROR IN GRADE \n"); - break; - } - printf("RESULT : %s\n", remark); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Reverse a Given Number.c b/c/_Basic/C Program to Reverse a Given Number.c deleted file mode 100644 index 93af145..0000000 --- a/c/_Basic/C Program to Reverse a Given Number.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * C program to accept an integer and reverse it - */ -#include - -void main() -{ - long num, reverse = 0, temp, remainder; - printf("Enter the number\n"); - scanf("%ld", &num); - temp = num; - while (num > 0) - { - remainder = num % 10; - reverse = reverse * 10 + remainder; - num /= 10; - } - printf("Given number = %ld\n", temp); - printf("Its reverse is = %ld\n", reverse); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Reverse a Number & Check if it is a Palindrome.c b/c/_Basic/C Program to Reverse a Number & Check if it is a Palindrome.c deleted file mode 100644 index e793701..0000000 --- a/c/_Basic/C Program to Reverse a Number & Check if it is a Palindrome.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * C program to reverse a given integer number and check - * whether it is a palindrome. Display the given number - * with appropriate message - */ -#include - -void main() -{ - int num, temp, remainder, reverse = 0; - printf("Enter an integer \n"); - scanf("%d", &num); - /* original number is stored at temp */ - temp = num; - while (num > 0) - { - remainder = num % 10; - reverse = reverse * 10 + remainder; - num /= 10; - } - printf("Given number is = %d\n", temp); - printf("Its reverse is = %d\n", reverse); - if (temp == reverse) - printf("Number is a palindrome \n"); - else - printf("Number is not a palindrome \n"); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Search a Word & Replace it with the Specified Word.c b/c/_Basic/C Program to Search a Word & Replace it with the Specified Word.c deleted file mode 100644 index d32ec6f..0000000 --- a/c/_Basic/C Program to Search a Word & Replace it with the Specified Word.c +++ /dev/null @@ -1,72 +0,0 @@ -/* -* C Program to Search a Word & Replace it with the Specified Word -*/ -#include -#include -#include - -/*Function to replace a string with another string*/ - -char *rep_str(const char *s, const char *old, const char *new1) -{ - char *ret; - int i, count = 0; - int newlen = strlen(new1); - int oldlen = strlen(old); - for (i = 0; s[i] != ''; i++) - { - if (strstr(&s[i], old) == &s[i]) - { - count++; - i += oldlen - 1; - } - } - ret = (char *)malloc(i + count * (newlen - oldlen)); - if (ret == NULL) - exit(EXIT_FAILURE); - i = 0; - while (*s) - { - if (strstr(s, old) == s) //compare the substring with the newstring - { - strcpy(&ret[i], new1); - i += newlen; //adding newlength to the new string - s += oldlen;//adding the same old length the old string - } - else - ret[i++] = *s++; - } - ret[i] = ''; - return ret; -} - -int main(void) -{ - char mystr[100], c[10], d[10]; - printf("Enter a string along with characters to be rep_strd: - "); - gets(mystr); - printf("Enter the character to be rep_strd: - "); - scanf(" %s",c); - printf("Enter the new character: - "); - scanf(" %s",d); - char *newstr = NULL; - puts(mystr); - newstr = rep_str(mystr, c,d); - printf("%s - ", newstr); - free(newstr); - return 0; -} - - - Enter a string along with characters to be rep_strd: - prrrogram C prrrogramming - Enter the character to be rep_strd: - rr - Enter the new character: - mmm - prrrogram C prrrogramming - pmmmrogram C pmmmrogramming \ No newline at end of file diff --git a/c/_Basic/C Program to Shutdown or Turn Off the Computer in Linux.c b/c/_Basic/C Program to Shutdown or Turn Off the Computer in Linux.c deleted file mode 100644 index a88db5b..0000000 --- a/c/_Basic/C Program to Shutdown or Turn Off the Computer in Linux.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * C Program to Shutdown or Turn Off the Computer in Linux. - */ -#include - -int main() -{ - system("shutdown -P now"); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C Program to Swap the Contents of two Numbers using Bitwise XOR Operation.c b/c/_Basic/C Program to Swap the Contents of two Numbers using Bitwise XOR Operation.c deleted file mode 100644 index 09f7b13..0000000 --- a/c/_Basic/C Program to Swap the Contents of two Numbers using Bitwise XOR Operation.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * C program to swap the contents of two numbers using bitwise XOR - * operation. Don't use either the temporary variable or arithmetic - * operators - */ -#include - -void main() -{ - long i, k; - printf("Enter two integers \n"); - scanf("%ld %ld", &i, &k); - printf("\n Before swapping i= %ld and k = %ld", i, k); - i = i ^ k; - k = i ^ k; - i = i ^ k; - printf("\n After swapping i= %ld and k = %ld", i, k); -} \ No newline at end of file diff --git a/c/_Basic/C Program to Use Bitwise Operations to Count the Number of Leading Zero's in a Number x.c b/c/_Basic/C Program to Use Bitwise Operations to Count the Number of Leading Zero's in a Number x.c deleted file mode 100644 index 84eeefc..0000000 --- a/c/_Basic/C Program to Use Bitwise Operations to Count the Number of Leading Zero's in a Number x.c +++ /dev/null @@ -1,114 +0,0 @@ -/* -* C Program to Use Bitwise Operations to Count the Number of -* Leading Zero's in a Number x -*/ -#include -#include -#define NUM_BITS_INT (sizeof(int)*8) -int find(int); - -void main() -{ - int n, i, a, count = 0, flag = 1, m = 1, j, cmp; - printf("Enter the number - "); - scanf("%d", &n); - a = n >> 31 & 1; - if (a == 0) - { - for (i = (NUM_BITS_INT)-1; i >= 0; i--) - { - a = (n >> i)& 1; - if (a == 0) - { - count++; - } - else - { - for (j = n + 1;; j++) - { - cmp = find(j); - if (cmp == (((NUM_BITS_INT)-1) - count) + 1) - { - printf("next higher power -> %d - ", j); - break; - } - } - break; - } - } - } - else - { - for (i = (NUM_BITS_INT)-1; i >= 0; i--) - { - a = (n >> i)& 1; - if (a == 1) - { - count++; - } - else - { - for (j = n + 1;; j++) - { - cmp = find(j); - if (cmp == (((NUM_BITS_INT)- 1) - count)) - { - printf("next higher power -> %d - ", j); - break; - } - } - break; - } - } - } -} - -/* To find trailing zero's */ -int find(int n) -{ - int count = 0, a, flag = 1, i; - for (i = 0; i <= (NUM_BITS_INT) - 1; i++) - { - a = (n >> i) & 1; - if (a == 1 && flag == 1) - { - return count; - } - else - { - count++; - flag = 1; - } - } -} - - -Enter the number -9 -next higher power -> 16 - -Enter the number --20 -next higher power -> -16 -Enter the number -44 -next higher power -> 64 - -Enter the number --7 -next higher power -> -4 - -Enter the number --31 -next higher power -> -16 - -Enter the number --56 -next higher power -> -32 - -Enter the number -34 -next higher power -> 64 diff --git a/c/_Basic/C Program to calculate the total execution time of a program.c b/c/_Basic/C Program to calculate the total execution time of a program.c deleted file mode 100644 index 4f64895..0000000 --- a/c/_Basic/C Program to calculate the total execution time of a program.c +++ /dev/null @@ -1,19 +0,0 @@ - #include - #include - int main() { - int i; - double total_time; - clock_t start, end; - start = clock(); - //time count starts - srand(time(NULL)); - for (i = 0; i < 25000; i++) { - printf("random_number[%d]= %d\n", i + 1, rand()); - } - end = clock(); - //time count stops - total_time = ((double) (end - start)) / CLK_TCK; - //calulate total time - printf("\nTime taken to print 25000 random number is: %f", total_time); - return 0; - } \ No newline at end of file diff --git a/c/_Basic/C Program to find Product of 2 Numbers using Recursion.c b/c/_Basic/C Program to find Product of 2 Numbers using Recursion.c deleted file mode 100644 index f1b754a..0000000 --- a/c/_Basic/C Program to find Product of 2 Numbers using Recursion.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * C Program to find Product of 2 Numbers using Recursion - */ -#include - -int product(int, int); - -int main() -{ - int a, b, result; - printf("Enter two numbers to find their product: "); - scanf("%d%d", &a, &b); - result = product(a, b); - printf("Product of %d and %d is %d\n", a, b, result); - return 0; -} - -int product(int a, int b) -{ - if (a < b) - { - return product(b, a); - } - else if (b != 0) - { - return (a + product(a, b - 1)); - } - else - { - return 0; - } -} \ No newline at end of file diff --git a/c/_Basic/C Program to find Reverse of a Number using Recursion.c b/c/_Basic/C Program to find Reverse of a Number using Recursion.c deleted file mode 100644 index 303ad1f..0000000 --- a/c/_Basic/C Program to find Reverse of a Number using Recursion.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * C program to find the reverse of a number using recursion - */ -#include -#include - -int rev(int, int); - -int main() -{ - int num, result; - int length = 0, temp; - printf("Enter an integer number to reverse: "); - scanf("%d", &num); - temp = num; - while (temp != 0) - { - length++; - temp = temp / 10; - } - result = rev(num, length); - printf("The reverse of %d is %d.\n", num, result); - return 0; -} - -int rev(int num, int len) -{ - if (len == 1) - { - return num; - } - else - { - return (((num % 10) * pow(10, len - 1)) + rev(num / 10, --len)); - } -} \ No newline at end of file diff --git a/c/_Basic/C Program to find Sum of N Numbers using Recursion.c b/c/_Basic/C Program to find Sum of N Numbers using Recursion.c deleted file mode 100644 index a610461..0000000 --- a/c/_Basic/C Program to find Sum of N Numbers using Recursion.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * C Program to find Sum of N Numbers using Recursion - */ -#include - -void display(int); - -int main() -{ - int num, result; - printf("Enter the Nth number: "); - scanf("%d", &num); - display(num); - return 0; -} - -void display(int num) -{ - static int i = 1; - if (num == i) - { - printf("%d \n", num); - return; - } - else - { - printf("%d ", i); - i++; - display(num); - } -} \ No newline at end of file diff --git a/c/_Basic/C Program to next higher value of n with same 1's.c b/c/_Basic/C Program to next higher value of n with same 1's.c deleted file mode 100644 index dc956db..0000000 --- a/c/_Basic/C Program to next higher value of n with same 1's.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - -* C Program to next higher value of n with same 1's -*/ -#define NUM_BITS_INT 32 -#include -int newcount(int); - -void main() -{ - int count1 = 0, k = 0, j, t, n, bit, i = 1, count = 0; - printf("Enter a number : "); - scanf("%d", &n); - t = n; - while(t != 0) - { - bit = t & 0x80000000; - if (bit == -0x80000000) - { - bit = 1; - } - if (bit == 1) - count++; - t = t << 1; - } - for (k = n + 1;; k++) - { - count1 = newcount(k); - if (count1 == count) - { - printf("The next highest number is : %d ", k); - break; - } - } -} - -/* To count the no. of 1's in the no. */ -int newcount(int k) -{ - int bit, count = 0; - while (k != 0) - { - bit = k & 0x80000000; - if (bit == -0x80000000) - { - bit = 1; - } - if (bit == 1) - count++; - k = k << 1; - } - return(count); -} - - -Enter a number : 128 -The next highest number is : 256 -Enter a number : 127 -The next highest number is : 191 -Enter a number : 6 -The next highest number is : 9 -Enter a number : 12 -The next highest number is : 17 \ No newline at end of file diff --git a/c/_Basic/C Program to replace first letter of every word with caps.c b/c/_Basic/C Program to replace first letter of every word with caps.c deleted file mode 100644 index 77abf20..0000000 --- a/c/_Basic/C Program to replace first letter of every word with caps.c +++ /dev/null @@ -1,61 +0,0 @@ -/* -* C Program to replace first letter of every word with caps -*/ -#include -#include -void main(int argc, char *argv[]) -{ - FILE *fp1; - int return_val; - if ((fp1 = fopen(argv[1],"r+")) = = NULL) - { - printf("file cant be opened"); - exit(0); - } - return_val = init_cap_file(fp1); - if (return_val == 1) - { - printf(" - success"); - } - else - { - printf(" - failure"); - } -} -int init_cap_file(FILE *fp1) -{ - char ch; - ch = fgetc(fp1); - if (ch >= 97 && ch <= 122) - { - fseek(fp1, -1L, 1); - fputc(ch - 32, fp1); - } - while (ch != EOF) - { - if (ch = = ' '|| ch == ' - ') - { - ch = fgetc(fp1); - if (ch >= 97 && ch <= 122) - { - fseek(fp1, -1L, 1); - fputc(ch - 32, fp1); - } - } - else - ch = fgetc(fp1); - } - return 1; -} -chandana ravella -chanikya ravella -sree lakshmi ravella -sree ramulu ravella -cat file5test -Chandana Ravella -Chanikya Ravella -Sree Lakshmi Ravella -Sree Ramulu Ravella \ No newline at end of file diff --git a/c/_Basic/C Program to sort string ignoring whitespaces and repeating characters only once.c b/c/_Basic/C Program to sort string ignoring whitespaces and repeating characters only once.c deleted file mode 100644 index c609be5..0000000 --- a/c/_Basic/C Program to sort string ignoring whitespaces and repeating characters only once.c +++ /dev/null @@ -1,64 +0,0 @@ - -/* -* C Program to sort string ignoring whitespaces and repeating characters only once -*/ -#include -#include - -#define SIZE 50 - -void main() -{ - char string[SIZE], string1[SIZE], string2[SIZE]; - int i, j = 0, a = 0, temp, len = 0, len1 = 0, k = 0; - printf(" - Enter a string:"); - scanf("%[^ - ]s", string1); - /* Code to remove whitespaces */ - for (i = 0; string1[i] != ''; i++) - { - if (string1[i] == ' ') - { - continue; - } - string[j++] = string1[i]; - } - /* Code to sort the string */ for (i = 0; string[i] != ''; i++) - { - for (j = i + 1; string[j] != ''; j++) - { - if (string[i] > string[j]) - { - temp = string[i]; - string[i] = string[j]; - string[j] = temp; - } - } - } - string[i] = ''; - len = strlen(string); - /* Code to remove redundant characters */ - for (i = 0; string[i] != ''; i++) - { - if (string[i] == string[i + 1] && string[i + 1] != '') - { - k++; - continue; - } - string2[a++] = string[i]; - string[a] = ''; - } - len1 = len - k; - printf("The sorted string is:"); - for (temp = 0; temp < len1; temp++) - { - printf("%c", string2[temp]); - } -} - - -Enter a string: -abcdel bcdl abcdefg -The sorted string is: -abcdefgl diff --git a/c/_Basic/C program for Binary to decimal conversion.c b/c/_Basic/C program for Binary to decimal conversion.c deleted file mode 100644 index 19ab181..0000000 --- a/c/_Basic/C program for Binary to decimal conversion.c +++ /dev/null @@ -1,16 +0,0 @@ -/*binary to decimal conversion:*/ -#include -void main() -{ - long int bn,dn=0,j=1,remainder; - printf("Enter any number any binary number: "); - scanf("%ld",&bn); - while(bn!=0) - { - remainder=bn%10; - dn=dn+remainder*j; - j=j*2; - bn=bn/10; - } - printf("Equivalent decimal value: %ld",dn); -} \ No newline at end of file diff --git a/c/_Basic/C program for decimal to octal converter.c b/c/_Basic/C program for decimal to octal converter.c deleted file mode 100644 index e0a294b..0000000 --- a/c/_Basic/C program for decimal to octal converter.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -void main() -{ - long int dn,remainder,q; - int on[100],i=1,j; - printf("Enter any decimal number"); - scanf("%ld",&dn); - q = dn; - while(q!=0) - { - on[i++]= q % 8; - q = q/ 8; - } - printf("Equivalent octal value %d: ",dn); - for(j = i -1 ; j> 0; j--) - printf("%d",on[j]); -} \ No newline at end of file diff --git a/c/_Basic/C program for hexadecimal to binary conversion.c b/c/_Basic/C program for hexadecimal to binary conversion.c deleted file mode 100644 index 91b1d80..0000000 --- a/c/_Basic/C program for hexadecimal to binary conversion.c +++ /dev/null @@ -1,85 +0,0 @@ -#include -#define MAX 1000 -void main() -{ - char hd[MAX]; - long int i=0; - printf("Enter any hexadecimal number: "); - scanf("%s",hd); - printf("\nEquivalent binary value: "); - while(hd[i]) - { - switch(hd[i]) - { - case '0': - printf("0000"); - break; - case '1': - printf("0001"); - break; - case '2': - printf("0010"); - break; - case '3': - printf("0011"); - break; - case '4': - printf("0100"); - break; - case '5': - printf("0101"); - break; - case '6': - printf("0110"); - break; - case '7': - printf("0111"); - break; - case '8': - printf("1000"); - break; - case '9': - printf("1001"); - break; - case 'A': - printf("1010"); - break; - case 'B': - printf("1011"); - break; - case 'C': - printf("1100"); - break; - case 'D': - printf("1101"); - break; - case 'E': - printf("1110"); - break; - case 'F': - printf("1111"); - break; - case 'a': - printf("1010"); - break; - case 'b': - printf("1011"); - break; - case 'c': - printf("1100"); - break; - case 'd': - printf("1101"); - break; - case 'e': - printf("1110"); - break; - case 'f': - printf("1111"); - break; - default: - printf("\nInvalid hexadecimal digit %c ",hd[i]); - } - i++; - } -} \ No newline at end of file diff --git a/c/_Basic/C program to Convert Decimal to Hexadecimal.c b/c/_Basic/C program to Convert Decimal to Hexadecimal.c deleted file mode 100644 index f75b9e5..0000000 --- a/c/_Basic/C program to Convert Decimal to Hexadecimal.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * C program to Convert Decimal to Hexadecimal - */ -#include - -int main() -{ - long decimalnum, quotient, remainder; - int i, j = 0; - char hexadecimalnum[100]; - printf("Enter decimal number: "); - scanf("%ld", &decimalnum); - quotient = decimalnum; - while (quotient != 0) - { - remainder = quotient % 16; - if (remainder < 10) - hexadecimalnum[j++] = 48 + remainder; - else - hexadecimalnum[j++] = 55 + remainder; - quotient = quotient / 16; - } - // display integer into character - for (i = j; i >= 0; i--) - printf("%c", hexadecimalnum[i]); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C program to Convert Decimal to Octal.c b/c/_Basic/C program to Convert Decimal to Octal.c deleted file mode 100644 index 0fe7667..0000000 --- a/c/_Basic/C program to Convert Decimal to Octal.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * C program to Convert Decimal to Octal - */ -#include - -int main() -{ - long decimalnum, remainder, quotient; - int octalNumber[100], i = 1, j; - printf("Enter the decimal number: "); - scanf("%ld", &decimalnum); - quotient = decimalnum; - while (quotient != 0) - { - octalNumber[i++] = quotient % 8; - quotient = quotient / 8; - } - printf("Equivalent octal value of decimal no %d: ", decimalnum); - for (j = i - 1; j > 0; j--) - printf("%d", octalNumber[j]); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C program to Increase 1 to all of the given Integer Digit.c b/c/_Basic/C program to Increase 1 to all of the given Integer Digit.c deleted file mode 100644 index 25055d3..0000000 --- a/c/_Basic/C program to Increase 1 to all of the given Integer Digit.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * C program to Increase 1 to all of the given Integer Digit - */ -#include - -int main() -{ - int number, sum = 0, remainder, count; - printf("Enter a number: "); - scanf("%d", &number); - while (number) - { - remainder = number % 10; - sum = sum + (remainder + 1); - number /= 10; - } - printf("increasing 1 to all digits: %d", sum); - return 0; -} \ No newline at end of file diff --git a/c/_Basic/C program to accept N numbers sorted in ascending order and to search for a given number using binary search..c b/c/_Basic/C program to accept N numbers sorted in ascending order and to search for a given number using binary search..c deleted file mode 100644 index 193d94c..0000000 --- a/c/_Basic/C program to accept N numbers sorted in ascending order and to search for a given number using binary search..c +++ /dev/null @@ -1,121 +0,0 @@ -/* -* C program to accept N numbers sorted in ascending order -* and to search for a given number using binary search. -* Report success or failure. -*/ -#include - -void main() -{ - int array[10]; - int i, j, num, temp, keynum; - int low, mid, high; - printf("Enter the value of num - "); - scanf("%d", &num); - printf("Enter the elements one by one - "); - for (i = 0; i < num; i++) - { - scanf("%d", &array[i]); - } - printf("Input array elements - "); - for (i = 0; i < num; i++) - { - printf("%d - ", array[i]); - } -/* Bubble sorting begins */ -for (i = 0; i < num; i++) - { - for (j = 0; j < (num - i - 1); j++) - { - if (array[j] > array[j + 1]) - { - temp = array[j]; - array[j] = array[j + 1]; - array[j + 1] = temp; - } - } - } - printf("Sorted array is... - "); - for (i = 0; i < num; i++) - { - printf("%d - ", array[i]); - } -printf("Enter the element to be searched - "); - scanf("%d", &keynum); - /* Binary searching begins */ - low = 1; - high = num; - do - { - mid = (low + high) / 2; - if (keynum < array[mid]) - high = mid - 1; - else if (keynum > array[mid]) - low = mid + 1; - } - while (keynum != array[mid] && low <= high); - if (keynum == array[mid]) - { - printf("SEARCH SUCCESSFUL - "); - } - else - { - printf("SEARCH FAILED - "); - } -} - - -Enter the value of num -5 -Enter the elements one by one -23 -90 -56 -15 -58 -Input array elements -23 - -90 -56 -15 -58 -Sorted array is... -15 -23 -56 -58 -90 -Enter the element to be searched -58 -SEARCH SUCCESSFUL - -Enter the value of num -4 -Enter the elements one by one -1 -98 -65 -45 -Input array elements -1 -98 -65 -45 -Sorted array is... -1 -45 -65 -98 -Enter the element to be searched -6 -SEARCH FAILED \ No newline at end of file diff --git a/c/_Basic/C program to accept an array of 10 elements and swap 3rd element with 4th element using pointers and display the results..c b/c/_Basic/C program to accept an array of 10 elements and swap 3rd element with 4th element using pointers and display the results..c deleted file mode 100644 index 71692c5..0000000 --- a/c/_Basic/C program to accept an array of 10 elements and swap 3rd element with 4th element using pointers and display the results..c +++ /dev/null @@ -1,47 +0,0 @@ -/* * C program to accept an array of 10 elements and swap 3rd element * with 4th element using pointers and display the results. */ -#include -void swap34(float *ptr1, float *ptr2); -void main() -{ - float x[10]; - int i, n; - printf("How many Elements... - "); - scanf("%d", &n); - printf("Enter Elements one by one - "); - for (i = 0; i < n; i++) - { - scanf("%f", x + i); - } - /* Function call:Interchanging 3rd element by 4th */ - swap34(x + 2, x + 3); - printf(" - Resultant Array... - "); - for (i = 0; i < n; i++) - { - printf("X[%d] = %f - ", i, x[i]); - } -} -/* Function to swap the 3rd element with the 4th element in the array */ -void swap34(float *ptr1, float *ptr2 ) -{ - float temp; - temp = *ptr1; - *ptr1 = *ptr2; - *ptr2 = temp; -} -How many Elements... -4 -Enter Elements one by one -23 -67 -45 -15 -Resultant Array... -X[0] = 23.000000 - X[1] = 67.000000 - X[2] = 15.000000 - X[3] = 45.000000 \ No newline at end of file diff --git a/c/_Basic/C program to find the length of a string without using the built-in function also check whether it is a palindrome.c b/c/_Basic/C program to find the length of a string without using the built-in function also check whether it is a palindrome.c deleted file mode 100644 index 0333342..0000000 --- a/c/_Basic/C program to find the length of a string without using the built-in function also check whether it is a palindrome.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * C program to find the length of a string without using the - * built-in function also check whether it is a palindrome - */ -#include -#include - -void main() -{ - char string[25], reverse_string[25] = {''}; - int i, length = 0, flag = 0; - printf("Enter a string - "); - gets(string); - /* keep going through each character of the string till its end */ - for (i = 0; string[i] != ''; i++) - { - length++; - } -printf("The length of the string '%s' = %d - ", string, length); - for (i = length - 1; i >= 0 ; i--) - { - reverse_string[length - i - 1] = string[i]; - } - /* Check if the string is a Palindrome */ - for (flag = 1, i = 0; i < length ; i++) - { - if (reverse_string[i] != string[i]) - flag = 0; - } - if (flag == 1) - printf ("%s is a palindrome ", string); - else - printf("%s is not a palindrome ", string); - } - - -Enter a string -how are you -The length of the string 'how are you' = 12 - how are you is not a palindrome - - Enter a string - madam - The length of the string 'madam' = 5 - madam is a palindrome \ No newline at end of file diff --git a/c/_Basic/C program to find the number of occurences of a given number in a list.c b/c/_Basic/C program to find the number of occurences of a given number in a list.c deleted file mode 100644 index 9610b47..0000000 --- a/c/_Basic/C program to find the number of occurences of a given number in a list.c +++ /dev/null @@ -1,50 +0,0 @@ -/* -* C program to find the number of occurences of a given number in a -* list -*/ -#include - -void occur(int [], int, int, int, int *); - -int main() -{ - int size, key, count = 0; - int list[20]; - int i; - printf("Enter the size of the list: "); - scanf("%d", &size); - printf("Printing the list: - "); - for (i = 0; i < size; i++) - { - list[i] = rand() % size; - printf("%d ", list[i]); - } - printf(" - Enter the key to find it's occurence: "); - scanf("%d", &key); - occur(list, size, 0, key, &count); - printf("%d occurs for %d times. - ", key, count); - return 0; -} - - void occur(int list[], int size, int index, int key, int *count) -{ - if (size == index) - { - return; - } - if (list[index] == key) - { - *count += 1; - } - occur(list, size, index + 1, key, count); -} - - -Enter the size of the list: 7 -Printing the list: -1 4 2 5 1 3 3 -Enter the key to find it's occurence: 3 -3 occurs for 2 times. diff --git a/c/_Basic/C program to print hello world without using semicolon.c b/c/_Basic/C program to print hello world without using semicolon.c deleted file mode 100644 index 3f92150..0000000 --- a/c/_Basic/C program to print hello world without using semicolon.c +++ /dev/null @@ -1,5 +0,0 @@ - #include - void main(){ - if(printf("Hello world")){ - } - } \ No newline at end of file diff --git a/c/_Basic/C program to read an English sentence and replace lowercase characters by uppercase and vice-versa..c b/c/_Basic/C program to read an English sentence and replace lowercase characters by uppercase and vice-versa..c deleted file mode 100644 index 93d82ae..0000000 --- a/c/_Basic/C program to read an English sentence and replace lowercase characters by uppercase and vice-versa..c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * C program to read an English sentence and replace - * lowercase characters by uppercase and vice-versa. - * Output the given sentence as well as the converted - * sentence on two different lines. - */ -#include -#include - -void main() -{ - char sentence[100]; - int count, ch, i; - printf("Enter a sentence - "); - for (i = 0; (sentence[i] = getchar()) != ' - '; i++) - { - ; - } - sentence[i] = ''; - /* shows the number of chars accepted in a sentence */ - count = i; - printf("The given sentence is : %s", sentence); - printf(" - Case changed sentence is: "); - for (i = 0; i < count; i++) - { - ch = islower(sentence[i])? toupper(sentence[i]) : - tolower(sentence[i]); - putchar(ch); - } -} - - -Enter a sentence -gETTING iLLUMIN8ED -The given sentence is : -gETTING iLLUMIN8ED -Case changed sentence is: -GETTING ILLUMIN8ED \ No newline at end of file diff --git a/c/_Basic/C program to sort n given numbers using pointers.c b/c/_Basic/C program to sort n given numbers using pointers.c deleted file mode 100644 index 3f70e14..0000000 --- a/c/_Basic/C program to sort n given numbers using pointers.c +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include -void main() -{ - int n,*p,i,j,temp; - clrscr(); - printf("\nHOW MANY NUMBER: "); - scanf("%d",&n); - p=(int *) malloc(n*2); - if(p==NULL) - { - printf("\nMEMORY ALLOCATION UNSUCCESSFUL"); - exit(); - } - for(i=0;i - #include - #include - int main(int argc, char** argv) { - char** new_argv; - int i; - /* Since argv[0] through argv[argc] are all valid, the - program needs to allocate room for argc+1 pointers. */ - new_argv = (char**) calloc(argc+1, sizeof (char*)); - /* or malloc((argc+1) * sizeof (char*)) */ - printf("allocated room for %d pointers starting at %P\n", argc+1, new_argv); - /* now copy all the strings themselves - (argv[0] through argv[argc-1]) */ - for (i = 0; i < argc; ++i) { - /* make room for '' at end, too */ - new_argv[i] = (char*) malloc(strlen(argv[i]) + 1); - strcpy(new_argv[i], argv[i]); - printf(" - allocated %d bytes for new_argv[%d] at %P, " - " - copied \" - %s\" - \n" - , - strlen(argv[i]) + 1, i, new_argv[i], new_argv[i]); - } - new_argv[argc] = NULL; - /* To deallocate everything, get rid of the strings (in any - order), then the array of pointers. If you free the array - of pointers first, you lose all reference to the copied - strings. */ - for (i = 0; i < argc; ++i) { - free(new_argv[i]); - printf(" - freed new_argv[%d] at %P\n" - , i, new_argv[i]); - argv[i] = NULL; - } - free(new_argv); - printf(" - freed new_argv itself at %P\n" - , new_argv); - return 0; - } \ No newline at end of file diff --git a/c/_Basic/Create and Use Your Own Header File in C Programming.c b/c/_Basic/Create and Use Your Own Header File in C Programming.c deleted file mode 100644 index 0584bd9..0000000 --- a/c/_Basic/Create and Use Your Own Header File in C Programming.c +++ /dev/null @@ -1,8 +0,0 @@ - #include - #include "myfirstheader.h" - - void main() { - int num1 = 10, num2 = 10, num3; - num3 = add(num1, num2); - printf("Addition of Two numbers : %d", num3); - } \ No newline at end of file diff --git a/c/_Basic/Get Address of an array using Arrays and Pointers.c b/c/_Basic/Get Address of an array using Arrays and Pointers.c deleted file mode 100644 index d7ad924..0000000 --- a/c/_Basic/Get Address of an array using Arrays and Pointers.c +++ /dev/null @@ -1,14 +0,0 @@ - #include - - int main(void) - { - char multiple[] = "My string"; - - char *p = &multiple[0]; - printf("\nThe address of the first array element : %p", p); - - p = multiple; - printf("\nThe address obtained from the array name: %p\n", p); - - return 0; - } \ No newline at end of file diff --git a/c/_Basic/Print mark-sheet of students.c b/c/_Basic/Print mark-sheet of students.c deleted file mode 100644 index 920ab9b..0000000 --- a/c/_Basic/Print mark-sheet of students.c +++ /dev/null @@ -1,43 +0,0 @@ - #include - #include - #include - #include - void main() { - /*variable declaration part */ - int rl,s1,s2,s3,t; - float per; - char nm[25],div[10]; - clrscr(); - /*reading part */ - printf("Enter the Roll No : "); - scanf("%d",&rl); - printf("Enter Name : "); - fflush(stdin); - gets(nm); - printf("Enter Three Subject Marks :\n"); - scanf("%d%d%d",&s1,&s2,&s3); - /* processing part */ - t=s1+s2+s3; - per=t/3.0; - if(per>=75) - strcpy(div,"Honour"); else if( per>=60) - strcpy(div,"First"); else if( per>=48) - strcpy(div,"Second"); else if (per>=36) - strcpy(div,"Pass"); else - strcpy(div,"Fail"); - /* display part */ - printf("\t\tUniversity of Rajasthan\n"); - printf("\n\n"); - printf("Roll No: %d \t Name : %s\n",rl,nm); - printf("---------------------------------------------------\n"); - printf("Subject Max Min Obt.Marks\n"); - printf("---------------------------------------------------\n"); - printf("Hist 100 36 %d\n",s1); - printf("socio. 100 36 %d\n",s2); - printf("Hindi 100 36 %d\n",s3); - printf("---------------------------------------------------\n"); - printf(" Total %d\n",t); - printf("per %f\t\t\t div: %s \n",per,div); - printf("---------------------------------------------------\n"); - getch(); - } \ No newline at end of file diff --git a/c/_Basic/Reverse a string using pointers.c b/c/_Basic/Reverse a string using pointers.c deleted file mode 100644 index 993008d..0000000 --- a/c/_Basic/Reverse a string using pointers.c +++ /dev/null @@ -1,15 +0,0 @@ - #include - #include - void main() - { - char *s; - int len,i; - clrscr(); - printf("\nENTER A STRING: "); - gets(s); - len=strlen(s); - printf("\nTHE REVERSE OF THE STRING IS:"); - for(i=len;i>=0;i--) - printf("%c",*(s+i)); - getch(); - } \ No newline at end of file diff --git a/c/_Basic/Reverse the order of each word of the string using pointers.c b/c/_Basic/Reverse the order of each word of the string using pointers.c deleted file mode 100644 index 3d59fc9..0000000 --- a/c/_Basic/Reverse the order of each word of the string using pointers.c +++ /dev/null @@ -1,28 +0,0 @@ - #include - #include - void main() - { - char *s; - int len,i,j,sp=0,start,end; - clrscr(); - printf("\nENTER A STRING: "); - gets(s); - printf("\nTHE STRING AFTER CHANGING THE ORDER OF EACH WORD:\n"); - len=strlen(s); - end=len-1; - for(i=len-1;i>=0;i--) - { - if(s[i]==32 || i==0) - { - if(i==0) - start=0; - else - start=i+1; - for(j=start;j<=end;j++) - printf("%c",s[j]); - end=i-1; - printf(" "); - } - } - getch(); - } \ No newline at end of file diff --git a/c/_Basic/Show the ticking of Clock.c b/c/_Basic/Show the ticking of Clock.c deleted file mode 100644 index 41ed0ae..0000000 --- a/c/_Basic/Show the ticking of Clock.c +++ /dev/null @@ -1,104 +0,0 @@ - #include - #include - #include - #include - #include - // Calculates new co-ordinates of a figure after - // rotating it at an angle about a point (cx,cy) - void rotate( int figure[], int edges, double angle, int cx, int cy ) { - double x, y; - angle = -1 * (angle*3.14/180); - double cos_a = cos(angle); - double sin_a = sin(angle); - for (int i=0; i < edges; i++) { - x = figure[2*i] - cx; - y = figure[2*i+1] - cy; - figure[2*i] = floor( (x * cos_a) - (y * sin_a) + cx + 0.5 ); - figure[2*i+1] = floor( (x * sin_a)+(y * cos_a) + cy + 0.5 ); - } - } - void drawClock(int,int,int); - void main() { - int second_hand[4],minute_hand[4], hour_hand[4], edges = 2 ; - double angle; - int cx=300, cy=200; - int gd = DETECT, gm; - initgraph( &gd, &gm, "" ); - int max_y = getmaxy(); - clrscr(); - cleardevice(); - angle = -6; - // Set the initial position of the second, minute and the hour hands. - second_hand[0] = cx ; - second_hand[1] = max_y - cy; - second_hand[2] = cx; - second_hand[3] = max_y - 320; - hour_hand[0] = cx; - hour_hand[1] = max_y - cy; - hour_hand[2] = cx + 90; - hour_hand[3] = max_y - 200; - minute_hand[0] = cx; - minute_hand[1] = max_y - cy; - minute_hand[2] = cx; - minute_hand[3] = max_y - 310; - cleardevice(); - setbkcolor(WHITE); - // Draw the clock - drawClock(cx,max_y - cy,150); - setlinestyle(SOLID_FILL,0,1); - // Draw the minute and the hour hand - drawpoly(2,minute_hand); - drawpoly(2,hour_hand); - int i=0; - while(!kbhit()) { - setcolor(RED); - drawpoly(2,second_hand); - setcolor(GREEN); - drawpoly(2,minute_hand); - setcolor(BLUE); - drawpoly(2,hour_hand); - delay(1000); - // set delay(10) to tick the clock fast - setcolor(15); - drawpoly(2,second_hand); - rotate(second_hand,edges,angle,cx,max_y - cy); - i++; - // Reset the second hand and move the minute hand - // when the second hand has moved 60 times. - if(i%60 == 0) { - second_hand[0] = cx ; - second_hand[1] = max_y - cy; - second_hand[2] = cx; - second_hand[3] = max_y - 320; - drawpoly(2,minute_hand); - rotate(minute_hand,edges,angle,cx,max_y - cy); - } - // Move the minute hand - // when the second hand has moved 720 (60*12) times. - if(i%720 == 0) { - i = 0; - drawpoly(2,hour_hand); - rotate(hour_hand,edges,angle,cx,max_y - cy); - } - } - getch(); - } - // Function to draw the clock - void drawClock(int cx, int cy, int r) { - setcolor(GREEN); - setlinestyle(SOLID_FILL,0,3); - circle(cx,cy,r); - int max_y = getmaxy(); - int center[2] = { - cx, max_y - 340 - } - ; - for (int i=0; i<60; i++) { - if(i%5 == 0) { - circle(center[0],center[1],2); - } else { - circle(center[0],center[1],1); - } - rotate(center,1,-6,cx,cy); - } - } \ No newline at end of file diff --git a/c/_Basic/Time functions in c.c b/c/_Basic/Time functions in c.c deleted file mode 100644 index 1e22ad8..0000000 --- a/c/_Basic/Time functions in c.c +++ /dev/null @@ -1,36 +0,0 @@ - #include - #include - #include - void main() - { - time_t now; - clrscr(); - now = time((time_t *)NULL); - - printf("%s", ctime(&now)); - - time(&now); - - printf("%s", ctime(&now)); - { - struct tm *l_time; - - l_time = localtime(&now); - printf("%s", asctime(l_time)); - } - - time(&now); - printf("%s", asctime(localtime( &now ))); - { - - struct tm *l_time; - char string[20]; - - time(&now); - l_time = localtime(&now); - strftime(string, sizeof string, "%d-%b-%y\n", l_time); - printf("%s", string); - } - - getch(); - } \ No newline at end of file diff --git a/c/_Basic/To compute the average of n given numbers using pointers.c b/c/_Basic/To compute the average of n given numbers using pointers.c deleted file mode 100644 index d277e16..0000000 --- a/c/_Basic/To compute the average of n given numbers using pointers.c +++ /dev/null @@ -1,26 +0,0 @@ - #include - #include - void main() - { - int n,*p,sum=0,i; - float avg; - clrscr(); - printf("\nHOW MANY NUMBERS: "); - scanf("%d",&n); - p=(int *) malloc(n*2); - if(p==NULL) - { - printf("\nMEMORY ALLOCATION UNSUCCCESSFUL"); - exit(); - } - for(i=0;i - #include - void main() - { - long unsigned age,sec; - clrscr(); - printf("\nENTER YOUR AGE: "); - scanf("%lu",&age); - sec=age*365*24*60*60; - printf("\nAGE IN SECONDS: %lu",sec); - getch(); - } \ No newline at end of file diff --git a/c/_Basic/To find the maximum number within n given numbers using pointers.c b/c/_Basic/To find the maximum number within n given numbers using pointers.c deleted file mode 100644 index 821f02f..0000000 --- a/c/_Basic/To find the maximum number within n given numbers using pointers.c +++ /dev/null @@ -1,28 +0,0 @@ - #include - #include - void main() - { - int n,*p,i,h=0; - clrscr(); - printf("\nHOW MANY NUMBERS: "); - scanf("%d",&n); - p=(int *) malloc(n*2); - if(p==NULL) - { - printf("\nMEMORY ALLOCATION UNSUCCCESSFUL"); - exit(); - } - for(i=0;ih) - h=*(p+i); - } - printf("\nTHE HIGHEST NUMBER IS %d",h); - getch(); - } \ No newline at end of file diff --git a/c/_Basic/To swap the address of two variables using pointer.c b/c/_Basic/To swap the address of two variables using pointer.c deleted file mode 100644 index 4c99b7b..0000000 --- a/c/_Basic/To swap the address of two variables using pointer.c +++ /dev/null @@ -1,20 +0,0 @@ - #include - #include - void swap(int *,int *); - void main() - { - int a=10,b=20; - clrscr(); - printf("\nVALUES OF a AND b BEFORE SWAPING ARE %d %d",a,b); - swap(&a,&b); - printf("\nVALUES OF a AND b AFTER SWAPING ARE %d %d",a,b); - getch(); - } - void swap(x,y) - int *x,*y; - { - int t; - t=*x; - *x=*y; - *y=t; - } \ No newline at end of file diff --git a/c/_Basic/What happens if you free a pointer twice.c b/c/_Basic/What happens if you free a pointer twice.c deleted file mode 100644 index 0e28b67..0000000 --- a/c/_Basic/What happens if you free a pointer twice.c +++ /dev/null @@ -1,21 +0,0 @@ - #include - #include - int main(int argc, char** argv) { - char** new_argv1; - char** new_argv2; - new_argv1 = calloc(argc+1, sizeof(char*)); - free(new_argv1); - /* freed once */ - new_argv2 = (char**) calloc(argc+1, sizeof(char*)); - if (new_argv1 == new_argv2) { - /* new_argv1 accidentally points to freeable memory */ - free(new_argv1); - /* freed twice */ - } else { - free(new_argv2); - } - new_argv1 = calloc(argc+1, sizeof(char*)); - free(new_argv1); - /* freed once again */ - return 0; - } \ No newline at end of file diff --git a/c/_Basic/Write a c program to check given string is palindrome number or not.c b/c/_Basic/Write a c program to check given string is palindrome number or not.c deleted file mode 100644 index 2fdf3ef..0000000 --- a/c/_Basic/Write a c program to check given string is palindrome number or not.c +++ /dev/null @@ -1,18 +0,0 @@ - #include - #include - void main() { - char *a; - int i,len,flag=0; - clrscr(); - printf("\nENTER A STRING: "); - gets(a); - len=strlen(a); - for (i=0;i - struct circ_list { - char value[ 3 ]; - /* e.g., "st" (incl '') */ - struct circ_list *next; - } - ; - struct circ_list suffixes[] = { - "th", & suffixes[ 1 ], - /* 0th */ - "st", & suffixes[ 2 ], - /* 1st */ - "nd", & suffixes[ 3 ], - /* 2nd */ - "rd", & suffixes[ 4 ], - /* 3rd */ - "th", & suffixes[ 5 ], - /* 4th */ - "th", & suffixes[ 6 ], - /* 5th */ - "th", & suffixes[ 7 ], - /* 6th */ - "th", & suffixes[ 8 ], - /* 7th */ - "th", & suffixes[ 9 ], - /* 8th */ - "th", & suffixes[ 0 ], - /* 9th */ - } - ; - #define MAX 20 - int main() { - int i = 0; - struct circ_list *p = suffixes; - while (i value ); - ++i; - p = p->next; - } - return 0; - } \ No newline at end of file diff --git a/c/_Basic/null pointer in c.c b/c/_Basic/null pointer in c.c deleted file mode 100644 index fee473f..0000000 --- a/c/_Basic/null pointer in c.c +++ /dev/null @@ -1,15 +0,0 @@ - /* A simple program that prints all its arguments. - It doesn't use argc ("argument count"); instead, - it takes advantage of the fact that the last value - in argv ("argument vector") is a null pointer. */ - #include - #include - int - main( int argc, char **argv) { - int i; - printf("program name = \"%s\"\n", argv[0]); - for (i=1; argv[i] != NULL; ++i) - printf("argv[%d] = \"%s\"\n", i, argv[i]); - assert(i == argc); - return 0; - } \ No newline at end of file diff --git a/perl/_Basics/!$v1 && $v2.pl b/perl/_Basics/!$v1 && $v2.pl deleted file mode 100644 index 57ea67a..0000000 --- a/perl/_Basics/!$v1 && $v2.pl +++ /dev/null @@ -1,13 +0,0 @@ - - -$v1 = 1; -$v2 = 0; -$v3 = ! $v1 &&$v2; -if($v3) { - print "\$v3 is true."; -} -else { - print "\$v3 is false."; -} - - \ No newline at end of file diff --git a/perl/_Basics/A program that uses the pre-increment operation..pl b/perl/_Basics/A program that uses the pre-increment operation..pl deleted file mode 100644 index 943c118..0000000 --- a/perl/_Basics/A program that uses the pre-increment operation..pl +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/local/bin/perl -$value = 0; -while (++$value <= 5) { - print("value is now$value\n"); -} -print("all done\n"); - - \ No newline at end of file diff --git a/perl/_Basics/Adding a number and a string.pl b/perl/_Basics/Adding a number and a string.pl deleted file mode 100644 index f2b5f58..0000000 --- a/perl/_Basics/Adding a number and a string.pl +++ /dev/null @@ -1,8 +0,0 @@ -$string = "Top 10"; -$number = 10.0; -print "Number is 10.0 and string is 'Top 10'\n\n"; - -$add =$number + $string; -print "Adding a number and a string:$add\n"; - - \ No newline at end of file diff --git a/perl/_Basics/After incrementing.pl b/perl/_Basics/After incrementing.pl deleted file mode 100644 index cc8050a..0000000 --- a/perl/_Basics/After incrementing.pl +++ /dev/null @@ -1,8 +0,0 @@ - -#!/usr/bin/perl -w - -$a = 4; -$b = 10; -print "Our variables are ", $a, " and ",$b, "\n"; -$b =$a++; -print "After incrementing, we have ", $a, " and ",$b, "\n"; diff --git a/perl/_Basics/After pre-decrement.pl b/perl/_Basics/After pre-decrement.pl deleted file mode 100644 index a7b6a6a..0000000 --- a/perl/_Basics/After pre-decrement.pl +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/perl -w - -$a = 4; -$b = 10; -print "Our variables are ", $a, " and ",$b, "\n"; - -$a = --$b + 4; -print "Finally, we have ", $a, " and ",$b, "\n"; \ No newline at end of file diff --git a/perl/_Basics/Arithmetic Operators in action.pl b/perl/_Basics/Arithmetic Operators in action.pl deleted file mode 100644 index bb356ee..0000000 --- a/perl/_Basics/Arithmetic Operators in action.pl +++ /dev/null @@ -1,7 +0,0 @@ - - -printf "%d\n", 4 * 5 / 2; -printf "%d\n", 5 ** 3; -printf "%d\n", 5 + 4 - 2 * 10; -printf "%d\n", (5 + 4 - 2 ) * 10; -printf "%d\n", 11 % 2; diff --git a/perl/_Basics/Assign value to four variables.pl b/perl/_Basics/Assign value to four variables.pl deleted file mode 100644 index 2039426..0000000 --- a/perl/_Basics/Assign value to four variables.pl +++ /dev/null @@ -1,10 +0,0 @@ -#!C:\perl\bin - -$age =$myage = $herage =$hisage = 25; - -print "\$age =$age\n\n"; -print "\$myage =$myage\n\n"; -print "\$herage =$herage\n\n"; -print "\$hisage =$hisage\n\n"; - - \ No newline at end of file diff --git a/perl/_Basics/Assignment Operators.pl b/perl/_Basics/Assignment Operators.pl deleted file mode 100644 index 1cb7319..0000000 --- a/perl/_Basics/Assignment Operators.pl +++ /dev/null @@ -1,15 +0,0 @@ -Operator Example Meaning -= $var = 5; Assign 5 to$var -+= $var += 3; Add --=$var -= 2; Subtract -.= $str.="ing"; Concatenate ing to$str -*= $var *= 2; Multiply$var by 2 -/= $var /= 2; Divide$var by 2 -**= $var **= 2; Square$var -%= $var %= 2; Divide$var by 2 -x= $str x= 2; Repeat value of$str 2 times -<<= $var <<= 1; Left-shift bits in$var one position ->>= $var>>= 2; Right-shift bits in$var two positions -&= $var &= 1; One is bitwise-ANDed to$var -|= $var |= 2; Two is bitwise-ORed to$var -^= $var ^= 2; Two is bitwise-exclusive ORed to$var \ No newline at end of file diff --git a/perl/_Basics/Assignment Statements.pl b/perl/_Basics/Assignment Statements.pl deleted file mode 100644 index 0aa5501..0000000 --- a/perl/_Basics/Assignment Statements.pl +++ /dev/null @@ -1,14 +0,0 @@ - -variable=expression; - - -$salary=50000; # Scalar assignment -@months=('Mar', 'Apr', 'May'); # Array assignment -%states= ( # Hash assignment - 'CA' => 'California', - 'NM' => 'New Mexico', - ); - - - - \ No newline at end of file diff --git a/perl/_Basics/Autoincrement and Autodecrement Operators and Assignment.pl b/perl/_Basics/Autoincrement and Autodecrement Operators and Assignment.pl deleted file mode 100644 index c6662d9..0000000 --- a/perl/_Basics/Autoincrement and Autodecrement Operators and Assignment.pl +++ /dev/null @@ -1,15 +0,0 @@ - -#!/usr/bin/perl -$x=5; $y=0; -$y=++$x; # Add 1 to$x first; then assign to $y -print "Pre-increment:\n"; -print "y is$y\n"; -print "x is $x\n"; - - -$x=5; -$y=0; -print "Post-increment:\n"; -$y=$x++; # Assign value in$x to $y; then add 1 to$x -print "y is $y\n"; -print "x is$x\n"; diff --git a/perl/_Basics/Basic Math Compound Assignment Statements.pl b/perl/_Basics/Basic Math Compound Assignment Statements.pl deleted file mode 100644 index 843f8f0..0000000 --- a/perl/_Basics/Basic Math Compound Assignment Statements.pl +++ /dev/null @@ -1,24 +0,0 @@ - -#! /usr/local/bin/perl -$a = 5; -print "\$a equals $a before the operation.\n "; - -$a += 4.2; -print "The result of \$a += 4.2 is$a \n"; -print "\$a equals$a before the operation.\n "; - -$a -= 4.2; -print "The result of \$a -= 4.2 is $a \n"; -print "\$a equals $a before the operation.\n "; - -$a *= 4.2; -print "The result of \$a *= 4.2 is$a \n"; -print "\$a equals$a before the operation.\n "; - -$a /= 6; - -print "The result of \$a /= 6 is $a \n"; -print "\$a equals $a before the operation.\n "; - -$a %= 6; -print "The result of \$a %= 6 is$a \n"; diff --git a/perl/_Basics/Basic Numeric Operations.pl b/perl/_Basics/Basic Numeric Operations.pl deleted file mode 100644 index 554578c..0000000 --- a/perl/_Basics/Basic Numeric Operations.pl +++ /dev/null @@ -1,17 +0,0 @@ -#! /usr/local/bin/perl - -$a = 4.2 + 3; -print "The result of 4.2 + 3 is$a \n"; - -$a = 4.2 - 3; -print "The result of 4.2 - 3 is$a \n"; - -$a = 4.2 * 3; -print "The result of 4.2 * 3 is$a \n"; - -$a = 26 / 8; -print "The result of 26 / 8 is$a \n"; - -$a = 26 % 8; - -print "The result of 26 % 8 is$a \n"; diff --git a/perl/_Basics/Bitwise And Operators in action.pl b/perl/_Basics/Bitwise And Operators in action.pl deleted file mode 100644 index d4e77fa..0000000 --- a/perl/_Basics/Bitwise And Operators in action.pl +++ /dev/null @@ -1,7 +0,0 @@ - - -print 5 & 4,"\n"; # 101 & 100 -print 5 & 0,"\n"; # 101 & 000 -print 4 & 0,"\n"; # 100 & 000 -print 0 & 4,"\n"; # 000 & 100 -print "=" x 10,"\n"; # print 10 equal signs \ No newline at end of file diff --git a/perl/_Basics/Bitwise Logical Operators.pl b/perl/_Basics/Bitwise Logical Operators.pl deleted file mode 100644 index e3c409e..0000000 --- a/perl/_Basics/Bitwise Logical Operators.pl +++ /dev/null @@ -1,7 +0,0 @@ - -Operator Example Meaning -& $x &$y Bitwise and -| $x |$y Bitwise or -^ $x ^$y Bitwise exclusive or -<< $x << 1 Bitwise left shift, integer multiply by two ->>$x >> 1 Bitwise right shift, integer divide by two \ No newline at end of file diff --git a/perl/_Basics/Bitwise Or Operators in action.pl b/perl/_Basics/Bitwise Or Operators in action.pl deleted file mode 100644 index 8adfce0..0000000 --- a/perl/_Basics/Bitwise Or Operators in action.pl +++ /dev/null @@ -1,7 +0,0 @@ - -print 1 | 4,"\n"; # 001 & 100 -print 5 | 0,"\n"; # 101 | 000 -print 4 | 0,"\n"; # 100 | 000 -print 0 | 4,"\n"; # 000 | 100 - -print "=" x 10,"\n"; # print 10 equal signs diff --git a/perl/_Basics/Bitwise operator.pl b/perl/_Basics/Bitwise operator.pl deleted file mode 100644 index 7f315d3..0000000 --- a/perl/_Basics/Bitwise operator.pl +++ /dev/null @@ -1,17 +0,0 @@ - -#!/usr/bin/perl - -use warnings; -use strict; - -my $a = 3; -my$b = 6; -my $r; - -printf "$a = %03b \n", $a; -printf "$b = %03b \n", $b; - -$r = $a &$b; printf "$a &$b = %03b = %d\n", $r,$r; -$r =$a | $b; printf "$a | $b = %03b = %d\n",$r, $r; -$r = $a ^$b; printf "$a ^$b = %03b = %d\n", $r,$r; -$r = ~$a; printf "~$a = %03b = %d\n",$r, $r; diff --git a/perl/_Basics/Boolean and &&.pl b/perl/_Basics/Boolean and &&.pl deleted file mode 100644 index 6d5fcea..0000000 --- a/perl/_Basics/Boolean and &&.pl +++ /dev/null @@ -1,11 +0,0 @@ - - -print "Please enter positive numbers up to 100\n"; -while (<>) { - chomp; - if ($_ > 0 && $_ < 100) { - print "Thank you - let's have another!\n"; - } else { - print "Please enter positive numbers up to 100\n"; - } -} diff --git a/perl/_Basics/Boolean operator.pl b/perl/_Basics/Boolean operator.pl deleted file mode 100644 index b023e87..0000000 --- a/perl/_Basics/Boolean operator.pl +++ /dev/null @@ -1,15 +0,0 @@ - -print "Please enter numbers from 5 to 10\n"; - -while (<>) { - chop; - if ($_ < 5 || $_ > 10) { - print "Please enter numbers from 5 to 10\n"; - } else { - print "Thank you - let's have another!\n"; - } -} - - - - \ No newline at end of file diff --git a/perl/_Basics/Built-in Perl Arithmetic Functions.pl b/perl/_Basics/Built-in Perl Arithmetic Functions.pl deleted file mode 100644 index 70b215b..0000000 --- a/perl/_Basics/Built-in Perl Arithmetic Functions.pl +++ /dev/null @@ -1,27 +0,0 @@ -atan2(Y,X) Returns the arctangent of Y/X. - -cos(EXPR) -cos EXPR Returns the cosine of EXPR in radians. If EXPR is omitted, takes cosine of$_. - -exp(EXPR) -exp EXPR Returns e to the power of EXPR. If EXPR is omitted, gives exp($_). - -int(EXPR) -int EXPR Returns the integer portion of EXPR. If EXPR is omitted, uses$_. - -log(EXPR) -log EXPR Returns logarithm (base e) of EXPR. If EXPR is omitted, returns log of $_. - -rand(EXPR) -rand EXPR -rand Returns a random fractional number between 0 and the value of EXPR. - If EXPR is omitted, returns a value between 0 and 1. - -sin(EXPR) -sin EXPR Returns the sine of EXPR in radians. If EXPR is omitted, returns sine of$_. - -sqrt(EXPR) -sqrt EXPR Return the square root of EXPR. If EXPR is omitted, returns square root of $_. - -srand(EXPR) -srand EXPR Sets the random number seed for the rand operator. If EXPR is omitted, does srand(time). \ No newline at end of file diff --git a/perl/_Basics/Complex Assignment.pl b/perl/_Basics/Complex Assignment.pl deleted file mode 100644 index d9754e4..0000000 --- a/perl/_Basics/Complex Assignment.pl +++ /dev/null @@ -1,16 +0,0 @@ - - -$degrees = 2; - -($degrees += 100) *= 700; - -print$degrees; - - -$degrees = 2; - -$degrees += 100; -$degrees *= 700; - - -print$degrees; diff --git a/perl/_Basics/Compound Assignment Operators.pl b/perl/_Basics/Compound Assignment Operators.pl deleted file mode 100644 index fee63ba..0000000 --- a/perl/_Basics/Compound Assignment Operators.pl +++ /dev/null @@ -1,31 +0,0 @@ -Operator Example Meaning - -+= $a += 3; Add - --=$a -= 3; Subtract - -*= $a *= 3; Multiply - -/=$a /= 3; Divide - -**= $a **= 3; Raise the power - -%=$a %= 3; Modulo - -.= $a .= "String Value"; Append - -x=$a x= 3; Multiply (replicate) the expression (string) - -&= $a &= 3; Binary AND - -|=$a |= 3; Binary OR - -^= $a ^= 3; Exclusive OR - -<<=$a <<= 3; Left shift - ->>= $a >>= 3; Right shift - -&&=$a &&= 1; Logical AND - -||= $a ||= 0; Logical OR \ No newline at end of file diff --git a/perl/_Basics/Compound operator.pl b/perl/_Basics/Compound operator.pl deleted file mode 100644 index 58d769d..0000000 --- a/perl/_Basics/Compound operator.pl +++ /dev/null @@ -1,13 +0,0 @@ - -#!/usr/bin/perl -w - -$a = 6 * 9; -print "Six nines are ", $a, "\n"; -$a += 3; -print "Plus three is ", $a, "\n"; -$a /= 3; -print "All over three is ", $a, "\n"; -$a += 1; -print "Add one is ", $a, "\n"; - - \ No newline at end of file diff --git a/perl/_Basics/Demonstrates the difference between pre- and postincrement.pl b/perl/_Basics/Demonstrates the difference between pre- and postincrement.pl deleted file mode 100644 index ccf6678..0000000 --- a/perl/_Basics/Demonstrates the difference between pre- and postincrement.pl +++ /dev/null @@ -1,11 +0,0 @@ - -$c = 5; -$d = 5; - -print$c, " "; -print $c++, " "; -print$c, "\n"; - -print $d, " "; -print ++$d, " "; -print $d, "\n"; diff --git a/perl/_Basics/Getting Input in Perl Scripts.pl b/perl/_Basics/Getting Input in Perl Scripts.pl deleted file mode 100644 index c20cd9f..0000000 --- a/perl/_Basics/Getting Input in Perl Scripts.pl +++ /dev/null @@ -1,14 +0,0 @@ -# Note the extra space after the question mark. -print "What is your favorite scripting language? "; - -$subLang = ; - -chomp($subLang); - -if ($subLang eq "perl" ) { - print "you chose perl!\n"; -} else { - print "$subLang "; -} - - \ No newline at end of file diff --git a/perl/_Basics/Increment and Decrement Operations.pl b/perl/_Basics/Increment and Decrement Operations.pl deleted file mode 100644 index 26d163e..0000000 --- a/perl/_Basics/Increment and Decrement Operations.pl +++ /dev/null @@ -1,14 +0,0 @@ -#! /usr/local/bin/perl -$a=15; -$b = ++$a -15; -$c =$a++ - 15; - -print "The increment operation occurs first on the left side\n"; -print "$b = ++$a - 15 results in $b equal "; -print "$b\n"; -print "The increment operation occurs after other operations when on the right side\n"; -print "$c =$a- - 15 results in $c equal "; -print "$c\n"; - - - \ No newline at end of file diff --git a/perl/_Basics/Logical Word Operators.pl b/perl/_Basics/Logical Word Operators.pl deleted file mode 100644 index bc1edcb..0000000 --- a/perl/_Basics/Logical Word Operators.pl +++ /dev/null @@ -1,11 +0,0 @@ -$num1=50; -$num2=100; -$num3=0; -print "\nOutput using the word operators.\n\n"; -print "\n$num1 and $num2: ",($num1 and $num2), "\n"; -print "\n$num1 or $num3: ", ($num1 or $num3), "\n"; -print "\n$num1 xor $num3: ",($num1 xor $num3), "\n"; -print "\nnot$num3: ", not $num3; -print "\n"; - - \ No newline at end of file diff --git a/perl/_Basics/Logical operators are defined.pl b/perl/_Basics/Logical operators are defined.pl deleted file mode 100644 index a7429f2..0000000 --- a/perl/_Basics/Logical operators are defined.pl +++ /dev/null @@ -1,12 +0,0 @@ - - -$a || $b # logical or: true if either is nonzero -$a && $b # logical and: true only if both are nonzero -!$a # logical not: true if $a is zero -Perl 5 also defines these logical operators: -$a or $b # another form of logical or -$a and $b # another form of logical and -not$a # another form of logical not -$a xor$b # logical xor: true if either $a or$b is nonzero, but not both - - \ No newline at end of file diff --git a/perl/_Basics/OPERATOR PURPOSENumeric operators.pl b/perl/_Basics/OPERATOR PURPOSENumeric operators.pl deleted file mode 100644 index 29bb536..0000000 --- a/perl/_Basics/OPERATOR PURPOSENumeric operators.pl +++ /dev/null @@ -1,51 +0,0 @@ -OPERATOR PURPOSE - -+ Computes the additive value of the two operands. - - Computes the difference between the two operands. - -* Computes the multiplication of the two operands. - -/ Computes the division between the two operands. - -% Computes the modulus (remainder) of the two operands. - -== Returns True if the two operands are equal, False otherwise. - -!= Returns True if the two operands are not equal, False otherwise. - ->= Greater than. - -<= Less than. - -> - -<=> Returns -1 if the left operand is less than the right, +1 if is it greater than, and 0 (False) otherwise. - -&& a logical AND operation. - -|| a logical OR operation. - -& Returns the value of the two operators bitwise ANDed. - -| Returns the value of the two operators bitwise ORed. - -~ Returns the value of the two operators bitwise XORed. - -++ Increment operator. Increments the variable's value by 1. - --- Decrement operator. Decrements the variable's value by 1. - -xx Computes the power of the left value to the power of the right value. - -+= Adds the value of the right operand to the value of the left operand. - --= Subtracts the value of the right operand from the value of the left operand. - -x= Multiplies the value of the left operand with the value of the right operand. - ->> Shifts the left operand right by the number of bits specified by the right operand. - -<< Shifts the left operand left by the number of bits specified by the right operand. - -~ Performs a 1s complement of the operator. This is a unary operator. \ No newline at end of file diff --git a/perl/_Basics/Operating and Assigning at Once.pl b/perl/_Basics/Operating and Assigning at Once.pl deleted file mode 100644 index c9f507b..0000000 --- a/perl/_Basics/Operating and Assigning at Once.pl +++ /dev/null @@ -1,14 +0,0 @@ - -#!/usr/bin/perl - -use warnings; -$a = 6 * 9; -print "Six nines are ",$a, "\n"; -$a += 3; -print "Plus three is ",$a, "\n"; -$a /= 3; -print "All over three is ",$a, "\n"; -$a += 1; -print "Add one is ",$a, "\n"; - - \ No newline at end of file diff --git a/perl/_Basics/Post-increment operation..pl b/perl/_Basics/Post-increment operation..pl deleted file mode 100644 index 43ce2c7..0000000 --- a/perl/_Basics/Post-increment operation..pl +++ /dev/null @@ -1,7 +0,0 @@ - -#!/usr/local/bin/perl -$value = 0; -while ($value++ <= 5) { - print("value is now $value\n"); -} -print("all done\n"); diff --git a/perl/_Basics/Precedence and Associativity.pl b/perl/_Basics/Precedence and Associativity.pl deleted file mode 100644 index 9a1f271..0000000 --- a/perl/_Basics/Precedence and Associativity.pl +++ /dev/null @@ -1,22 +0,0 @@ -Operator Description Associativity -() [ ] { } Function call, array subscripts Left to right -** Exponentiation Right to left -! ~ \ + - Logical not, bitwise not, backslash, plus,minus Right to left -=~ !~ Match and not match Left to right -* / % x Multiply, divide, modulus, string repetition Left to right -+ -. Add, subtract, string concatenation Left to right -<< >> Bitwise left shift, right shift Left to right --r -w -x -o etc. File test operators None -< <= > >= lt le gt ge Numeric and string: less than, greater than, etc. None -== != <=> eq ne cmp Numeric and string: equal to, not equal to, etc. None -& Bitwise and Left to right -| ^ Bitwise or, exclusive or (xor) Left to right -&& Logical and Left to right -|| Logical or Left to right -.. Range operator None -? : Ternary, conditional Right to left -= += -= *= /= %= Assignment Right to left -, => Left to right -not ! Right -and && Left to right -or xor ||, ^ Left to right \ No newline at end of file diff --git a/perl/_Basics/Precedence with word operators and short-circuit operators.pl b/perl/_Basics/Precedence with word operators and short-circuit operators.pl deleted file mode 100644 index 4792408..0000000 --- a/perl/_Basics/Precedence with word operators and short-circuit operators.pl +++ /dev/null @@ -1,12 +0,0 @@ - -$x=5; -$y=6; -$z=0; -$result=$x && $y &&$z; # Precedence of = lower than && -print "Result: $result\n"; - -$result2 = $x and$y and $z; # Precedence of = higher than and -print "Result:$result2\n"; - -$result3 = ($x and $y and$z ); -print "Result: $result3\n"; diff --git a/perl/_Basics/Read user input and use if statement to check it.pl b/perl/_Basics/Read user input and use if statement to check it.pl deleted file mode 100644 index 4e5e145..0000000 --- a/perl/_Basics/Read user input and use if statement to check it.pl +++ /dev/null @@ -1,24 +0,0 @@ - -#!/usr/bin/perl - -use warnings; -use strict; -my$weather = "good"; -print "How hot is it, in degrees? "; -my $temperature = ; -print "And how many emails left to reply to? "; -my$work = ; -chomp($weather,$temperature); -if ($weather eq "snowing") { - print "OK, let's go!\n"; -} elsif ($weather eq "raining") { - print "No way, sorry, I'm staying in.\n"; -} elsif ($temperature < 18) { - print "Too cold for me!\n"; -} elsif ($work > 30) { - print "Sorry just too busy.\n"; -} else { - print "Well, why not?\n"; -} - - \ No newline at end of file diff --git a/perl/_Basics/Remainder and power.pl b/perl/_Basics/Remainder and power.pl deleted file mode 100644 index f453045..0000000 --- a/perl/_Basics/Remainder and power.pl +++ /dev/null @@ -1,26 +0,0 @@ -#!C:\perl\bin - -$b = 7; -$size = 25; -$othervalue = 12; -$mass = 10; -$acceleration = 14; -$minutes = 600; -$num = 12; - -$a = $b + 5; - -$size = $size -$othervalue; -print "\$size =$size\n\n"; - -$speed =$mass * $acceleration; -print "\$speed = $speed\n\n"; - -$hours = $minutes / 60; -print "\$hours = $hours\n\n"; - -$remainder = 5 % 2; -print "\$remainder =$remainder\n\n"; - -$square =$num ** 2; -print "\$square =$square\n\n"; \ No newline at end of file diff --git a/perl/_Basics/Short-circuit operators.pl b/perl/_Basics/Short-circuit operators.pl deleted file mode 100644 index b730cd5..0000000 --- a/perl/_Basics/Short-circuit operators.pl +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/perl - -$num1=50; -$num2=100; -$num3=0; - -print$num1 && $num3, "\n"; -print$num3 && $num1, "\n"; -print$num1 && $num2, "\n"; -print$num2 && $num1, "\n\n"; - -print$num1 || $num3, "\n"; -print$num3 || $num1, "\n"; -print$num1 || $num2, "\n"; -print$num2 || $num1, "\n"; \ No newline at end of file diff --git a/perl/_Basics/Square$var.pl b/perl/_Basics/Square $var.pl deleted file mode 100644 index 6bf68bd..0000000 --- a/perl/_Basics/Square$var.pl +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/perl - -$var=0; - -$var **= 2; # Square $var -print "\$var squared is $var\n"; diff --git a/perl/_Basics/Subtract 1 from$var.pl b/perl/_Basics/Subtract 1 from $var.pl deleted file mode 100644 index 20e9f29..0000000 --- a/perl/_Basics/Subtract 1 from$var.pl +++ /dev/null @@ -1,7 +0,0 @@ - -#!/usr/bin/perl - -$var=0; - -$var -= 1; # Subtract 1 from $var -print "\$var -= 1 is $var\n"; diff --git a/perl/_Basics/The assignment operators.pl b/perl/_Basics/The assignment operators.pl deleted file mode 100644 index 2643fdb..0000000 --- a/perl/_Basics/The assignment operators.pl +++ /dev/null @@ -1,11 +0,0 @@ -Operator Operations performed -= Assignment only -+= Addition and assignment --= Subtraction and assignment -*= Multiplication and assignment -/= Division and assignment -%= Remainder and assignment -**= Exponentiation and assignment -&= Bitwise AND and assignment -|= Bitwise OR and assignment -^= Bitwise XOR and assignment diff --git a/perl/_Basics/The autoincrement operator.pl b/perl/_Basics/The autoincrement operator.pl deleted file mode 100644 index c2ec299..0000000 --- a/perl/_Basics/The autoincrement operator.pl +++ /dev/null @@ -1,9 +0,0 @@ - -#!/usr/bin/perl - -use warnings; -$a = "A9"; print ++$a, "\n"; -$a = "bc"; print ++$a, "\n"; -$a = "Zc"; print ++$a, "\n"; -$a = "z9"; print ++$a, "\n"; -$a = "9z"; print ++$a, "\n"; diff --git a/perl/_Basics/To set a variable, use the = operator.pl b/perl/_Basics/To set a variable, use the = operator.pl deleted file mode 100644 index 65a11c9..0000000 --- a/perl/_Basics/To set a variable, use the = operator.pl +++ /dev/null @@ -1,6 +0,0 @@ -# Setting scalar variables. -$var = "Text"; -$number_var = 44.5; - -print$var; -print $number_var; diff --git a/perl/_Basics/Use parentheses wherever possible to force precedence.pl b/perl/_Basics/Use parentheses wherever possible to force precedence.pl deleted file mode 100644 index f53e8dd..0000000 --- a/perl/_Basics/Use parentheses wherever possible to force precedence.pl +++ /dev/null @@ -1,22 +0,0 @@ - - - #!/usr/local/bin/perl -w - - print "Enter the first number : "; - my$num1 = ; chomp $num1; - print "Enter the second number: "; - my$num2 = ; chomp $num2; - print "Enter the third number : "; - my$num3 = ; chomp $num3; - - # A*B-C - my$answer = $num1 *$num2 - $num3; - print "$num1 * $num2 -$num3 = $answer \n"; - - # (A*B)-C -$answer = ($num1 *$num2) - $num3; - print "($num1 * $num2) -$num3 = $answer \n"; - - # A*(B-C) -$answer = $num1 * ($num2 - $num3); - print "$num1 * ($num2 -$num3) = $answer \n"; diff --git a/perl/_Basics/Using Assignment Operators on Scalar Variables.pl b/perl/_Basics/Using Assignment Operators on Scalar Variables.pl deleted file mode 100644 index 7bf8e34..0000000 --- a/perl/_Basics/Using Assignment Operators on Scalar Variables.pl +++ /dev/null @@ -1,16 +0,0 @@ -#How do you place data in a scalar variable? -#You use the assignment operator. - -$variable1 = 5; - -#String assignments work much the same way: - -$variable1 = "Hello there!"; - -#Besides single assignments, you can create multiple assignments in the same statement like this: - -$x = $y =$z = 1; -print join (", ", $x,$y, $z); - - - \ No newline at end of file diff --git a/perl/_Basics/Using auto-increment operator for a string with digits.pl b/perl/_Basics/Using auto-increment operator for a string with digits.pl deleted file mode 100644 index 9d7977e..0000000 --- a/perl/_Basics/Using auto-increment operator for a string with digits.pl +++ /dev/null @@ -1,6 +0,0 @@ - -#!/usr/bin/perl -w - -$a = "A9"; print ++$a, "\n"; -$a = "z9"; print ++$a, "\n"; -$a = "9z"; print ++$a, "\n"; diff --git a/perl/_Basics/Using auto-increment operator for a string.pl b/perl/_Basics/Using auto-increment operator for a string.pl deleted file mode 100644 index 327f0f4..0000000 --- a/perl/_Basics/Using auto-increment operator for a string.pl +++ /dev/null @@ -1,5 +0,0 @@ - -#!/usr/bin/perl -w - -$a = "bz"; print ++$a, "\n"; -$a = "Zz"; print ++$a, "\n"; diff --git a/php/_Basics/Add two numbers Program in PHP.php b/php/_Basics/Add two numbers Program in PHP.php deleted file mode 100644 index 9c4a746..0000000 --- a/php/_Basics/Add two numbers Program in PHP.php +++ /dev/null @@ -1,11 +0,0 @@ - - -/* Output : Sum: 30*/ \ No newline at end of file diff --git a/php/_Basics/Armstrong number Program in PHP.php b/php/_Basics/Armstrong number Program in PHP.php deleted file mode 100644 index a9b4ccd..0000000 --- a/php/_Basics/Armstrong number Program in PHP.php +++ /dev/null @@ -1,26 +0,0 @@ - - -/* -Output - -Armstrong number \ No newline at end of file diff --git a/php/_Basics/Even Odd number program in PHP.php b/php/_Basics/Even Odd number program in PHP.php deleted file mode 100644 index e965ef0..0000000 --- a/php/_Basics/Even Odd number program in PHP.php +++ /dev/null @@ -1,14 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/Factorial of a number in PHP.php b/php/_Basics/Factorial of a number in PHP.php deleted file mode 100644 index 4242e53..0000000 --- a/php/_Basics/Factorial of a number in PHP.php +++ /dev/null @@ -1,16 +0,0 @@ -=1;$x--) -{ - $factorial =$factorial * $x; -} -echo "Factorial of$num is $factorial"; - -?> - -/* -Output - -Factorial of 4 is 24 \ No newline at end of file diff --git a/php/_Basics/Fibonacci Series Program in PHP.php b/php/_Basics/Fibonacci Series Program in PHP.php deleted file mode 100644 index 4e15c5d..0000000 --- a/php/_Basics/Fibonacci Series Program in PHP.php +++ /dev/null @@ -1,30 +0,0 @@ - -/* Output Fibonacci Series 0 1 1 2 3 5 */ \ No newline at end of file diff --git a/php/_Basics/Number Pattern Problems in PHP.php b/php/_Basics/Number Pattern Problems in PHP.php deleted file mode 100644 index 19ef43f..0000000 --- a/php/_Basics/Number Pattern Problems in PHP.php +++ /dev/null @@ -1,59 +0,0 @@ -/* Print number Pattern in PHP */ -=1;$b--) -{ -echo "$b"; -} -echo " "; -} - -?> -/* Output - -1 -21 -321 -4321 */ - /* Print number Pattern in PHP */ -=1;$a--) -{ -for($b=1;$b<=$a;$b++) -{ -echo $b; -} - echo " "; -} - -?> - /* Output - -12345 -1234 -123 -12 -1 */ -/* Print number Pattern in PHP */ -=1;$a--) -{ -for($b=5;$b>=$a;$b--) -{ -echo $b; -} - echo " "; -} - -?> - /* Output - -5 -54 -543 -5432 -54321 */ \ No newline at end of file diff --git a/php/_Basics/PHP Program for Bubble sorting in PHP.php b/php/_Basics/PHP Program for Bubble sorting in PHP.php deleted file mode 100644 index 0cec82d..0000000 --- a/php/_Basics/PHP Program for Bubble sorting in PHP.php +++ /dev/null @@ -1,24 +0,0 @@ -// Write a Program for Bubble sorting in PHP - -$numbers[$d+1]) /* For decreasing order use < */ - { -$swap = $numbers[$d]; - $numbers[$d] = $numbers[$d+1]; - $numbers[$d+1] = $swap; - } - } - } - -echo "Sorted list in ascending order "; - - for ($c = 0 ; $c <$n ; $c++ ) - echo$numbers[$c]." "; - -?> \ No newline at end of file diff --git a/php/_Basics/PHP Program for finding the biggest number in an array without using any array functions.php b/php/_Basics/PHP Program for finding the biggest number in an array without using any array functions.php deleted file mode 100644 index 7645db5..0000000 --- a/php/_Basics/PHP Program for finding the biggest number in an array without using any array functions.php +++ /dev/null @@ -1,15 +0,0 @@ -// Write a Program for finding the biggest number in an array without using any array functions. - -$max) - { - $max=$numbers[$i]; - } - } -echo "The biggest number is ".$max; -?> \ No newline at end of file diff --git a/php/_Basics/PHP Program for finding the smallest number in an array.php b/php/_Basics/PHP Program for finding the smallest number in an array.php deleted file mode 100644 index 178fa55..0000000 --- a/php/_Basics/PHP Program for finding the smallest number in an array.php +++ /dev/null @@ -1,16 +0,0 @@ -// Write a Program for finding the smallest number in an array - - \ No newline at end of file diff --git a/php/_Basics/PHP Program to find whether a year is LEAP year or not.php b/php/_Basics/PHP Program to find whether a year is LEAP year or not.php deleted file mode 100644 index 896dad6..0000000 --- a/php/_Basics/PHP Program to find whether a year is LEAP year or not.php +++ /dev/null @@ -1,14 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to add the digits of a positive integer repeatedly until the result has a single digit..php b/php/_Basics/PHP program to add the digits of a positive integer repeatedly until the result has a single digit..php deleted file mode 100644 index 4ebf312..0000000 --- a/php/_Basics/PHP program to add the digits of a positive integer repeatedly until the result has a single digit..php +++ /dev/null @@ -1,16 +0,0 @@ - 0) - { - return ($num - 1) % 9 + 1; - } - else - { - return 0; - } -} - -print_r(add_digits(48)."\n"); -print_r(add_digits(59)."\n"); -?> \ No newline at end of file diff --git a/php/_Basics/PHP program to check a sequence of numbers is a geometric progression or not..php b/php/_Basics/PHP program to check a sequence of numbers is a geometric progression or not..php deleted file mode 100644 index 63cf4ed..0000000 --- a/php/_Basics/PHP program to check a sequence of numbers is a geometric progression or not..php +++ /dev/null @@ -1,28 +0,0 @@ - - -Output: -Geometric sequence -Not an geometric sequence \ No newline at end of file diff --git a/php/_Basics/PHP program to check a sequence of numbers is an arithmetic progression or not..php b/php/_Basics/PHP program to check a sequence of numbers is an arithmetic progression or not..php deleted file mode 100644 index 2c03c26..0000000 --- a/php/_Basics/PHP program to check a sequence of numbers is an arithmetic progression or not..php +++ /dev/null @@ -1,20 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to check if a given positive integer is a power of four..php b/php/_Basics/PHP program to check if a given positive integer is a power of four..php deleted file mode 100644 index d329366..0000000 --- a/php/_Basics/PHP program to check if a given positive integer is a power of four..php +++ /dev/null @@ -1,22 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to check if a given positive integer is a power of three..php b/php/_Basics/PHP program to check if a given positive integer is a power of three..php deleted file mode 100644 index eb05867..0000000 --- a/php/_Basics/PHP program to check if a given positive integer is a power of three..php +++ /dev/null @@ -1,22 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to check if a given positive integer is a power of two..php b/php/_Basics/PHP program to check if a given positive integer is a power of two..php deleted file mode 100644 index 6502375..0000000 --- a/php/_Basics/PHP program to check if a given positive integer is a power of two..php +++ /dev/null @@ -1,16 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to check if a given string is an anagram of another given string..php b/php/_Basics/PHP program to check if a given string is an anagram of another given string..php deleted file mode 100644 index 3ee13ef..0000000 --- a/php/_Basics/PHP program to check if a given string is an anagram of another given string..php +++ /dev/null @@ -1,15 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to check if an integer is the power of another integer..php b/php/_Basics/PHP program to check if an integer is the power of another integer..php deleted file mode 100644 index f9cd662..0000000 --- a/php/_Basics/PHP program to check if an integer is the power of another integer..php +++ /dev/null @@ -1,23 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to check whether a given number is an ugly number..php b/php/_Basics/PHP program to check whether a given number is an ugly number..php deleted file mode 100644 index 139a5a4..0000000 --- a/php/_Basics/PHP program to check whether a given number is an ugly number..php +++ /dev/null @@ -1,31 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to compute and return the square root of a given number..php b/php/_Basics/PHP program to compute and return the square root of a given number..php deleted file mode 100644 index cba7e46..0000000 --- a/php/_Basics/PHP program to compute and return the square root of a given number..php +++ /dev/null @@ -1,15 +0,0 @@ -$y) - { - $x = ($x + $y)/2; -$y = $n/$x; - } - return $x; -} -print_r(my_sqrt(16)."\n"); -print_r(my_sqrt(14)."\n"); -?> \ No newline at end of file diff --git a/php/_Basics/PHP program to compute the sum of the two reversed numbers and display the sum in reversed form..php b/php/_Basics/PHP program to compute the sum of the two reversed numbers and display the sum in reversed form..php deleted file mode 100644 index c2a8fda..0000000 --- a/php/_Basics/PHP program to compute the sum of the two reversed numbers and display the sum in reversed form..php +++ /dev/null @@ -1,21 +0,0 @@ - 0) - { -$reverse = $reverse * 10; -$reverse = $reverse +$n % 10; - $n = (int)($n/10); - } - return $reverse; -} -print_r(reverse_sum(13, 14)."\n"); -print_r(reverse_sum(130, 1)."\n"); -print_r(reverse_sum(305, 794)."\n"); -?> \ No newline at end of file diff --git a/php/_Basics/PHP program to find HCF of two numbers.php b/php/_Basics/PHP program to find HCF of two numbers.php deleted file mode 100644 index 842712f..0000000 --- a/php/_Basics/PHP program to find HCF of two numbers.php +++ /dev/null @@ -1,37 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to find a missing number(s) from an array.php b/php/_Basics/PHP program to find a missing number(s) from an array.php deleted file mode 100644 index 3f5a69f..0000000 --- a/php/_Basics/PHP program to find a missing number(s) from an array.php +++ /dev/null @@ -1,14 +0,0 @@ -function missing_number($num_list) -{ - -// construct a new array -$new_arr = range($num_list[0],max($num_list)); - -// use array_diff to find the missing elements -return array_diff($new_arr, $num_list); - -} - -print_r(missing_number(array(1,2,3,6,7,8))); -print_r(missing_number(array(10,11,12,14,15,16,17))); -?> \ No newline at end of file diff --git a/php/_Basics/PHP program to find a single element in an array where every element appears three times except for one..php b/php/_Basics/PHP program to find a single element in an array where every element appears three times except for one..php deleted file mode 100644 index d4a7e0b..0000000 --- a/php/_Basics/PHP program to find a single element in an array where every element appears three times except for one..php +++ /dev/null @@ -1,24 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to find a single number in an array that doesn't occur twice..php b/php/_Basics/PHP program to find a single number in an array that doesn't occur twice..php deleted file mode 100644 index de4753e..0000000 --- a/php/_Basics/PHP program to find a single number in an array that doesn't occur twice..php +++ /dev/null @@ -1,20 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to find factor of any number.php b/php/_Basics/PHP program to find factor of any number.php deleted file mode 100644 index ec01f1a..0000000 --- a/php/_Basics/PHP program to find factor of any number.php +++ /dev/null @@ -1,17 +0,0 @@ -// Write a program to find factor of any number - - \ No newline at end of file diff --git a/php/_Basics/PHP program to find majority element in an array..php b/php/_Basics/PHP program to find majority element in an array..php deleted file mode 100644 index 555baee..0000000 --- a/php/_Basics/PHP program to find majority element in an array..php +++ /dev/null @@ -1,29 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to find table of a number.php b/php/_Basics/PHP program to find table of a number.php deleted file mode 100644 index d900937..0000000 --- a/php/_Basics/PHP program to find table of a number.php +++ /dev/null @@ -1,16 +0,0 @@ -//Write a program to find table of a number - - Table of " .$num."
"; - for($i=1;$i<=10;$i++) - { - echo$num*$i; - echo " "; - } - - } - - ?> \ No newline at end of file diff --git a/php/_Basics/PHP program to find the length of the last word in a string..php b/php/_Basics/PHP program to find the length of the last word in a string..php deleted file mode 100644 index 6b327d3..0000000 --- a/php/_Basics/PHP program to find the length of the last word in a string..php +++ /dev/null @@ -1,23 +0,0 @@ -1) - return strlen(substr($s, strrpos($s, ' ') + 1)); - else - return "Single word"; - - -} -print_r(length_of_last_word("PHP Exercises")."\n"); -print_r(length_of_last_word("PHP")."\n"); -print_r(length_of_last_word("")."\n"); -print_r(length_of_last_word(" ")."\n"); -?> \ No newline at end of file diff --git a/php/_Basics/PHP program to find the single element appears once in an array where every element appears twice except for one.php b/php/_Basics/PHP program to find the single element appears once in an array where every element appears twice except for one.php deleted file mode 100644 index b8f6d74..0000000 --- a/php/_Basics/PHP program to find the single element appears once in an array where every element appears twice except for one.php +++ /dev/null @@ -1,15 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to find the single number which occurs odd numbers and other numbers occur even number..php b/php/_Basics/PHP program to find the single number which occurs odd numbers and other numbers occur even number..php deleted file mode 100644 index 844fb54..0000000 --- a/php/_Basics/PHP program to find the single number which occurs odd numbers and other numbers occur even number..php +++ /dev/null @@ -1,19 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to find three numbers from an array such that the sum of three consecutive numbers equal to a given number..php b/php/_Basics/PHP program to find three numbers from an array such that the sum of three consecutive numbers equal to a given number..php deleted file mode 100644 index bece5b6..0000000 --- a/php/_Basics/PHP program to find three numbers from an array such that the sum of three consecutive numbers equal to a given number..php +++ /dev/null @@ -1,17 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to find three numbers from an array such that the sum of three consecutive numbers equal to zero.php b/php/_Basics/PHP program to find three numbers from an array such that the sum of three consecutive numbers equal to zero.php deleted file mode 100644 index 52daa43..0000000 --- a/php/_Basics/PHP program to find three numbers from an array such that the sum of three consecutive numbers equal to zero.php +++ /dev/null @@ -1,20 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to find whether a number is Armstrong or not.php b/php/_Basics/PHP program to find whether a number is Armstrong or not.php deleted file mode 100644 index e01668e..0000000 --- a/php/_Basics/PHP program to find whether a number is Armstrong or not.php +++ /dev/null @@ -1,26 +0,0 @@ -// If the sum of cubes of individual digits of a number is equal to the number itslef then it is called Armstrong Number. - \ No newline at end of file diff --git a/php/_Basics/PHP program to get the Hamming numbers upto a given numbers also check whether a given number is a Hamming number..php b/php/_Basics/PHP program to get the Hamming numbers upto a given numbers also check whether a given number is a Hamming number..php deleted file mode 100644 index b0a0fc6..0000000 --- a/php/_Basics/PHP program to get the Hamming numbers upto a given numbers also check whether a given number is a Hamming number..php +++ /dev/null @@ -1,41 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to print Reverse of any number.php b/php/_Basics/PHP program to print Reverse of any number.php deleted file mode 100644 index 46f799f..0000000 --- a/php/_Basics/PHP program to print Reverse of any number.php +++ /dev/null @@ -1,14 +0,0 @@ -=1) - { -$re=$num%10; -$rev=$rev*10+$re; - $num=$num/10; - } -} -?> \ No newline at end of file diff --git a/php/_Basics/PHP program to push all zeros to the end of an array..php b/php/_Basics/PHP program to push all zeros to the end of an array..php deleted file mode 100644 index 2c79107..0000000 --- a/php/_Basics/PHP program to push all zeros to the end of an array..php +++ /dev/null @@ -1,28 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/PHP program to reverse the bits of an integer (32 bits unsigned)..php b/php/_Basics/PHP program to reverse the bits of an integer (32 bits unsigned)..php deleted file mode 100644 index 6caa6c7..0000000 --- a/php/_Basics/PHP program to reverse the bits of an integer (32 bits unsigned)..php +++ /dev/null @@ -1,15 +0,0 @@ ->= 1; - } - return $result; - -} -print_r(reverse_integer(1234)."\n"); -?> \ No newline at end of file diff --git a/php/_Basics/PHP program to reverse the digits of an integer..php b/php/_Basics/PHP program to reverse the digits of an integer..php deleted file mode 100644 index 0754ff9..0000000 --- a/php/_Basics/PHP program to reverse the digits of an integer..php +++ /dev/null @@ -1,15 +0,0 @@ - 0) - { -$reverse = $reverse * 10; -$reverse = $reverse +$n % 10; - $n = (int)($n/10); - } - return $reverse; -} -print_r(reverse_integer(1234)."\n"); -print_r(reverse_integer(23)."\n"); -?> \ No newline at end of file diff --git a/php/_Basics/PHP program where you take any positive integer n, if n is even, divide it by 2 to get n (by) 2..php b/php/_Basics/PHP program where you take any positive integer n, if n is even, divide it by 2 to get n (by) 2..php deleted file mode 100644 index cf2aa70..0000000 --- a/php/_Basics/PHP program where you take any positive integer n, if n is even, divide it by 2 to get n (by) 2..php +++ /dev/null @@ -1,26 +0,0 @@ - 1) - { - if ($x % 2 == 0) - { - $x =$x / 2; - } - else - { - $x = 3 *$x + 1; - } - # Added line - array_push($num_seq,$x); - } - return $num_seq; -} -print_r(collatz_sequence(12)); -print_r(collatz_sequence(19)); -?> \ No newline at end of file diff --git a/php/_Basics/Palindrome number Program in PHP.php b/php/_Basics/Palindrome number Program in PHP.php deleted file mode 100644 index 6862f27..0000000 --- a/php/_Basics/Palindrome number Program in PHP.php +++ /dev/null @@ -1,24 +0,0 @@ - -/* -Output - -121 is palindrome number \ No newline at end of file diff --git a/php/_Basics/Pattern Problems in PHP.php b/php/_Basics/Pattern Problems in PHP.php deleted file mode 100644 index 78fb9fe..0000000 --- a/php/_Basics/Pattern Problems in PHP.php +++ /dev/null @@ -1,406 +0,0 @@ -/* Pattern problems in PHP */ -/* 1 */ - -"; -} - -?> -/* -Output - -* -* -* -* -* -*/ -/* Print Triangle of Stars in PHP */ - -"; -} - -?> - -/* -Output - -* * * * * -* * * * * -* * * * * -* * * * * -* * * * * -*/ - -/*Print Star Pattern in PHP */ - -"; -} - -?> - -/* - -Output - -* -* * -* * * -* * * * -* * * * * -* * * * * * -* * * * * * * -*/ -/* Print Star Pattern in PHP */ -=1;$j--) -{ -echo "* "; -} -echo "
"; -} - -?> - -/* -Output - -* * * * * * * -* * * * * * -* * * * * -* * * * -* * * -* * -* -*/ - -/* Print Triangle of Stars in PHP */ - -=1; $a--) -{ -if($a%2 != 0) -{ -for($b=5;$b>=$a;$b--) -{ -echo "* "; -} -echo "
"; -} -} -for($a=2;$a<=5; $a++) -{ - if($a%2 != 0) -{ - for($b=5;$b>=$a;$b--) -{ -echo "* "; -} -echo "
"; -} -} - -?> - -/* -Output - -* -* * * -* * * * * -* * * -* -*/ -/* -Print Star Pattern in PHP*/ - - 3 ? 6 - $row :$row); $col++) - { - echo '* '; - } - - echo " "; -} - -?> -/* -Output - -* -* * -* * * -* * -* -*/ - -/* Print Triangle of Stars in PHP*/ - -=$i;$k--) -{ -echo " "; -} -for($j=1;$j<=$i;$j++) -{ -echo "* "; -} -echo " "; -} -for($i=5;$i>=1;$i--) -{ -for($k=6;$k>=$i;$k--) -{ -echo " "; -} -for($j=1;$j<=$i;$j++) -{ -echo "* "; -} -echo "
"; -} - -?> -/* -Output - -* -* * -* * * -* * * * -* * * * * -* * * * * * -* * * * * * * -* * * * * * -* * * * * -* * * * -* * * -* * -* -*/ - -* * * * * * * * * * * * * * * -* * * * * * * * * * * * * -* * * * * * * * * * * -* * * * * * * * * -* * * * * * * -* * * * * -* * * -* - -=1;--$i) - { - for($space=0;$space<$rows-$i;++$space) - echo " "; - for($j=$i;$j<=2*$i-1;++$j) - echo "* "; - for($j=0;$j<$i-1;++$j) - echo "* "; - echo " "; - } - } - ?> - -Program to print below format. -1 2 3 4 5 6 7 8 -1 2 3 4 5 6 7 -1 2 3 4 5 6 -1 2 3 4 5 -1 2 3 4 -1 2 3 -1 2 -1 -Hide Answer -=1;--$i) - { - for($j=1;$j<=$i;++$j) - { - echo $j; - } - echo " "; - } - } - ?> - - Program to print below format -* -* * -* * * -* * * * -* * * * * -* * * * * * -* * * * * * * -* * * * * * * * -* * * * * * * * * -Hide Answer -"; - } - } - ?> - - /* Write a program to print below format -1 -1 2 -1 2 3 -1 2 3 4 -1 2 3 4 5 -1 2 3 4 5 6 -1 2 3 4 5 6 7 -1 2 3 4 5 6 7 8 -*/ -"; - } - } - -/* - Write a program to print the below format : -1 5 9 -2 6 10 -3 7 11 -4 8 12 -*/ -"; -} - - -?> - - -Write a program for this Pattern: -***** -* * -* * -* * -***** -Hide Answer -"; - } -?> - - - -How to write a Floyd's Triangle? -1 -23 -456 -78910 -1112131415 -Hide Answer - '; -} -?> - -Write a program to make a chess: - -Hide Answer - - - "; - for($col=1;$col<=8;$col++) - { - $total=$row+$col; - if($total%2==0) - { - echo ""; - } - else - { - echo ""; - } - } - echo ""; - } - ?> - - diff --git a/php/_Basics/Print Table of aby number Program in PHP.php b/php/_Basics/Print Table of aby number Program in PHP.php deleted file mode 100644 index e3fa982..0000000 --- a/php/_Basics/Print Table of aby number Program in PHP.php +++ /dev/null @@ -1,23 +0,0 @@ -'; -} - -?> - -/* -3 -6 -9 -12 -15 -18 -21 -24 -27 -30 \ No newline at end of file diff --git a/php/_Basics/Print an array in PHP.php b/php/_Basics/Print an array in PHP.php deleted file mode 100644 index 3c11200..0000000 --- a/php/_Basics/Print an array in PHP.php +++ /dev/null @@ -1,16 +0,0 @@ -".$v; - } - -?> \ No newline at end of file diff --git a/php/_Basics/Print an array using foreach in php.php b/php/_Basics/Print an array using foreach in php.php deleted file mode 100644 index ed9b8dd..0000000 --- a/php/_Basics/Print an array using foreach in php.php +++ /dev/null @@ -1,11 +0,0 @@ -"; - } - -?> \ No newline at end of file diff --git a/php/_Basics/Program to combine the array elements into a string with given delimiter..php b/php/_Basics/Program to combine the array elements into a string with given delimiter..php deleted file mode 100644 index 593a91d..0000000 --- a/php/_Basics/Program to combine the array elements into a string with given delimiter..php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/Program to create a Simple Calculator..php b/php/_Basics/Program to create a Simple Calculator..php deleted file mode 100644 index 678a320..0000000 --- a/php/_Basics/Program to create a Simple Calculator..php +++ /dev/null @@ -1,33 +0,0 @@ - - - -Calculator - -No1: - -No2: - -Res: - - - - - - \ No newline at end of file diff --git a/php/_Basics/Program to create simple Login and Logout example using sessions.php b/php/_Basics/Program to create simple Login and Logout example using sessions.php deleted file mode 100644 index 329257c..0000000 --- a/php/_Basics/Program to create simple Login and Logout example using sessions.php +++ /dev/null @@ -1,56 +0,0 @@ -login.php - - - -Login Form - - - ## Login Form - -User Id: -Password: - - - - - -checklogin.php - - - -securepage.php - -"; - echo "Logout"; - } - else - { - header("location:login.php"); - } -?> - -logout.php - - \ No newline at end of file diff --git a/php/_Basics/Program to find number of elements in an array..php b/php/_Basics/Program to find number of elements in an array..php deleted file mode 100644 index 97397d2..0000000 --- a/php/_Basics/Program to find number of elements in an array..php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/Program to find prime numbers in between a Range.php b/php/_Basics/Program to find prime numbers in between a Range.php deleted file mode 100644 index 532974f..0000000 --- a/php/_Basics/Program to find prime numbers in between a Range.php +++ /dev/null @@ -1,33 +0,0 @@ -/* -Output - -Prime Number : 2 -Prime Number : 3 -Prime Number : 5 -Prime Number : 7 -Prime Number : 11 -Prime Number : 13 -Prime Number : 17 -Prime Number : 19 -Prime Number : 23 \ No newline at end of file diff --git a/php/_Basics/Program to find the product of elements in an array..php b/php/_Basics/Program to find the product of elements in an array..php deleted file mode 100644 index d79f61c..0000000 --- a/php/_Basics/Program to find the product of elements in an array..php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/Program to find the sum of elements in an array..php b/php/_Basics/Program to find the sum of elements in an array..php deleted file mode 100644 index f9d36c2..0000000 --- a/php/_Basics/Program to find the sum of elements in an array..php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/Program to join the array elements into a string..php b/php/_Basics/Program to join the array elements into a string..php deleted file mode 100644 index dead124..0000000 --- a/php/_Basics/Program to join the array elements into a string..php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/Program to merge two arrays into a new array..php b/php/_Basics/Program to merge two arrays into a new array..php deleted file mode 100644 index 7e71e02..0000000 --- a/php/_Basics/Program to merge two arrays into a new array..php +++ /dev/null @@ -1,9 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/Program to remove the duplicate values from an array..php b/php/_Basics/Program to remove the duplicate values from an array..php deleted file mode 100644 index 02a9923..0000000 --- a/php/_Basics/Program to remove the duplicate values from an array..php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/Program to sort elements in an array in ascending order..php b/php/_Basics/Program to sort elements in an array in ascending order..php deleted file mode 100644 index 0ab59a2..0000000 --- a/php/_Basics/Program to sort elements in an array in ascending order..php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/Program to sort elements in an array in descending order..php b/php/_Basics/Program to sort elements in an array in descending order..php deleted file mode 100644 index faf863c..0000000 --- a/php/_Basics/Program to sort elements in an array in descending order..php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/Program to split a string into an array elements based on delimiter..php b/php/_Basics/Program to split a string into an array elements based on delimiter..php deleted file mode 100644 index 3443655..0000000 --- a/php/_Basics/Program to split a string into an array elements based on delimiter..php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/php/_Basics/Reverse String Program in PHP.php b/php/_Basics/Reverse String Program in PHP.php deleted file mode 100644 index a7bfc79..0000000 --- a/php/_Basics/Reverse String Program in PHP.php +++ /dev/null @@ -1,25 +0,0 @@ -=$a;$i--) - -{ - -$c[]=$a[$i]; - - - - } - - echo implode($c,); - - - -?> \ No newline at end of file diff --git a/php/_Basics/Swap two number using third variable program in PHP.php b/php/_Basics/Swap two number using third variable program in PHP.php deleted file mode 100644 index 300477d..0000000 --- a/php/_Basics/Swap two number using third variable program in PHP.php +++ /dev/null @@ -1,23 +0,0 @@ -"; -echo "Value of b:$b
"; - -$temp=$a; -$a=$b; -$b=$temp; - -echo "Value of a: $a "; -echo "Value of b:$b
"; - -?> - -/* -Output -Value of a: 10 -Value of b: 20 -Value of a: 20 -Value of b: 10 \ No newline at end of file diff --git a/php/_Basics/Swap two number without using third variable program in PHP.php b/php/_Basics/Swap two number without using third variable program in PHP.php deleted file mode 100644 index 0769a89..0000000 --- a/php/_Basics/Swap two number without using third variable program in PHP.php +++ /dev/null @@ -1,24 +0,0 @@ -"; -echo "Value of b: $b "; - -$a=$a+$b; -$b=$a-$b; -$a=$a-$b; - -echo "Value of a: $a "; -echo "Value of b:$b
"; - -?> -/* - -Output - -Value of a: 10 -Value of b: 20 -Value of a: 20 -Value of b: 10 \ No newline at end of file diff --git a/python/_Basics/Accept the base and height of a triangle and compute the area.py b/python/_Basics/Accept the base and height of a triangle and compute the area.py deleted file mode 100644 index 90ba5ac..0000000 --- a/python/_Basics/Accept the base and height of a triangle and compute the area.py +++ /dev/null @@ -1,6 +0,0 @@ -b = int(input("Input the base : ")) -h = int(input("Input the height : ")) - -area = b*h/2 - -print("area = ", area) \ No newline at end of file diff --git a/python/_Basics/Access and print a URL's content to the console.py b/python/_Basics/Access and print a URL's content to the console.py deleted file mode 100644 index 8c583ee..0000000 --- a/python/_Basics/Access and print a URL's content to the console.py +++ /dev/null @@ -1,7 +0,0 @@ -from http.client import HTTPConnection -conn = HTTPConnection("example.com") -conn.request("GET", "/") -result = conn.getresponse() -# retrieves the entire contents. -contents = result.read() -print(contents) \ No newline at end of file diff --git a/python/_Basics/Access environment variables.py b/python/_Basics/Access environment variables.py deleted file mode 100644 index e375b2d..0000000 --- a/python/_Basics/Access environment variables.py +++ /dev/null @@ -1,10 +0,0 @@ -import os -# Access all environment variables -print('*----------------------------------*') -print(os.environ) -print('*----------------------------------*') -# Access a particular environment variable -print(os.environ['HOME']) -print('*----------------------------------*') -print(os.environ['PATH']) -print('*----------------------------------*') \ No newline at end of file diff --git a/python/_Basics/Calculate midpoints of a line.py b/python/_Basics/Calculate midpoints of a line.py deleted file mode 100644 index 479d551..0000000 --- a/python/_Basics/Calculate midpoints of a line.py +++ /dev/null @@ -1,15 +0,0 @@ -print('\nCalculate the midpoint of a line :') - -x1 = float(input('The value of x (the first endpoint) ')) -y1 = float(input('The value of y (the first endpoint) ')) - -x2 = float(input('The value of x (the first endpoint) ')) -y2 = float(input('The value of y (the first endpoint) ')) - -x_m_point = (x1 + x2)/2 -y_m_point = (y1 + y2)/2 -print(); -print("The midpoint of line is :") -print( "The midpoint's x value is: ",x_m_point) -print( "The midpoint's y value is: ",y_m_point) -print(); \ No newline at end of file diff --git a/python/_Basics/Calculate number of days between two dates.py b/python/_Basics/Calculate number of days between two dates.py deleted file mode 100644 index 2fe74d3..0000000 --- a/python/_Basics/Calculate number of days between two dates.py +++ /dev/null @@ -1,6 +0,0 @@ -from datetime import date - -f_date = date(2014, 7, 2) -l_date = date(2014, 7, 11) -delta = l_date - f_date -print(delta.days) \ No newline at end of file diff --git a/python/_Basics/Calculate the hypotenuse of a right angled triangle.py b/python/_Basics/Calculate the hypotenuse of a right angled triangle.py deleted file mode 100644 index 082da02..0000000 --- a/python/_Basics/Calculate the hypotenuse of a right angled triangle.py +++ /dev/null @@ -1,7 +0,0 @@ -from math import sqrt -print("Input lengths of shorter triangle sides:") -a = float(input("a: ")) -b = float(input("b: ")) - -c = sqrt(a**2 + b**2) -print("The length of the hypotenuse is", c ) \ No newline at end of file diff --git a/python/_Basics/Calculate the sum of the digits in an integer.py b/python/_Basics/Calculate the sum of the digits in an integer.py deleted file mode 100644 index fc43b2f..0000000 --- a/python/_Basics/Calculate the sum of the digits in an integer.py +++ /dev/null @@ -1,6 +0,0 @@ -num = int(input("Input a four digit numbers: ")) -x = num //1000 -x1 = (num - x*1000)//100 -x2 = (num - x*1000 - x1*100)//10 -x3 = num - x*1000 - x1*100 - x2*10 -print("The sum of digits in the number is", x+x1+x2+x3) \ No newline at end of file diff --git a/python/_Basics/Calculate the sum of three given numbers, if the values are equal then return thrice of their sum.py b/python/_Basics/Calculate the sum of three given numbers, if the values are equal then return thrice of their sum.py deleted file mode 100644 index 77b1baf..0000000 --- a/python/_Basics/Calculate the sum of three given numbers, if the values are equal then return thrice of their sum.py +++ /dev/null @@ -1,10 +0,0 @@ -def sum_thrice(x, y, z): - - sum = x + y + z - - if x == y == z: - sum = sum * 3 - return sum - -print(sum_thrice(1, 2, 3)) -print(sum_thrice(3, 3, 3)) \ No newline at end of file diff --git a/python/_Basics/Check whether Python shell is executing in 32bit or 64bit mode on OS.py b/python/_Basics/Check whether Python shell is executing in 32bit or 64bit mode on OS.py deleted file mode 100644 index c6d4142..0000000 --- a/python/_Basics/Check whether Python shell is executing in 32bit or 64bit mode on OS.py +++ /dev/null @@ -1,3 +0,0 @@ -# For 32 bit it will return 32 and for 64 bit it will return 64 -import struct -print(struct.calcsize("P") * 8) \ No newline at end of file diff --git a/python/_Basics/Compute the distance between two points.py b/python/_Basics/Compute the distance between two points.py deleted file mode 100644 index e4fad5f..0000000 --- a/python/_Basics/Compute the distance between two points.py +++ /dev/null @@ -1,7 +0,0 @@ -import math - -p1 = [4, 0] -p2 = [6, 6] -distance = math.sqrt( ((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2) ) - -print(distance) \ No newline at end of file diff --git a/python/_Basics/Concatenate all elements in a list into a string.py b/python/_Basics/Concatenate all elements in a list into a string.py deleted file mode 100644 index 68d36c9..0000000 --- a/python/_Basics/Concatenate all elements in a list into a string.py +++ /dev/null @@ -1,7 +0,0 @@ -def concatenate_list_data(list): - result= '' - for element in list: - result += str(element) - return result - -print(concatenate_list_data([1, 5, 12, 2])) \ No newline at end of file diff --git a/python/_Basics/Convert all units of time into seconds.py b/python/_Basics/Convert all units of time into seconds.py deleted file mode 100644 index ee4cd99..0000000 --- a/python/_Basics/Convert all units of time into seconds.py +++ /dev/null @@ -1,8 +0,0 @@ -days = int(input("Input days: ")) * 3600 * 24 -hours = int(input("Input hours: ")) * 3600 -minutes = int(input("Input minutes: ")) * 60 -seconds = int(input("Input seconds: ")) - -time = days + hours + minutes + seconds - -print("The amounts of seconds", time) \ No newline at end of file diff --git a/python/_Basics/Convert height (in feet and inches) to centimeters.py b/python/_Basics/Convert height (in feet and inches) to centimeters.py deleted file mode 100644 index 0e2ac23..0000000 --- a/python/_Basics/Convert height (in feet and inches) to centimeters.py +++ /dev/null @@ -1,8 +0,0 @@ -print("Input your height: ") -h_ft = int(input("Feet: ")) -h_inch = int(input("Inches: ")) - -h_inch += h_ft * 12 -h_cm = round(h_inch * 2.54, 1) - -print("Your height is : %d cm." % h_cm) \ No newline at end of file diff --git a/python/_Basics/Convert pressure in kilopascals to pounds.py b/python/_Basics/Convert pressure in kilopascals to pounds.py deleted file mode 100644 index d0e9b2c..0000000 --- a/python/_Basics/Convert pressure in kilopascals to pounds.py +++ /dev/null @@ -1,7 +0,0 @@ -kpa = float(input("Input pressure in in kilopascals> ")) -psi = kpa / 6.89475729 -mmhg = kpa * 760 / 101.325 -atm = kpa / 101.325 -print("The pressure in pounds per square inch: %.2f psi" % (psi)) -print("The pressure in millimeter of mercury: %.2f mmHg" % (mmhg)) -print("Atmosphere pressure: %.2f atm." % (atm)) \ No newline at end of file diff --git a/python/_Basics/Convert the distance in feet to inches, yards, and miles.py b/python/_Basics/Convert the distance in feet to inches, yards, and miles.py deleted file mode 100644 index 4f59a40..0000000 --- a/python/_Basics/Convert the distance in feet to inches, yards, and miles.py +++ /dev/null @@ -1,8 +0,0 @@ -d_ft = int(input("Input distance in feet: ")) -d_inches = d_ft * 12 -d_yards = d_ft / 3.0 -d_miles = d_ft / 5280.0 - -print("The distance in inches is %i inches." % d_inches) -print("The distance in yards is %.2f yards." % d_yards) -print("The distance in miles is %.2f miles." % d_miles) \ No newline at end of file diff --git a/python/_Basics/Create a histogram from a given list of integers.py b/python/_Basics/Create a histogram from a given list of integers.py deleted file mode 100644 index b3b4ded..0000000 --- a/python/_Basics/Create a histogram from a given list of integers.py +++ /dev/null @@ -1,10 +0,0 @@ -def histogram( items ): - for n in items: - output = '' - times = n - while( times > 0 ): - output += '*' - times = times - 1 - print(output) - -histogram([2, 3, 6, 5]) \ No newline at end of file diff --git a/python/_Basics/Determine profiling of Python programs.py b/python/_Basics/Determine profiling of Python programs.py deleted file mode 100644 index e04e202..0000000 --- a/python/_Basics/Determine profiling of Python programs.py +++ /dev/null @@ -1,4 +0,0 @@ -import cProfile -def sum(): - print(1+2) -cProfile.run('sum()') \ No newline at end of file diff --git a/python/_Basics/Find out the number of CPUs using.py b/python/_Basics/Find out the number of CPUs using.py deleted file mode 100644 index 51a01df..0000000 --- a/python/_Basics/Find out the number of CPUs using.py +++ /dev/null @@ -1,2 +0,0 @@ -import multiprocessing -print(multiprocessing.cpu_count()) \ No newline at end of file diff --git a/python/_Basics/Generate a list and tuple with comma-separated numbers.py b/python/_Basics/Generate a list and tuple with comma-separated numbers.py deleted file mode 100644 index 77f0d1c..0000000 --- a/python/_Basics/Generate a list and tuple with comma-separated numbers.py +++ /dev/null @@ -1,5 +0,0 @@ -values = input("Input some comma seprated numbers : ") -list = values.split(",") -tuple = tuple(list) -print('List : ',list) -print('Tuple : ',tuple) \ No newline at end of file diff --git a/python/_Basics/Get OS name, platform and release information.py b/python/_Basics/Get OS name, platform and release information.py deleted file mode 100644 index 62f2bc8..0000000 --- a/python/_Basics/Get OS name, platform and release information.py +++ /dev/null @@ -1,5 +0,0 @@ -import platform -import os -print(os.name) -print(platform.system()) -print(platform.release()) \ No newline at end of file diff --git a/python/_Basics/Get a string which is n (non-negative integer) copies of a given string.py b/python/_Basics/Get a string which is n (non-negative integer) copies of a given string.py deleted file mode 100644 index d3f7bb3..0000000 --- a/python/_Basics/Get a string which is n (non-negative integer) copies of a given string.py +++ /dev/null @@ -1,8 +0,0 @@ -def larger_string(str, n): - result = "" - for i in range(n): - result = result + str - return result - -print(larger_string('abc', 2)) -print(larger_string('.py', 3)) \ No newline at end of file diff --git a/python/_Basics/Get the difference between a given number and 17, if the number is greater than 17 return double the absolute difference.py b/python/_Basics/Get the difference between a given number and 17, if the number is greater than 17 return double the absolute difference.py deleted file mode 100644 index 83f6ee3..0000000 --- a/python/_Basics/Get the difference between a given number and 17, if the number is greater than 17 return double the absolute difference.py +++ /dev/null @@ -1,8 +0,0 @@ -def difference(n): - if n <= 17: - return 17 - n - else: - return (n - 17) * 2 - -print(difference(22)) -print(difference(14)) \ No newline at end of file diff --git a/python/_Basics/Get the path and name of the file that is currently executing.py b/python/_Basics/Get the path and name of the file that is currently executing.py deleted file mode 100644 index 0716553..0000000 --- a/python/_Basics/Get the path and name of the file that is currently executing.py +++ /dev/null @@ -1,2 +0,0 @@ -import os -print("Current File Name : ",os.path.realpath(__file__)) \ No newline at end of file diff --git a/python/_Basics/Input a filename and print the extension of that.py b/python/_Basics/Input a filename and print the extension of that.py deleted file mode 100644 index dff0367..0000000 --- a/python/_Basics/Input a filename and print the extension of that.py +++ /dev/null @@ -1,3 +0,0 @@ -filename = input("Input the Filename: ") -f_extns = filename.split(".") -print ("The extension of the file is : " + repr(f_extns[-1])) \ No newline at end of file diff --git a/python/_Basics/Input an integer (n) and computes the value of n+nn+nnn.py b/python/_Basics/Input an integer (n) and computes the value of n+nn+nnn.py deleted file mode 100644 index 5a51e2d..0000000 --- a/python/_Basics/Input an integer (n) and computes the value of n+nn+nnn.py +++ /dev/null @@ -1,5 +0,0 @@ -a = int(input("Input an integer : ")) -n1 = int( "%s" % a ) -n2 = int( "%s%s" % (a,a) ) -n3 = int( "%s%s%s" % (a,a,a) ) -print (n1+n2+n3) \ No newline at end of file diff --git a/python/_Basics/Input the radius of a circle and compute the area.py b/python/_Basics/Input the radius of a circle and compute the area.py deleted file mode 100644 index 9e721d9..0000000 --- a/python/_Basics/Input the radius of a circle and compute the area.py +++ /dev/null @@ -1,3 +0,0 @@ -from math import pi -r = float(input ("Input the radius of the circle : ")) -print ("The area of the circle with radius " + str(r) + " is: " + str(pi * r**2)) \ No newline at end of file diff --git a/python/_Basics/List all files in a directory in Python.py b/python/_Basics/List all files in a directory in Python.py deleted file mode 100644 index 98ea65b..0000000 --- a/python/_Basics/List all files in a directory in Python.py +++ /dev/null @@ -1,4 +0,0 @@ -from os import listdir -from os.path import isfile, join -files_list = [f for f in listdir('/home/students') if isfile(join('/home/students', f))] -print(files_list); \ No newline at end of file diff --git a/python/_Basics/Measure execution time.py b/python/_Basics/Measure execution time.py deleted file mode 100644 index 15d8192..0000000 --- a/python/_Basics/Measure execution time.py +++ /dev/null @@ -1,11 +0,0 @@ -import time -def sum_of_n_numbers(n): - start_time = time.time() - s = 0 - for i in range(1,n+1): - s = s + i - end_time = time.time() - return s,end_time-start_time - -n = 5 -print("\nTime to sum of 1 to ",n," and required time to calculate is :",sum_of_n_numbers(n)) \ No newline at end of file diff --git a/python/_Basics/Print first and last name in reverse order with a space between them.py b/python/_Basics/Print first and last name in reverse order with a space between them.py deleted file mode 100644 index 1deaca5..0000000 --- a/python/_Basics/Print first and last name in reverse order with a space between them.py +++ /dev/null @@ -1,3 +0,0 @@ -fname = input("Input your First Name : ") -lname = input("Input your Last Name : ") -print ("Hello " + lname + " " + fname) \ No newline at end of file diff --git a/python/_Basics/Program to add two numbers.py b/python/_Basics/Program to add two numbers.py deleted file mode 100644 index 90236ef..0000000 --- a/python/_Basics/Program to add two numbers.py +++ /dev/null @@ -1,10 +0,0 @@ -# This program adds two numbers - -num1 = 1.5 -num2 = 6.3 - -# Add two numbers -sum = float(num1) + float(num2) - -# Display the sum -print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) \ No newline at end of file diff --git a/python/_Basics/Program to calculate the square root.py b/python/_Basics/Program to calculate the square root.py deleted file mode 100644 index 32796f5..0000000 --- a/python/_Basics/Program to calculate the square root.py +++ /dev/null @@ -1,9 +0,0 @@ -# Python Program to calculate the square root - -# Note: change this value for a different result -num = 8 - -# uncomment to take the input from the user -#num = float(input('Enter a number: ')) -num_sqrt = num ** 0.5 -print('The square root of %0.3f is %0.3f'%(num ,num_sqrt)) \ No newline at end of file diff --git a/python/_Basics/Program to generate a random number between 0 and 9.py b/python/_Basics/Program to generate a random number between 0 and 9.py deleted file mode 100644 index 8bf1dde..0000000 --- a/python/_Basics/Program to generate a random number between 0 and 9.py +++ /dev/null @@ -1,6 +0,0 @@ -# Program to generate a random number between 0 and 9 - -# import the random module -import random - -print(random.randint(0,9)) \ No newline at end of file diff --git a/python/_Basics/Python Program To Display Powers of 2 Using Anonymous Function.py b/python/_Basics/Python Program To Display Powers of 2 Using Anonymous Function.py deleted file mode 100644 index e1c5564..0000000 --- a/python/_Basics/Python Program To Display Powers of 2 Using Anonymous Function.py +++ /dev/null @@ -1,29 +0,0 @@ -# Python Program to display the powers of 2 using anonymous function - -# Change this value for a different result -terms = 10 - -# Uncomment to take number of terms from user -#terms = int(input("How many terms? ")) - -# use anonymous function -result = list(map(lambda x: 2 ** x, range(terms))) - -# display the result - -print("The total terms is:",terms) -for i in range(terms): - print("2 raised to power",i,"is",result[i]) - - Output: - The total terms is: 10 -2 raised to power 0 is 1 -2 raised to power 1 is 2 -2 raised to power 2 is 4 -2 raised to power 3 is 8 -2 raised to power 4 is 16 -2 raised to power 5 is 32 -2 raised to power 6 is 64 -2 raised to power 7 is 128 -2 raised to power 8 is 256 -2 raised to power 9 is 512 \ No newline at end of file diff --git a/python/_Basics/Python Program to Add Two Matrices.py b/python/_Basics/Python Program to Add Two Matrices.py deleted file mode 100644 index 9cc8310..0000000 --- a/python/_Basics/Python Program to Add Two Matrices.py +++ /dev/null @@ -1,22 +0,0 @@ -# Program to add two matrices using nested loop - -X = [[12,7,3], - [4 ,5,6], - [7 ,8,9]] - -Y = [[5,8,1], - [6,7,3], - [4,5,9]] - -result = [[0,0,0], - [0,0,0], - [0,0,0]] - -# iterate through rows -for i in range(len(X)): - # iterate through columns - for j in range(len(X[0])): - result[i][j] = X[i][j] + Y[i][j] - -for r in result: - print(r) \ No newline at end of file diff --git a/python/_Basics/Python Program to Check Armstrong Number.py b/python/_Basics/Python Program to Check Armstrong Number.py deleted file mode 100644 index b805177..0000000 --- a/python/_Basics/Python Program to Check Armstrong Number.py +++ /dev/null @@ -1,20 +0,0 @@ -# Python program to check if the number provided by the user is an Armstrong number or not - -# take input from the user -# num = int(input("Enter a number: ")) - -# initialize sum -sum = 0 - -# find the sum of the cube of each digit -temp = num -while temp > 0: - digit = temp % 10 - sum += digit ** 3 - temp //= 10 - -# display the result -if num == sum: - print(num,"is an Armstrong number") -else: - print(num,"is not an Armstrong number") \ No newline at end of file diff --git a/python/_Basics/Python Program to Check Leap Year.py b/python/_Basics/Python Program to Check Leap Year.py deleted file mode 100644 index 0a463c3..0000000 --- a/python/_Basics/Python Program to Check Leap Year.py +++ /dev/null @@ -1,17 +0,0 @@ -# Python program to check if the input year is a leap year or not - -year = 2000 - -# To get year (integer input) from the user -# year = int(input("Enter a year: ")) - -if (year % 4) == 0: - if (year % 100) == 0: - if (year % 400) == 0: - print("{0} is a leap year".format(year)) - else: - print("{0} is not a leap year".format(year)) - else: - print("{0} is a leap year".format(year)) -else: - print("{0} is not a leap year".format(year)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Check Prime Number.py b/python/_Basics/Python Program to Check Prime Number.py deleted file mode 100644 index ac467de..0000000 --- a/python/_Basics/Python Program to Check Prime Number.py +++ /dev/null @@ -1,22 +0,0 @@ -# Python program to check if the input number is prime or not - -num = 407 - -# take input from the user -# num = int(input("Enter a number: ")) - -# prime numbers are greater than 1 -if num > 1: - # check for factors - for i in range(2,num): - if (num % i) == 0: - print(num,"is not a prime number") - print(i,"times",num//i,"is",num) - break - else: - print(num,"is a prime number") - -# if input number is less than -# or equal to 1, it is not prime -else: - print(num,"is not a prime number") \ No newline at end of file diff --git a/python/_Basics/Python Program to Check Whether a String is Palindrome or Not.py b/python/_Basics/Python Program to Check Whether a String is Palindrome or Not.py deleted file mode 100644 index f7f3134..0000000 --- a/python/_Basics/Python Program to Check Whether a String is Palindrome or Not.py +++ /dev/null @@ -1,17 +0,0 @@ -# Program to check if a string -# is palindrome or not - -# change this value for a different output -my_str = 'aIbohPhoBiA' - -# make it suitable for caseless comparison -my_str = my_str.casefold() - -# reverse the string -rev_str = reversed(my_str) - -# check if the string is equal to its reverse -if list(my_str) == list(rev_str): - print("It is palindrome") -else: - print("It is not palindrome") \ No newline at end of file diff --git a/python/_Basics/Python Program to Check if a Number is Odd or Even.py b/python/_Basics/Python Program to Check if a Number is Odd or Even.py deleted file mode 100644 index ad604f8..0000000 --- a/python/_Basics/Python Program to Check if a Number is Odd or Even.py +++ /dev/null @@ -1,5 +0,0 @@ -num = int(input("Enter a number: ")) -if (num % 2) == 0: - print("{0} is Even".format(num)) -else: - print("{0} is Odd".format(num)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Convert Celsius To Fahrenheit.py b/python/_Basics/Python Program to Convert Celsius To Fahrenheit.py deleted file mode 100644 index e7897f9..0000000 --- a/python/_Basics/Python Program to Convert Celsius To Fahrenheit.py +++ /dev/null @@ -1,8 +0,0 @@ -# Python Program to convert temperature in celsius to fahrenheit - -# change this value for a different result -celsius = 37.5 - -# calculate fahrenheit -fahrenheit = (celsius * 1.8) + 32 -print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Convert Decimal to Binary Using Recursion.py b/python/_Basics/Python Program to Convert Decimal to Binary Using Recursion.py deleted file mode 100644 index b8fead5..0000000 --- a/python/_Basics/Python Program to Convert Decimal to Binary Using Recursion.py +++ /dev/null @@ -1,11 +0,0 @@ -def convertToBinary(n): - """Function to print binary number - for the input decimal using recursion""" - if n > 1: - convertToBinary(n//2) - print(n % 2,end = '') - -# decimal number -dec = 34 - -convertToBinary(dec) \ No newline at end of file diff --git a/python/_Basics/Python Program to Convert Decimal to Binary, Octal and Hexadecimal.py b/python/_Basics/Python Program to Convert Decimal to Binary, Octal and Hexadecimal.py deleted file mode 100644 index 854a6ad..0000000 --- a/python/_Basics/Python Program to Convert Decimal to Binary, Octal and Hexadecimal.py +++ /dev/null @@ -1,9 +0,0 @@ -# Python program to convert decimal number into binary, octal and hexadecimal number system - -# Change this line for a different result -dec = 344 - -print("The decimal value of",dec,"is:") -print(bin(dec),"in binary.") -print(oct(dec),"in octal.") -print(hex(dec),"in hexadecimal.") \ No newline at end of file diff --git a/python/_Basics/Python Program to Convert Kilometers to Miles.py b/python/_Basics/Python Program to Convert Kilometers to Miles.py deleted file mode 100644 index e5cfb3a..0000000 --- a/python/_Basics/Python Program to Convert Kilometers to Miles.py +++ /dev/null @@ -1,11 +0,0 @@ -kilometers = 5.5 - -# To take kilometers from the user, uncomment the code below -kilometers = input("Enter value in kilometers") - -# conversion factor -conv_fac = 0.621371 - -# calculate miles -miles = kilometers * conv_fac -print('%0.3f kilometers is equal to %0.3f miles' %(kilometers,miles)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Count the Number of Each Vowel.py b/python/_Basics/Python Program to Count the Number of Each Vowel.py deleted file mode 100644 index be0b21b..0000000 --- a/python/_Basics/Python Program to Count the Number of Each Vowel.py +++ /dev/null @@ -1,23 +0,0 @@ -# Program to count the number of each vowel in a string - -# string of vowels -vowels = 'aeiou' - -# change this value for a different result -ip_str = 'Hello, have you tried our turorial section yet?' - -# uncomment to take input from the user -#ip_str = input("Enter a string: ") - -# make it suitable for caseless comparisions -ip_str = ip_str.casefold() - -# make a dictionary with each vowel a key and value 0 -count = {}.fromkeys(vowels,0) - -# count the vowels -for char in ip_str: - if char in count: - count[char] += 1 - -print(count) \ No newline at end of file diff --git a/python/_Basics/Python Program to Display Calendar.py b/python/_Basics/Python Program to Display Calendar.py deleted file mode 100644 index 09d3bc8..0000000 --- a/python/_Basics/Python Program to Display Calendar.py +++ /dev/null @@ -1,14 +0,0 @@ -# Python program to display calendar of given month of the year - -# import module -import calendar - -yy = 2014 -mm = 11 - -# To ask month and year from the user -# yy = int(input("Enter year: ")) -# mm = int(input("Enter month: ")) - -# display the calendar -print(calendar.month(yy, mm)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Display Fibonacci Sequence Using Recursion.py b/python/_Basics/Python Program to Display Fibonacci Sequence Using Recursion.py deleted file mode 100644 index feccb19..0000000 --- a/python/_Basics/Python Program to Display Fibonacci Sequence Using Recursion.py +++ /dev/null @@ -1,23 +0,0 @@ -# Python program to display the Fibonacci sequence up to n-th term using recursive functions - -def recur_fibo(n): - """Recursive function to - print Fibonacci sequence""" - if n <= 1: - return n - else: - return(recur_fibo(n-1) + recur_fibo(n-2)) - -# Change this value for a different result -nterms = 10 - -# uncomment to take input from the user -#nterms = int(input("How many terms? ")) - -# check if the number of terms is valid -if nterms <= 0: - print("Plese enter a positive integer") -else: - print("Fibonacci sequence:") - for i in range(nterms): - print(recur_fibo(i)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Display the multiplication Table.py b/python/_Basics/Python Program to Display the multiplication Table.py deleted file mode 100644 index c4fcaa8..0000000 --- a/python/_Basics/Python Program to Display the multiplication Table.py +++ /dev/null @@ -1,11 +0,0 @@ -''' Python program to find the -multiplication table (from 1 to 10)''' - -num = 12 - -# To take input from the user -# num = int(input("Display multiplication table of? ")) - -# use for loop to iterate 10 times -for i in range(1, 11): - print(num,'x',i,'=',num*i) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find ASCII Value of Character.py b/python/_Basics/Python Program to Find ASCII Value of Character.py deleted file mode 100644 index 1052ff8..0000000 --- a/python/_Basics/Python Program to Find ASCII Value of Character.py +++ /dev/null @@ -1,9 +0,0 @@ -# Program to find the ASCII value of the given character - -# Change this value for a different result -c = 'p' - -# Uncomment to take character from user -#c = input("Enter a character: ") - -print("The ASCII value of '" + c + "' is",ord(c)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find Armstrong Number in an Interval.py b/python/_Basics/Python Program to Find Armstrong Number in an Interval.py deleted file mode 100644 index 530a3f8..0000000 --- a/python/_Basics/Python Program to Find Armstrong Number in an Interval.py +++ /dev/null @@ -1,26 +0,0 @@ -# Program to check Armstrong numbers in certain interval - -lower = 100 -upper = 2000 - -# To take input from the user -# lower = int(input("Enter lower range: ")) -# upper = int(input("Enter upper range: ")) - -for num in range(lower, upper + 1): - - # order of number - order = len(str(num)) - - # initialize sum - sum = 0 - - # find the sum of the cube of each digit - temp = num - while temp > 0: - digit = temp % 10 - sum += digit ** order - temp //= 10 - - if num == sum: - print(num) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find Factorial of Number Using Recursion.py b/python/_Basics/Python Program to Find Factorial of Number Using Recursion.py deleted file mode 100644 index 3fb9da6..0000000 --- a/python/_Basics/Python Program to Find Factorial of Number Using Recursion.py +++ /dev/null @@ -1,23 +0,0 @@ -# Python program to find the factorial of a number using recursion - -def recur_factorial(n): - """Function to return the factorial - of a number using recursion""" - if n == 1: - return n - else: - return n*recur_factorial(n-1) - -# Change this value for a different result -num = 7 - -# uncomment to take input from the user -#num = int(input("Enter a number: ")) - -# check is the number is negative -if num < 0: - print("Sorry, factorial does not exist for negative numbers") -elif num == 0: - print("The factorial of 0 is 1") -else: - print("The factorial of",num,"is",recur_factorial(num)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find Factors of Number.py b/python/_Basics/Python Program to Find Factors of Number.py deleted file mode 100644 index 3ed6213..0000000 --- a/python/_Basics/Python Program to Find Factors of Number.py +++ /dev/null @@ -1,18 +0,0 @@ -# Python Program to find the factors of a number - -# define a function -def print_factors(x): - # This function takes a number and prints the factors - - print("The factors of",x,"are:") - for i in range(1, x + 1): - if x % i == 0: - print(i) - -# change this value for a different result. -num = 320 - -# uncomment the following line to take input from the user -#num = int(input("Enter a number: ")) - -print_factors(num) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find HCF or GCD.py b/python/_Basics/Python Program to Find HCF or GCD.py deleted file mode 100644 index cef7ef9..0000000 --- a/python/_Basics/Python Program to Find HCF or GCD.py +++ /dev/null @@ -1,26 +0,0 @@ -# Python program to find the H.C.F of two input number - -# define a function -def computerHCF(x, y): - """This function takes two - integers and returns the H.C.F""" - - # choose the smaller number - if x > y: - smaller = y - else: - smaller = x - - for i in range(1,smaller + 1): - if((x % i == 0) and (y % i == 0)): - hcf = i - return hcf - -num1 = 54 -num2 = 24 - -# take input from the user -# num1 = int(input("Enter first number: ")) -# num2 = int(input("Enter second number: ")) - -print("The H.C.F. of", num1,"and", num2,"is", computeHCF(num1, num2)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find Hash of File.py b/python/_Basics/Python Program to Find Hash of File.py deleted file mode 100644 index e79f80a..0000000 --- a/python/_Basics/Python Program to Find Hash of File.py +++ /dev/null @@ -1,27 +0,0 @@ -# Python rogram to find the SHA-1 message digest of a file - -# import hashlib module -import hashlib - -def hash_file(filename): - """"This function returns the SHA-1 hash - of the file passed into it""" - - # make a hash object - h = hashlib.sha1() - - # open file for reading in binary mode - with open(filename,'rb') as file: - - # loop till the end of the file - chunk = 0 - while chunk != b'': - # read only 1024 bytes at a time - chunk = file.read(1024) - h.update(chunk) - - # return the hex representation of digest - return h.hexdigest() - -message = hash_file("track1.mp3") -print(message) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find LCM.py b/python/_Basics/Python Program to Find LCM.py deleted file mode 100644 index fbba211..0000000 --- a/python/_Basics/Python Program to Find LCM.py +++ /dev/null @@ -1,30 +0,0 @@ -# Python Program to find the L.C.M. of two input number - -# define a function -def lcm(x, y): - """This function takes two - integers and returns the L.C.M.""" - - # choose the greater number - if x > y: - greater = x - else: - greater = y - - while(True): - if((greater % x == 0) and (greater % y == 0)): - lcm = greater - break - greater += 1 - - return lcm - -# change the values of num1 and num2 for a different result -num1 = 54 -num2 = 24 - -# uncomment the following lines to take input from the user -#num1 = int(input("Enter first number: ")) -#num2 = int(input("Enter second number: ")) - -print("The L.C.M. of", num1,"and", num2,"is", lcm(num1, num2)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find Numbers Divisible by Another Number.py b/python/_Basics/Python Program to Find Numbers Divisible by Another Number.py deleted file mode 100644 index 8ce9c45..0000000 --- a/python/_Basics/Python Program to Find Numbers Divisible by Another Number.py +++ /dev/null @@ -1,10 +0,0 @@ -# Python Program to find numbers divisible by thirteen from a list using anonymous function - -# Take a list of numbers -my_list = [12, 65, 54, 39, 102, 339, 221,] - -# use anonymous function to filter -result = list(filter(lambda x: (x % 13 == 0), my_list)) - -# display the result -print("Numbers divisible by 13 are",result) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find Sum of Natural Numbers Using Recursion.py b/python/_Basics/Python Program to Find Sum of Natural Numbers Using Recursion.py deleted file mode 100644 index c560063..0000000 --- a/python/_Basics/Python Program to Find Sum of Natural Numbers Using Recursion.py +++ /dev/null @@ -1,20 +0,0 @@ -# Python program to find the sum of natural numbers up to n using recursive function - -def recur_sum(n): - """Function to return the sum - of natural numbers using recursion""" - if n <= 1: - return n - else: - return n + recur_sum(n-1) - -# change this value for a different result -num = 16 - -# uncomment to take input from the user -#num = int(input("Enter a number: ")) - -if num < 0: - print("Enter a positive number") -else: - print("The sum is",recur_sum(num)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find the Factorial of a Number.py b/python/_Basics/Python Program to Find the Factorial of a Number.py deleted file mode 100644 index b5347e3..0000000 --- a/python/_Basics/Python Program to Find the Factorial of a Number.py +++ /dev/null @@ -1,19 +0,0 @@ -# Python program to find the factorial of a number provided by the user. - -# change the value for a different result -num = 7 - -# uncomment to take input from the user -#num = int(input("Enter a number: ")) - -factorial = 1 - -# check if the number is negative, positive or zero -if num < 0: - print("Sorry, factorial does not exist for negative numbers") -elif num == 0: - print("The factorial of 0 is 1") -else: - for i in range(1,num + 1): - factorial = factorial*i - print("The factorial of",num,"is",factorial) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find the Largest Among Three Numbers.py b/python/_Basics/Python Program to Find the Largest Among Three Numbers.py deleted file mode 100644 index b8d12e8..0000000 --- a/python/_Basics/Python Program to Find the Largest Among Three Numbers.py +++ /dev/null @@ -1,21 +0,0 @@ -# Python program to find the largest number among the three input numbers - -# change the values of num1, num2 and num3 -# for a different result -num1 = 10 -num2 = 14 -num3 = 12 - -# uncomment following lines to take three numbers from user -#num1 = float(input("Enter first number: ")) -#num2 = float(input("Enter second number: ")) -#num3 = float(input("Enter third number: ")) - -if (num1 > num2) and (num1 > num3): - largest = num1 -elif (num2 > num1) and (num2 > num3): - largest = num2 -else: - largest = num3 - -print("The largest number between",num1,",",num2,"and",num3,"is",largest) \ No newline at end of file diff --git a/python/_Basics/Python Program to Find the Size (Resolution) of Image.py b/python/_Basics/Python Program to Find the Size (Resolution) of Image.py deleted file mode 100644 index ff18f5c..0000000 --- a/python/_Basics/Python Program to Find the Size (Resolution) of Image.py +++ /dev/null @@ -1,26 +0,0 @@ - # Python Program to find the resolution of a jpeg image without using external libraries - - def jpeg_res(filename): - """"This function prints the resolution - of the jpeg image file passed into it""" - - # open image for reading in binary mode - with open(filename,'rb') as img_file: - - # height of image (in 2 bytes) is at 164th position - img_file.seek(163) - - # read the 2 bytes - a = img_file.read(2) - - # calculate height - height = (a[0] << 8) + a[1] - - # next 2 bytes is width - a = img_file.read(2) - - # calculate width - width = (a[0] << 8) + a[1] - - print("The resolution of the image is",width,"x",height) - jpeg_res("img1.jpg") \ No newline at end of file diff --git a/python/_Basics/Python Program to Find the Size (Resolution) of a Image.py b/python/_Basics/Python Program to Find the Size (Resolution) of a Image.py deleted file mode 100644 index c4d89e2..0000000 --- a/python/_Basics/Python Program to Find the Size (Resolution) of a Image.py +++ /dev/null @@ -1,24 +0,0 @@ -def jpeg_res(filename): - """"This function prints the resolution of the jpeg image file passed into it""" - - # open image for reading in binary mode - with open(filename,'rb') as img_file: - - # height of image (in 2 bytes) is at 164th position - img_file.seek(163) - - # read the 2 bytes - a = img_file.read(2) - - # calculate height - height = (a[0] << 8) + a[1] - - # next 2 bytes is width - a = img_file.read(2) - - # calculate width - width = (a[0] << 8) + a[1] - - print("The resolution of the image is",width,"x",height) - -jpeg_res("img1.jpg") \ No newline at end of file diff --git a/python/_Basics/Python Program to Find the Sum of Natural Numbers.py b/python/_Basics/Python Program to Find the Sum of Natural Numbers.py deleted file mode 100644 index a8efd63..0000000 --- a/python/_Basics/Python Program to Find the Sum of Natural Numbers.py +++ /dev/null @@ -1,17 +0,0 @@ -# Python program to find the sum of natural numbers up to n where n is provided by user - -# change this value for a different result -num = 16 - -# uncomment to take input from the user -#num = int(input("Enter a number: ")) - -if num < 0: - print("Enter a positive number") -else: - sum = 0 - # use while loop to iterate un till zero - while(num > 0): - sum += num - num -= 1 - print("The sum is",sum) \ No newline at end of file diff --git a/python/_Basics/Python Program to Illustrate Different Set Operations.py b/python/_Basics/Python Program to Illustrate Different Set Operations.py deleted file mode 100644 index f3b27e2..0000000 --- a/python/_Basics/Python Program to Illustrate Different Set Operations.py +++ /dev/null @@ -1,17 +0,0 @@ -# Program to perform different set operations like in mathematics - -# define three sets -E = {0, 2, 4, 6, 8}; -N = {1, 2, 3, 4, 5}; - -# set union -print("Union of E and N is",E | N) - -# set intersection -print("Intersection of E and N is",E & N) - -# set difference -print("Difference of E and N is",E - N) - -# set symmetric difference -print("Symmetric difference of E and N is",E ^ N) \ No newline at end of file diff --git a/python/_Basics/Python Program to Make a Simple Calculator.py b/python/_Basics/Python Program to Make a Simple Calculator.py deleted file mode 100644 index 41aa2e3..0000000 --- a/python/_Basics/Python Program to Make a Simple Calculator.py +++ /dev/null @@ -1,44 +0,0 @@ -''' Program make a simple calculator that can add, subtract, multiply and divide using functions ''' - -# define functions -def add(x, y): - """This function adds two numbers""" - return x + y - -def subtract(x, y): - """This function subtracts two numbers""" - return x - y - -def multiply(x, y): - """This function multiplies two numbers""" - return x * y - -def divide(x, y): - """This function divides two numbers""" - return x / y - -# take input from the user -print("Select operation.") -print("1.Add") -print("2.Subtract") -print("3.Multiply") -print("4.Divide") - -choice = input("Enter choice(1/2/3/4):") - -num1 = int(input("Enter first number: ")) -num2 = int(input("Enter second number: ")) - -if choice == '1': - print(num1,"+",num2,"=", add(num1,num2)) - -elif choice == '2': - print(num1,"-",num2,"=", subtract(num1,num2)) - -elif choice == '3': - print(num1,"*",num2,"=", multiply(num1,num2)) - -elif choice == '4': - print(num1,"/",num2,"=", divide(num1,num2)) -else: - print("Invalid input") \ No newline at end of file diff --git a/python/_Basics/Python Program to Merge Mails.py b/python/_Basics/Python Program to Merge Mails.py deleted file mode 100644 index 08b1a26..0000000 --- a/python/_Basics/Python Program to Merge Mails.py +++ /dev/null @@ -1,20 +0,0 @@ -# Python program to mail merger -# Names are in the file names.txt -# Body of the mail is in body.txt - -# open names.txt for reading -with open("names.txt",'r',encoding = 'utf-8') as names_file: - - # open body.txt for reading - with open("body.txt",'r',encoding = 'utf-8') as body_file: - - # read entire content of the body - body = body_file.read() - - # iterate over names - for name in names_file: - mail = "Hello "+name+body - - # write the mails to individual files - with open(name.strip()+".txt",'w',encoding = 'utf-8') as mail_file: - mail_file.write(mail) \ No newline at end of file diff --git a/python/_Basics/Python Program to Multiply Two Matrices.py b/python/_Basics/Python Program to Multiply Two Matrices.py deleted file mode 100644 index d0a0cf2..0000000 --- a/python/_Basics/Python Program to Multiply Two Matrices.py +++ /dev/null @@ -1,25 +0,0 @@ -# Program to multiply two matrices using nested loops - -# 3x3 matrix -X = [[12,7,3], - [4 ,5,6], - [7 ,8,9]] -# 3x4 matrix -Y = [[5,8,1,2], - [6,7,3,0], - [4,5,9,1]] -# result is 3x4 -result = [[0,0,0,0], - [0,0,0,0], - [0,0,0,0]] - -# iterate through rows of X -for i in range(len(X)): - # iterate through columns of Y - for j in range(len(Y[0])): - # iterate through rows of Y - for k in range(len(Y)): - result[i][j] += X[i][k] * Y[k][j] - -for r in result: - print(r) \ No newline at end of file diff --git a/python/_Basics/Python Program to Print all Prime Numbers in an Interval.py b/python/_Basics/Python Program to Print all Prime Numbers in an Interval.py deleted file mode 100644 index 3eb7fc8..0000000 --- a/python/_Basics/Python Program to Print all Prime Numbers in an Interval.py +++ /dev/null @@ -1,20 +0,0 @@ -# Python program to display all the prime numbers within an interval - -# change the values of lower and upper for a different result -lower = 900 -upper = 1000 - -# uncomment the following lines to take input from the user -#lower = int(input("Enter lower range: ")) -#upper = int(input("Enter upper range: ")) - -print("Prime numbers between",lower,"and",upper,"are:") - -for num in range(lower,upper + 1): - # prime numbers are greater than 1 - if num > 1: - for i in range(2,num): - if (num % i) == 0: - break - else: - print(num) \ No newline at end of file diff --git a/python/_Basics/Python Program to Print the Fibonacci sequence.py b/python/_Basics/Python Program to Print the Fibonacci sequence.py deleted file mode 100644 index 4a7285c..0000000 --- a/python/_Basics/Python Program to Print the Fibonacci sequence.py +++ /dev/null @@ -1,29 +0,0 @@ -# Program to display the Fibonacci sequence up to n-th term where n is provided by the user - -# change this value for a different result -nterms = 10 - -# uncomment to take input from the user -#nterms = int(input("How many terms? ")) - -# first two terms -n1 = 0 -n2 = 1 -count = 2 - -# check if the number of terms is valid -if nterms <= 0: - print("Please enter a positive integer") -elif nterms == 1: - print("Fibonacci sequence upto",nterms,":") - print(n1) -else: - print("Fibonacci sequence upto",nterms,":") - print(n1,",",n2,end=', ') - while count < nterms: - nth = n1 + n2 - print(nth,end=' , ') - # update values - n1 = n2 - n2 = nth - count += 1 \ No newline at end of file diff --git a/python/_Basics/Python Program to Remove Punctuations From a String.py b/python/_Basics/Python Program to Remove Punctuations From a String.py deleted file mode 100644 index 51c8b93..0000000 --- a/python/_Basics/Python Program to Remove Punctuations From a String.py +++ /dev/null @@ -1,16 +0,0 @@ -# define punctuation -punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~''' - -my_str = "Hello!!!, he said ---and went." - -# To take input from the user -# my_str = input("Enter a string: ") - -# remove punctuation from the string -no_punct = "" -for char in my_str: - if char not in punctuations: - no_punct = no_punct + char - -# display the unpunctuated string -print(no_punct) \ No newline at end of file diff --git a/python/_Basics/Python Program to Shuffle Deck of Cards.py b/python/_Basics/Python Program to Shuffle Deck of Cards.py deleted file mode 100644 index 64864d3..0000000 --- a/python/_Basics/Python Program to Shuffle Deck of Cards.py +++ /dev/null @@ -1,15 +0,0 @@ -# Python program to shuffle a deck of card using the module random and draw 5 cards - -# import modules -import itertools, random - -# make a deck of cards -deck = list(itertools.product(range(1,14),['Spade','Heart','Diamond','Club'])) - -# shuffle the cards -random.shuffle(deck) - -# draw five cards -print("You got:") -for i in range(5): - print(deck[i][0], "of", deck[i][1]) \ No newline at end of file diff --git a/python/_Basics/Python Program to Solve the quadratic equation.py b/python/_Basics/Python Program to Solve the quadratic equation.py deleted file mode 100644 index 87424b8..0000000 --- a/python/_Basics/Python Program to Solve the quadratic equation.py +++ /dev/null @@ -1,22 +0,0 @@ -# Solve the quadratic equation ax**2 + bx + c = 0 - -# import complex math module -import cmath - -a = 1 -b = 5 -c = 6 - -# To take coefficient input from the users -# a = float(input('Enter a: ')) -# b = float(input('Enter b: ')) -# c = float(input('Enter c: ')) - -# calculate the discriminant -d = (b**2) - (4*a*c) - -# find two solutions -sol1 = (-b-cmath.sqrt(d))/(2*a) -sol2 = (-b+cmath.sqrt(d))/(2*a) - -print('The solution are {0} and {1}'.format(sol1,sol2)) \ No newline at end of file diff --git a/python/_Basics/Python Program to Sort Words in Alphabetic Order.py b/python/_Basics/Python Program to Sort Words in Alphabetic Order.py deleted file mode 100644 index 11f6db9..0000000 --- a/python/_Basics/Python Program to Sort Words in Alphabetic Order.py +++ /dev/null @@ -1,19 +0,0 @@ -# Program to sort alphabetically the words form a string provided by the user - -# change this value for a different result -my_str = "Hello this Is an Example With cased letters" - -# uncomment to take input from the user -#my_str = input("Enter a string: ") - -# breakdown the string into a list of words -words = my_str.split() - -# sort the list -words.sort() - -# display the sorted words - -print("The sorted words are:") -for word in words: - print(word) \ No newline at end of file diff --git a/python/_Basics/Python Program to Transpose a Matrix.py b/python/_Basics/Python Program to Transpose a Matrix.py deleted file mode 100644 index 623d8ef..0000000 --- a/python/_Basics/Python Program to Transpose a Matrix.py +++ /dev/null @@ -1,17 +0,0 @@ -# Program to transpose a matrix using nested loop - -X = [[12,7], - [4 ,5], - [3 ,8]] - -result = [[0,0,0], - [0,0,0]] - -# iterate through rows -for i in range(len(X)): - # iterate through columns - for j in range(len(X[0])): - result[j][i] = X[i][j] - -for r in result: - print(r) \ No newline at end of file diff --git a/python/_Basics/Python Program to find the area of triangle.py b/python/_Basics/Python Program to find the area of triangle.py deleted file mode 100644 index cf34cf0..0000000 --- a/python/_Basics/Python Program to find the area of triangle.py +++ /dev/null @@ -1,17 +0,0 @@ -# Python Program to find the area of triangle - -a = 5 -b = 6 -c = 7 - -# Uncomment below to take inputs from the user -# a = float(input('Enter first side: ')) -# b = float(input('Enter second side: ')) -# c = float(input('Enter third side: ')) - -# calculate the semi-perimeter -s = (a + b + c) / 2 - -# calculate the area -area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 -print('The area of the triangle is %0.2f' %area) \ No newline at end of file diff --git a/python/_Basics/Python program that accepts a comma separated sequence of words as input and prints the unique words in sorted form (alphanumerically).py b/python/_Basics/Python program that accepts a comma separated sequence of words as input and prints the unique words in sorted form (alphanumerically).py deleted file mode 100644 index 7d99aaa..0000000 --- a/python/_Basics/Python program that accepts a comma separated sequence of words as input and prints the unique words in sorted form (alphanumerically).py +++ /dev/null @@ -1,3 +0,0 @@ -items = input("Input comma separated sequence of words") -words = [word for word in items.split(",")] -print(",".join(sorted(list(set(words))))) \ No newline at end of file diff --git a/python/_Basics/Python program to count the number of characters (character frequency) in a string.py b/python/_Basics/Python program to count the number of characters (character frequency) in a string.py deleted file mode 100644 index 1890f8f..0000000 --- a/python/_Basics/Python program to count the number of characters (character frequency) in a string.py +++ /dev/null @@ -1,10 +0,0 @@ -def char_frequency(str1): - dict = {} - for n in str1: - keys = dict.keys() - if n in keys: - dict[n] += 1 - else: - dict[n] = 1 - return dict -print(char_frequency('google.com')) \ No newline at end of file diff --git a/python/_Basics/Python program to count the occurrences of each word in a given sentence.py b/python/_Basics/Python program to count the occurrences of each word in a given sentence.py deleted file mode 100644 index a994916..0000000 --- a/python/_Basics/Python program to count the occurrences of each word in a given sentence.py +++ /dev/null @@ -1,13 +0,0 @@ -def word_count(str): - counts = dict() - words = str.split() - - for word in words: - if word in counts: - counts[word] += 1 - else: - counts[word] = 1 - - return counts - -print( word_count('the quick brown fox jumps over the lazy dog.')) \ No newline at end of file diff --git a/python/_Basics/Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself.py b/python/_Basics/Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself.py deleted file mode 100644 index e33d485..0000000 --- a/python/_Basics/Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself.py +++ /dev/null @@ -1,9 +0,0 @@ -def change_char(str1): - char = str1[0] - length = len(str1) - str1 = str1.replace(char, '$') - str1 = char + str1[1:] - - return str1 - -print(change_char('restart')) \ No newline at end of file diff --git a/python/_Basics/Python program to get a string made of the first 2 and the last 2 chars from a given a string.py b/python/_Basics/Python program to get a string made of the first 2 and the last 2 chars from a given a string.py deleted file mode 100644 index 350c517..0000000 --- a/python/_Basics/Python program to get a string made of the first 2 and the last 2 chars from a given a string.py +++ /dev/null @@ -1,9 +0,0 @@ -def string_both_ends(str): - if len(str) < 2: - return '' - - return str[0:2] + str[-2:] - -print(string_both_ends('w3resource')) -print(string_both_ends('w3')) -print(string_both_ends('w')) \ No newline at end of file diff --git a/python/_Basics/Python program to get the the volume of a sphere with radius 6.py b/python/_Basics/Python program to get the the volume of a sphere with radius 6.py deleted file mode 100644 index f720644..0000000 --- a/python/_Basics/Python program to get the the volume of a sphere with radius 6.py +++ /dev/null @@ -1,4 +0,0 @@ -pi = 3.1415926535897931 -r= 6.0 -V= 4.0/3.0*pi* r**3 -print('The volume of the sphere is: ',V) \ No newline at end of file diff --git a/python/_Basics/Python program to swap two variables.py b/python/_Basics/Python program to swap two variables.py deleted file mode 100644 index 0716dce..0000000 --- a/python/_Basics/Python program to swap two variables.py +++ /dev/null @@ -1,16 +0,0 @@ -# Python program to swap two variables - -# To take input from the user -# x = input('Enter value of x: ') -# y = input('Enter value of y: ') - -x = 5 -y = 10 - -# create a temporary variable and swap the values -temp = x -x = y -y = temp - -print('The value of x after swapping: {}'.format(x)) -print('The value of y after swapping: {}'.format(y)) \ No newline at end of file diff --git a/python/_Basics/Python script that takes input from the user and displays that input back in upper and lower cases.py b/python/_Basics/Python script that takes input from the user and displays that input back in upper and lower cases.py deleted file mode 100644 index 2961a85..0000000 --- a/python/_Basics/Python script that takes input from the user and displays that input back in upper and lower cases.py +++ /dev/null @@ -1,3 +0,0 @@ -user_input = input("What's your favourite language? ") -print("My favourite language is ", user_input.upper()) -print("My favourite language is ", user_input.lower()) \ No newline at end of file diff --git a/python/_Basics/Return true if the two given int values are equal or their sum or difference is 5.py b/python/_Basics/Return true if the two given int values are equal or their sum or difference is 5.py deleted file mode 100644 index 9804503..0000000 --- a/python/_Basics/Return true if the two given int values are equal or their sum or difference is 5.py +++ /dev/null @@ -1,9 +0,0 @@ -def test_number5(x, y): - if x == 5 or y == 5 or abs(x-y) == 5 or (x+y) == 5: - return True - else: - return False - -print(test_number5(7, 2)) -print(test_number5(3, 2)) -print(test_number5(2, 2)) \ No newline at end of file diff --git a/python/_Basics/Sort files by date.py b/python/_Basics/Sort files by date.py deleted file mode 100644 index 7bc0e36..0000000 --- a/python/_Basics/Sort files by date.py +++ /dev/null @@ -1,6 +0,0 @@ -import glob -import os - -files = glob.glob("*.txt") -files.sort(key=os.path.getmtime) -print("\n".join(files)) \ No newline at end of file diff --git a/python/_Basics/Sum of the first n positive integers.py b/python/_Basics/Sum of the first n positive integers.py deleted file mode 100644 index 813573e..0000000 --- a/python/_Basics/Sum of the first n positive integers.py +++ /dev/null @@ -1,3 +0,0 @@ -n = int(input("Input a number: ")) -sum_num = (n * (n + 1)) / 2 -print(sum_num) \ No newline at end of file diff --git a/python/_Basics/Test whether a number is within 100 of 1000 or 2000.py b/python/_Basics/Test whether a number is within 100 of 1000 or 2000.py deleted file mode 100644 index 606450e..0000000 --- a/python/_Basics/Test whether a number is within 100 of 1000 or 2000.py +++ /dev/null @@ -1,6 +0,0 @@ -def near_thousand(n): - return ((abs(1000 - n) <= 100) or (abs(2000 - n) <= 100)) -print(near_thousand(1000)) -print(near_thousand(900)) -print(near_thousand(800)) -print(near_thousand(2200)) \ No newline at end of file diff --git a/python/_Basics/Test whether a passed letter is a vowel or not.py b/python/_Basics/Test whether a passed letter is a vowel or not.py deleted file mode 100644 index f6d659a..0000000 --- a/python/_Basics/Test whether a passed letter is a vowel or not.py +++ /dev/null @@ -1,5 +0,0 @@ -def is_vowel(char): - all_vowels = 'aeiou' - return char in all_vowels -print(is_vowel('c')) -print(is_vowel('e')) \ No newline at end of file diff --git a/ruby/_Basics/CheckForPowerOfTwo.rb b/ruby/_Basics/CheckForPowerOfTwo.rb deleted file mode 100644 index 340c5eb..0000000 --- a/ruby/_Basics/CheckForPowerOfTwo.rb +++ /dev/null @@ -1,13 +0,0 @@ -#Given a number,check if it is power of 2 or not without using division or modulo operator. -#Algorithm: For any power of 2,say x, the bitwise and of x and x-1 is always 0. -#e.g. 64 = 1000000, 63= 0111111 now 1000000&0111111==0000000 - -def check_power(x) - if x&(x-1)==0 - print "#{x} is power of two" - else - print "#{x} is not power of two" - end -end -check_power(126) # => 126 is not power of two -check_power(1024) # => 1024 is power of two \ No newline at end of file diff --git a/ruby/_Basics/CheckIFEvenOrOdd.rb b/ruby/_Basics/CheckIFEvenOrOdd.rb deleted file mode 100644 index fedfdf3..0000000 --- a/ruby/_Basics/CheckIFEvenOrOdd.rb +++ /dev/null @@ -1,12 +0,0 @@ -#Given a number,check if it is even or odd using bit operations. -#Algorithm: let num be x -#find x&1 ,if result is 0 then even else odd. -#The Least significant bit of odd number is always 1 and even is always 0,hence x&1 will be 0 if even else odd. - -def check_evenOdd(x) - if x&1==0 - print "#{x} is even" - else - print "#{x} is odd" - end -end \ No newline at end of file diff --git a/ruby/_Basics/CountSetBits.rb b/ruby/_Basics/CountSetBits.rb deleted file mode 100644 index 0cfd13b..0000000 --- a/ruby/_Basics/CountSetBits.rb +++ /dev/null @@ -1,12 +0,0 @@ -#Given a number "n",count the number of set bits in it. -#Algorithm: Brian Kernighan's method(set count=0 ,while n>0 set n:=n&(n-1) and increment count, return count) -#Time-complexity:O(logn) - -def count_set_bits(num) - count=0 - while num>0 - num&=(num-1) - count+=1 - end - return count -end \ No newline at end of file diff --git a/ruby/_Basics/UnsetRightmostSetBit.rb b/ruby/_Basics/UnsetRightmostSetBit.rb deleted file mode 100644 index b823b33..0000000 --- a/ruby/_Basics/UnsetRightmostSetBit.rb +++ /dev/null @@ -1,8 +0,0 @@ -#Given a binary number unset the rightmost set bit. -#Algorithm: The biwise "&" of any number n with n-1 unsets the rightmost set bit -#e.g. 5=101 ,5-1=4=100 ,5&4=(101)&(100)=100(result with rightmost bit unset) - -def unset_rightmost(n) - return n&(n-1) -end -unset_rightmost(3) # => 2 \ No newline at end of file diff --git a/ruby/_Basics/auth.rb b/ruby/_Basics/auth.rb deleted file mode 100644 index ee22bdd..0000000 --- a/ruby/_Basics/auth.rb +++ /dev/null @@ -1,45 +0,0 @@ -require "csv" -require "logger" - -class AuthenticationError < StandardError -end - -class User - attr_reader :username - attr_reader :password - - def initialize(username, password) - raise ArgumentError unless /^[A-Za-z0-9_-]{3,16}$/.match(username) - raise ArgumentError unless /^[A-Za-z0-9!@#$%^&*()_+-=]{6,16}$/.match(password) - @username = username - @password = password - end -end - -class Application - def initialize - @logger = Logger.new(STDOUT) - @users = {} - @is_authenticated = false - end - - def load_users(filename) - # Your code goes here - end - - def login - until @is_authenticated - # Your code goes here - end - - @logger.info("Login successful!") - end - - def run - login - end -end - -application = Application.new -application.load_users("users.csv") -application.run diff --git a/ruby/_Basics/basic_game.rb b/ruby/_Basics/basic_game.rb deleted file mode 100644 index c7edc56..0000000 --- a/ruby/_Basics/basic_game.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Player - # Your code goes here -end - -class Game - # Your code goes here -end - -game = Game.new("RPS") - -players = [ - Player.new("John"), - Player.new("Lizzy"), - Player.new("Clair"), - Player.new("Brad"), - 15 -] - -players.each { |player| game.add_player(player) } diff --git a/ruby/_Basics/card_deck.rb b/ruby/_Basics/card_deck.rb deleted file mode 100644 index aa68fb2..0000000 --- a/ruby/_Basics/card_deck.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Create a standard 52 card deck -# Sort card suits according to Hearts, Diamonds, Clubs, then Spades. -# Sort cards in ascending order, from 2 to Ace. - -def create_deck - # Your code goes here -end - - -card_deck = create_deck - -puts card_deck[0] == "2h" # 2 of Hearts -puts card_deck[8] == "10h" # 10 of Hearts -puts card_deck[51] == "As" # Ace of Spades diff --git a/ruby/_Basics/dependency_inversion.rb b/ruby/_Basics/dependency_inversion.rb deleted file mode 100644 index 196e16c..0000000 --- a/ruby/_Basics/dependency_inversion.rb +++ /dev/null @@ -1,48 +0,0 @@ -# The Dependency Inversion Principle has to do with high-level (think business -# logic) objects not depending on low-level (think database querying and IO) -# implementation details. This can be achieved with duck typing and the -# Dependency Inversion Principle. Often this pattern is used to achieve the -# Open/Closed Principle that we discussed above. In fact, we can even reuse -# that same example as a demonstration of this principle. - -# Now there is a formatter class, but I've hardcoded it on the Report class, -# thus creating a dependency from the Report to the JSONFormatter. Since the -# Report is a more abstract (high-level) concept than the JSONFormatter, we're -# effectively breaking the DIP. - -class Report - def body - # Implementation - end - - def print - JSONFormatter.new.format(body) - end -end - -class JSONFormatter - def format(body) - # Implementation - end -end - -# Solution - -# This way the Report does not depend on the JSONFormatter and can use any type -# of formatter that has a method called format (this is known as duck typing). -# Another thing of note is that we've used, once again, dependency injection to -# solve a problem. This technique is a very powerful one when our goal is -# decoupling objects, and even though it has the same initials as the dependency -# inversion principle (vs dependency injection pattern), they are completely -# different concepts. - -class Report - def body - # Implementation - end - - def print(formatter: JSONFormatter.new) - formatter.format body - end -end - diff --git a/ruby/_Basics/family.rb b/ruby/_Basics/family.rb deleted file mode 100644 index b20700e..0000000 --- a/ruby/_Basics/family.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Ages of family members -mom = 48 -dad = 51 -john = 18 -mary = 16 - -# Your code goes here - diff --git a/ruby/_Basics/fibers.rb b/ruby/_Basics/fibers.rb deleted file mode 100644 index be1bad3..0000000 --- a/ruby/_Basics/fibers.rb +++ /dev/null @@ -1,22 +0,0 @@ -# Fibers are primitives for implementing light weight cooperative concurrency in -# Ruby. Basically they are a means of creating code blocks that can be paused -# and resumed, much like threads. The main difference is that they are never -# preempted and that the scheduling must be done by the programmer and not the VM. - -require 'fiber' - -f = Fiber.new do |value| - first = value - puts "first call fiber with args: #{first ? first : 'not passed'}" - second = Fiber.yield - puts "second call fiber with args: #{second ? second : 'not passed'}" - other = Fiber.yield - puts "First: #{first}, Second: #{second}, Other: #{other ? other : 'not passed'}" - puts "Last call" -end - -f.resume('First argument') -f.resume('Second argument') -f.resume -# f.resume call error if try call one more time fiber is dead - diff --git a/ruby/_Basics/fibonacci.rb b/ruby/_Basics/fibonacci.rb deleted file mode 100644 index a81c6fa..0000000 --- a/ruby/_Basics/fibonacci.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Print out all the Fibonacci numbers from 1 to 10 in order - -# Your code goes here - diff --git a/ruby/_Basics/fighter.rb b/ruby/_Basics/fighter.rb deleted file mode 100644 index 4cee2d4..0000000 --- a/ruby/_Basics/fighter.rb +++ /dev/null @@ -1,23 +0,0 @@ -require "logger" -require_relative "mixins" - -module Logging - # Provided for your convenience - def logger - Logging.logger - end - - def self.logger - @logger ||= Logger.new(STDOUT) - end -end - -class Fighter - # Your code goes here -end - -fighter = Fighter.new("Bruce Lee") -fighter.uppercut -fighter.block -fighter.riposte -fighter.straight_kick diff --git a/ruby/_Basics/game_rankings.rb b/ruby/_Basics/game_rankings.rb deleted file mode 100644 index e3fab17..0000000 --- a/ruby/_Basics/game_rankings.rb +++ /dev/null @@ -1,17 +0,0 @@ -# Top 10 Nintendo 64 games from Gamerankings - -game_rankings = { - "The Legend of Zelda: Ocarina of Time" => 0.9754, - "Super Mario 64" => 0.9641, - "GoldenEye 007" => 0.9470, - "Perfect Dark" => 0.9455, - "The Legend of Zelda: Majora's Mask" => 0.9195, - "1080: TenEighty Snowboarding" => 0.8960, - "Conker's Bad Fur Day" => 0.8928, - "Excitebike 64" => 0.8907, - "Turok 2: Seeds of Evil" => 0.8896, - "Paper Mario" => 0.8881 -} - -# Your code goes here - diff --git a/ruby/_Basics/gil.rb b/ruby/_Basics/gil.rb deleted file mode 100644 index a167168..0000000 --- a/ruby/_Basics/gil.rb +++ /dev/null @@ -1,25 +0,0 @@ -# This simple fact is what makes threads so powerful, and also what makes them -# difficult to work with. I've already given you an idea of why threads are -# good; here's a simple program to illustrate their difficulty. - -shared_array = Array.new - -10.times.map do - Thread.new do - 1000.times do - shared_array << nil - end - end -end.each(&:join) - -# Here you can see that we have 10 * 10000 elements in array - -puts shared_array.size - -# Note that different ruby can show different result -# GIL exist only in MRI ruby - -# $ruby => 10000 -#$ jruby => 7521 -# $rbx => 8541 - diff --git a/ruby/_Basics/inheritance robots.rb b/ruby/_Basics/inheritance robots.rb deleted file mode 100644 index 7f1ef4a..0000000 --- a/ruby/_Basics/inheritance robots.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Robot - # Your code goes here -end - -class Ultron < Robot - # Your code goes here -end - -class MegaMan < Robot - # Your code goes here -end - -class Glados < Robot - # Your code goes here -end diff --git a/ruby/_Basics/interface_segregation.rb b/ruby/_Basics/interface_segregation.rb deleted file mode 100644 index d2c990b..0000000 --- a/ruby/_Basics/interface_segregation.rb +++ /dev/null @@ -1,96 +0,0 @@ -# The principle states that a client should not be forced to depend on methods -# that it does not use - -# In this example, there are Computer, Programmer and Technician classes. Both, -# Programmer and Technician use the Computer in a different way. The programmer -# uses the computer for typing, but the technician knows how to change the -# computer hard drive. What Interface Segregation Principle (ISP) enforces is -# that one class should not depend on methods it does not use. -# In our case, Programmer is unnecessarily coupled to the -# Computer#change_hard_drive method because it does not use it, but the state -# changes that this method enforces can affect the Programmer. Let's refactor -# the code to obey the LSP. - -class Computer - def turn_on - # Implementation - end - - def type - # Implementation - end - - def change_hard_drive - # Implementation - end -end - -class User - attr_reader :computer - - def initialize(computer) - @computer = computer - end -end - -class Programmer < User - def use_computer - computer.turn_on - computer.type - end -end - -class Technician < User - def fix_computer - computer.change_hard_drive - end -end - -# Solution - -# After this refactor the Technician uses a different object from the type -# ComputerInternals which is isolated from the state of the Computer. The state -# of the Computer object can be influenced by the Programmer but the changes -# wont affect the Technician in any way. - -class Computer - def turn_on - # Implementation - end - - def type - # Implementation - end -end - -class ComputerInternals - def change_hard_drive - # Implementation - end -end - -class Programmer - attr_reader :computer - - def initialize(computer) - @computer = computer - end - - def use_computer - computer.turn_on - computer.type - end -end - -class Technician - attr_reader :computer_internals - - def initialize(computer_internals) - @computer_internals = computer_internals - end - - def fix_computer - computer_internals.change_hard_drive - end -end - diff --git a/ruby/_Basics/liskov_substitution.rb b/ruby/_Basics/liskov_substitution.rb deleted file mode 100644 index 2293448..0000000 --- a/ruby/_Basics/liskov_substitution.rb +++ /dev/null @@ -1,82 +0,0 @@ -# Liskov’s principle tends to be the most difficult to understand. The principle -# states that you should be able to replace any instances of a parent class -# with an instance of one of its children without creating any unexpected or -# incorrect behaviors. - -class Rectangle - def initialize(height, width) - @height = height - @width = width - end - - def set_height(height) - @height = height - end - - def set_width(width) - @width = width - end - - def square - @width * @height - end -end - -# Solution - -# LSP says is if we know the interface of Rectangle, We need to be able to guess -# the interface of subtype class Square -# Square.new(3).square => 9 - -class Square < Rectangle - def initialize(side) - super(side, side) - end - - def set_height(height) - super(height) - @width = height - end - - def set_width(width) - super(width) - @height = width - end -end - -# Another common instance of a Liskov violation is raising an exception for an -# overridden method in a child class. It’s also not uncommon to see methods -# overridden with modified method signatures causing branching on type in -# classes that depend on objects of the parent’s type. All of these either -# lead to unstable code or unnecessary and ugly branching. - -class Animal - def walk - 'walking_as_animal' - end -end - -class Cat < Animal - def run - 'run_as_cat' - end -end - -# Solution - -class Animal - def walk - 'walking_as_animal' - end - - def run - raise NotImplementedError - end -end - -class Cat < Animal - def run - 'run_as_cat' - end -end - diff --git a/ruby/_Basics/mixins.rb b/ruby/_Basics/mixins.rb deleted file mode 100644 index 964f537..0000000 --- a/ruby/_Basics/mixins.rb +++ /dev/null @@ -1,15 +0,0 @@ -module WingChunMixin - # Your code goes here -end - -module BoxingMixin - # Your code goes here -end - -module FencingMixin - # Your code goes here -end - -module JeetKuneDoMixin - # Your code goes here -end diff --git a/ruby/_Basics/mutex.rb b/ruby/_Basics/mutex.rb deleted file mode 100644 index c3acd6b..0000000 --- a/ruby/_Basics/mutex.rb +++ /dev/null @@ -1,46 +0,0 @@ -# Mutexes provide a mechanism for multiply threads to synchronize access to a -# critical portion of code. It helps bring some order and some guaranty to the -# world of multi-threaded chaos. -# In this program, since any thread has to lock the mutex before it can push to -# the Array, there's a guarantee that no two threads will be performing this -# operation at the same time. In other words, this operation can no longer be -# interrupted before it's completed. Once one thread begins pushing to the -# Array, no other threads will be able to enter that portion of code until the -# first thread is finished. This operation is now thread-safe. - -shared_array = Array.new -# Notice that the mutex is shared among all the threads. The guarantee only -# works if the threads are sharing the same Mutex instance. In this way, when -# one thread locks a mutex, others have to wait for it to be unlocked. -mutex = Mutex.new - -10.times.map do - Thread.new do - 1000.times do - # Thread lock mutex and become owner, could be one one owner - # Now only one thread can run wrapper code and update - mutex.lock - shared_array << nil - mutex.unlock - # After unlock mutex other threads can lock mutex - - # Other convenience method to do same - # mutex.synchronize { shared_array << nil } - end - end -end.each(&:join) - -# Here you can see that we have 10 * 10000 elements in array - -puts shared_array.size - -# Now all are same, because of mutex/ -# The mutex sets up same boundaries for the thread. The first thread that hits -# this bit of code will lock the mutex. it then becomes the owner of that mutex. -# Until the owning thread unlocks the mutex, no other thread can lock it. - - -#$ ruby => 10000 -# $jruby => 10000 -#$ rbx => 1000 - diff --git a/ruby/_Basics/names.rb b/ruby/_Basics/names.rb deleted file mode 100644 index e360f0d..0000000 --- a/ruby/_Basics/names.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Game of Thrones characters -name1 = "Joffrey Baratheon" -name2 = "Arya Stark" -name3 = "Beric Dondarrion" -name4 = "Melisandre" - -# Your code goes here - diff --git a/ruby/_Basics/netflix.rb b/ruby/_Basics/netflix.rb deleted file mode 100644 index 494c8c9..0000000 --- a/ruby/_Basics/netflix.rb +++ /dev/null @@ -1,41 +0,0 @@ -class Movie - attr_reader :title - - def initialize(title) - @title = title - end -end - -class NetflixAccount - # Your code goes here - - def initialize(username) - @username = username - @my_list = [] - @recently_watched = [] - end - - def add_to_my_list(movie) - # Your code goes here - end - - def remove_from_my_list(movie) - # Your code goes here - end - - def watch(movie) - # Your code goes here - end -end - -movies = [ - Movie.new("Seven Samurai"), - Movie.new("Wall Street"), - Movie.new("Big Hero 6") -] - -account = NetflixAccount.new("user123") -account.watch(movies[0]) -account.add_to_my_list(movies[1]) -account.add_to_my_list(movies[2]) -account.remove_from_my_list(movies[2]) diff --git a/ruby/_Basics/open_close.rb b/ruby/_Basics/open_close.rb deleted file mode 100644 index 3cc3362..0000000 --- a/ruby/_Basics/open_close.rb +++ /dev/null @@ -1,84 +0,0 @@ -# The Open/Closed Principle states that classes or methods should be open for -# extension, but closed for modification. This tells us we should strive for -# modular designs that make it possible for us to change the behavior of the -# system without making modifications to the classes themselves. This is -# generally achieved through the use of patterns such as the strategy pattern. - -# In the below example we can see that we’ll have to modify our file parser -# anytime we add a client that reports usage information to us in a different -# file format. This violates the Open/Closed Principle. - -class FileParser - attr_reader :file - - def initialize(file) - @file = file - end - - def parse - # If we want add new parser we must to edit this method and in private method - case file.format - when :xml - parse_xml - when :cvs - parse_cvs - # when :json - # parse_json - else - # Implementation - end - - end - - private - - def parse_xml - # Implementation - end - - def parse_cvs - # Implementation - end - - # New parse method - # def parse_json - # # Implementation - # end -end - -# Solution - -# With this refactor we’ve made it possible to add new parsers without changing any code. Any additional behavior will only require the addition of a new handler. This makes our FileParser reusable and in many cases will keep us in compliance with the Single Responsibility Principle as well by encouraging us to create smaller more focused classes. - -class FileParser - attr_reader :parser - - def initialize(parser) - @parser = parser - end - - def parse(file) - # Now if we want new parser just write new Class and pass it to method - Data.new(parser.parse file) - end -end - -class JsonParser - # We write new class for extension solution. - def self.parse(file) - # Implementation - end -end - -class XmlParser - def self.parse(file) - # Implementation - end -end - -class CvsParser - def self.parse(file) - # Implementation - end -end - diff --git a/ruby/_Basics/order.rb b/ruby/_Basics/order.rb deleted file mode 100644 index 8668d94..0000000 --- a/ruby/_Basics/order.rb +++ /dev/null @@ -1,59 +0,0 @@ -require "bigdecimal" -require "yaml" - -class Item - attr_reader :name - attr_reader :price - - def initialize(name, price) - @name = name - @price = price - end -end - -class Order - @@WIDTH1 = 20 - @@WIDTH2 = 8 - @@SALES_TAX_RATE = 0.08875 - attr_reader :items - - def initialize - @items = [] - end - - def add(item) - # Your code goes here - end - - def print_receipt - @items.each do |item| - puts "#{item.name.ljust(@@WIDTH1)}" + - "#{item.price.truncate(2).to_s("F").rjust(@@WIDTH2)}" - end - puts "".ljust(@@WIDTH1 + @@WIDTH2, "=") - puts "#{"Total".ljust(@@WIDTH1)}" + - "#{base.truncate(2).to_s("F").rjust(@@WIDTH2)}" - puts "#{"Tax".ljust(@@WIDTH1)}#{tax.truncate(2).to_s("F").rjust(@@WIDTH2)}" - puts "".ljust(@@WIDTH1 + @@WIDTH2, "=") - puts "#{"Grand Total".ljust(@@WIDTH1)}" + - "#{total_cost.truncate(2).to_s("F").rjust(@@WIDTH2)}" - end - - private - def base - # Your code goes here - end - - private - def tax - # Your code goes here - end - - private - def total_cost - # Your code goes here - end -end - -order = YAML.load_file "order.yml" -order.print_receipt diff --git a/ruby/_Basics/phones.rb b/ruby/_Basics/phones.rb deleted file mode 100644 index ece2971..0000000 --- a/ruby/_Basics/phones.rb +++ /dev/null @@ -1,30 +0,0 @@ -require "date" - -class Phone - # Your code goes here -end - -phones = [ - { - :brand => "Apple", - :model => "iPhone 1st gen", - :operating_system => "iPhone OS 1.0", - :release_date => Date.new(2007, 6, 29) - }, - { - :brand => "Google", - :model => "Nexus One", - :operating_system => "Android 2.1 Eclair", - :release_date => Date.new(2010, 1, 5) - }, - { - :brand => "Samsung", - :model => "Galaxy S", - :operating_system => "Android 2.3.6 Gingerbread", - :release_date => Date.new(2010, 6, 4) - } -] - -new_phones = [] - -# Your code goes here diff --git a/ruby/_Basics/rails.rb b/ruby/_Basics/rails.rb deleted file mode 100644 index 590ed51..0000000 --- a/ruby/_Basics/rails.rb +++ /dev/null @@ -1,56 +0,0 @@ -# config.threadsafe!: what does it do? -# Let’s take a look at the threadsafe! method: - -def threadsafe! - @preload_frameworks = true - @cache_classes = true - @dependency_loading = false - @allow_concurrency = true - self -end - -# Calling this method sets four options in our app configuration. Let’s walk -# through each option and talk about what it does. - -# Preloading Frameworks -# The first option @preload_frameworks does pretty much what it says, it forces -# the Rails framework to be eagerly loaded on boot. When this option is not -# enabled, framework classes are loaded lazily via autoload. In multi-threaded -# environments, the framework needs to be eagerly loaded before any threads are -# created because of thread safety issues with autoload. We know that loading -# the framework isn’t threadsafe, so the strategy is to load it all up before -# any threads are ready to handle requests. - -# Caching classes -# The @cache_classes option controls whether or not classes get reloaded. -# Remember when you’re doing “TDD” in your application? You modify a controller, -# then reload the page to “test” it and see that things changed? Ya, that’s what -# this option controls. When this option is false, as in development, your -# classes will be reloaded when they are modified. Without this option, we -# wouldn’t be able to do our “F5DD” (yes, that’s F5 Driven Development). -# In production, we know that classes aren’t going to be modified on the fly, -# so doing the work to figure out whether or not to reload classes is just -# wasting resources, so it makes sense to never reload class definitions. - -# Dependency loading -# This option, @dependency_loading controls code loading when missing constants -# are encountered. For example, a controller references the User model, but the -# User constant isn’t defined. In that case, if @dependency_loading is true, -# Rails will find the file that contains the User constant, and load that file. -# We already talked about how code loading is not thread safe, so the idea here -# is that we should load the framework, then load all user code, then disable -# dependency loading. Once dependency loading is disabled, framework code and -# app code should be loaded, and any missing constants will just raise an -# exception rather than attempt to load code. -# We justify disabling this option in production because (as was mentioned -# earlier) code loading is not threadsafe, and we expect to have all code loaded -# before any threads can handle requests. - -# Allowing concurrency -# @allow_concurrency option controls whether or not the Rack::Lock middleware -# is used in your stack. Rack::Lock wraps a mutex around your request. The idea -# being that if you have code that is not threadsafe, this mutex will prevent -# multiple threads from executing your controller code at the same time. When -# threadsafe! is set, this middleware is removed, and controller code can be -# executed in parallel. - diff --git a/ruby/_Basics/single_responsibility.rb b/ruby/_Basics/single_responsibility.rb deleted file mode 100644 index e245c7d..0000000 --- a/ruby/_Basics/single_responsibility.rb +++ /dev/null @@ -1,92 +0,0 @@ -# The Single Responsibility Principle is the most abstract of the bunch. It -# helps keep classes and methods small and maintainable. In addition to keeping -# classes small and focused it also makes them easier to understand. - -# While we all agree that focusing on a single responsibility is important, it’s -# difficult to determine what a class’s responsibility is. Generally, it is said -# that anything that gives a class a reason to change can be viewed as a -# responsibility. By change I am talking about structural changes to the class -# itself (as in modifying the code in the class’s file, not the object’s -# in-memory state). -# In the below class we have a single command interface that processes -# commission payments for deals. At first glance the class seems simple enough, -# but let’s look at reasons we might want to change this class. Any change in -# how we calculate commissions would require a change to this class. We could -# introduce new commission rules or strategies that would cause our -# calculate_commission method to change. For instance, we might want to vary -# the percentage based on deal amount. Any change in the steps required to mark -# a deal as processed in the mark_deal_processed method would result in a change -# in the file as well. An example of this might be adding support for sending an -# email summary of a specific person’s commissions after marking a deal -# processed. The fact that we can identify multiple reasons to change signals a -# violation of the Single Responsibility Principle. - -class DealProcessor - attr_reader :deals - - def initialize(deals) - @deals = deals - end - - def process - deals.each do |deal| - # Here we calculate commission and create instance of Commission - Commission.create(deal: deal, amount: calculate_commission(deal)) - mark_deal_processed - end - end - - private - - def mark_deal_processed - # Implementation - end - - def calculate_commission(deal) - deal.amount * 0.05 - end -end - -class Commission - # Implementation -end - -# Solution - -class DealProcessor - attr_reader :deals - - def initialize(deals) - @deals = deals - end - - def process - deals.each do |deal| - # Now we call calculator in one operation, all logic now in it - CommissionCalculator.create_commission(deal) if mark_deal_processed - end - end - - private - - def mark_deal_processed - # Implementation - end -end - -class CommissionCalculator - def self.create_commission(deal) - Commission.new(deal: deal, amount: calculate(deal)) - end - - private - - def self.calculate(deal) - deal.amount * 0.05 - end -end - -class Commission - # Implementation -end - diff --git a/ruby/_Basics/sites.rb b/ruby/_Basics/sites.rb deleted file mode 100644 index cdcbc63..0000000 --- a/ruby/_Basics/sites.rb +++ /dev/null @@ -1,10 +0,0 @@ -require "open-uri" - -urls = [ - "https://www.reddit.com", - "https://www.facebook.com", - "https://www.spotify.com" -] - -# Your code goes here - diff --git a/ruby/_Basics/towers.rb b/ruby/_Basics/towers.rb deleted file mode 100644 index 6bf2ce8..0000000 --- a/ruby/_Basics/towers.rb +++ /dev/null @@ -1,16 +0,0 @@ -# Height in meters -towers = [ - { :name => "Berliner Fernsehturm", :height => 368.0 }, - { :name => "Canton Tower", :height => 600.0 }, - { :name => "Eiffel Tower", :height => 324.0 }, - { :name => "Tokyo Tower", :height => 332.6 }, - { :name => "Stratosphere Tower", :height => 350.2 } -] - -factor = 100/2.54 # Converts centimeters to inches - -conversion = lambda do |x| - # Your code goes here -end - -# Your code goes here