Repository: Upendhar10/LogicBuilding101 Branch: main Commit: 66ffb53a6e6d Files: 71 Total size: 73.5 KB Directory structure: gitextract_uj61cvru/ ├── .gitignore ├── DAY01/ │ ├── Questions.md │ └── Solutions.js ├── DAY02/ │ ├── Questions.md │ └── Solutions.js ├── DAY03/ │ ├── Questions.md │ └── Solutions.js ├── DAY04/ │ ├── Questions.md │ └── Solutions.js ├── DAY05/ │ ├── Questions.md │ └── Solutions.js ├── DAY06/ │ ├── Questions.md │ └── Solutions.js ├── DAY07/ │ ├── Questions.md │ └── Solutions.js ├── DAY08/ │ ├── Questions.md │ └── Solutions.js ├── DAY09/ │ ├── Questions.md │ └── Solutions.js ├── DAY10/ │ ├── Questions.md │ └── Solutions.js ├── DAY11/ │ ├── Questions.md │ └── Solutions.js ├── DAY12/ │ ├── Questions.md │ └── Solutions.js ├── DAY13/ │ ├── Questions.md │ └── Solutions.js ├── DAY14/ │ ├── Questions.md │ └── Solutions.js ├── DAY15/ │ ├── Questions.md │ └── Solutions.js ├── DAY16/ │ ├── Questions.md │ └── Solutions.js ├── DAY17/ │ ├── Questions.md │ ├── Solutions.js │ └── notes.md ├── DAY18/ │ ├── Questions.md │ └── Solutions.js ├── DAY19/ │ ├── Questions.md │ └── Solutions.js ├── DAY20/ │ ├── Questions.md │ └── Solutions.js ├── DAY21/ │ ├── Questions.md │ └── Solutions.js ├── DAY22/ │ ├── Questions.md │ └── Solutions.js ├── DAY23/ │ ├── Questions.md │ └── Solutions.js ├── DAY24/ │ ├── Questions.md │ └── Solutions.js ├── DAY25/ │ ├── Questions.md │ └── Solutions.js ├── DAY26/ │ ├── Questions.md │ └── Solutions.js ├── DAY27/ │ ├── Questions.md │ └── Solutions.js ├── DAY28/ │ ├── Questions.md │ └── Solutions.js ├── DAY29/ │ ├── Questions.md │ └── Solutions.js ├── DAY30/ │ ├── Questions.md │ └── Solutions.js ├── DAY31/ │ ├── Questions.md │ └── Solutions.js ├── DAY32/ │ ├── Questions.md │ └── Solutions.js ├── DAY33/ │ ├── Questions.md │ └── Solutions.js ├── DAY34/ │ ├── Questions.md │ └── Solutions.js └── readme.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .git/ ================================================ FILE: DAY01/Questions.md ================================================ # DAY - 01 1. **Program to Print Integer Numbers Entered by the User:** Write a program where the user is asked to enter an integer number, and the program prints that number back to them. For example: - **Input:** **`42`** - **Output:** **`You entered: 42`** 2. **Write a Program to Find the Size of `int`, `float`, `double`, and `char` on Your Computer:** Write a program that displays the size of fundamental data types (**`int`**, **`float`**, **`double`**, and **`char`**) on your system. For example: - **Output:** ```jsx Size of int: 4 bytes Size of float: 4 bytes Size of double: 8 bytes Size of char: 1 byte ``` 3. **Program to Find the Larger Number Among Two Numbers:** Write a program to compare two integers entered by the user and print the larger one. For example: - **Input:** **`Enter two numbers: 15, 20`** - **Output:** **`The larger number is: 20`** ================================================ FILE: DAY01/Solutions.js ================================================ // # Program to Print Integer Numbers Entered by the User: /* - Since, NaN (Not-a-Number) is a special value in JavaScript, and comparing it with == or === will always return false. This is because NaN is not equal to itself by design. So we use isNaN() function - isNaN(): This function checks if the value is NaN and returns true if it is, and false otherwise. */ var num = parseInt(prompt("Enter any number", 0)); isNaN(num) ? console.log(num + " is not a valid number") : console.log("You entered: " + num); // ---------------------------------------------------------- // # Write a Program to Find the Size of int, float, double, and char on Your Computer: /* - In JavaScript, we cannot directly determine the memory size of fundamental data types like int, float, or char as you would in statically typed languages like C or C++. This is because JavaScript is a dynamically typed language, and it abstracts away memory management details. - All numbers in JavaScript, whether integers or floating points, are represented as 64-bit floating-point values (IEEE 754 standard). - Strings are collections of characters, and their size depends on encoding (e.g., UTF-16 in JavaScript).There is no direct equivalent for a char type. - We need to use workarounds involving buffers, typed arrays, or specialized libraries, but those are more advanced concepts for now. */ // ---------------------------------------------------------- // # Program to Find the Larger Number Among Two Numbers: const num1 = parseInt(prompt("Enter num1 value", 0)); const num2 = parseInt(prompt("Enter num2 value", 0)); function findMax(num1, num2) { if (isNaN(num1) || isNaN(num2)) { return "Invalid Inputs"; } else { return Math.max(num1, num2); } } console.log(findMax(num1, num2)); ================================================ FILE: DAY02/Questions.md ================================================ # DAY - 02 1. **Program to Check Whether the Number is Odd or Even:** Write a program that checks whether a number entered by the user is odd or even. For example: - **Input:** **`Enter a number: 7`** - **Output:** **`7 is an odd number`** 2. **Program to Check Whether the Number is Divisible by 5:** Write a program that determines if a number entered by the user is divisible by 5. For example: - **Input:** **`Enter a number: 25`** - **Output:** **`25 is divisible by 5.`** 3. **Program to Check Whether the Number is a Multiple of 7:** Write a program that verifies if a number entered by the user is a multiple of 7. For example: - **Input:** **`Enter a number: 14`** - **Output:** **`14 is a multiple of 7.`** --- # NOTES ## Taking Input from the user in NodeJs Environment - Node.js provides several methods for receiving input from users, including reading from standard input (stdin), command-line arguments, and user prompts. ### Using readline-sync - This module is used to receive input from the user synchronously, ensuring program execution line by line. command : npm install readline-sync #### Importing the module const readline = require("readline-sync"); #### Enter the number ```javascript let a = Number(readline.question()); let number = []; for (let i = 0; i < a; ++i) { number.push(Number(readline.question())); } console.log(number); ``` #### Output 2 1 2 [1,2] ================================================ FILE: DAY02/Solutions.js ================================================ let num = parseInt(prompt("Enter a number: ", 0)); //* Program to Check Whether the Number is Odd or Even: function CheckEvenOdd(num) { if (isNaN(num)) { console.log("Invalid Input"); } else { if (num % 2 == 0) { console.log(`${num} is an even number`); } else console.log(`${num} is an Odd number`); } } CheckEvenOdd(num); // ------------------------------------------------------------------------------------------------------ //* Program to Check Whether the Number is Divisible by 5: function divisibleBy5(num) { if (isNaN(num)) { console.log("Invalid Input"); } else { if (num % 5 == 0) { console.log(`${num} is divisible`); } else console.log(`${num} is not divisible by 5`); } } divisibleBy5(num); // -------------------------------------------------------------------------------------------------------- //* Program to Check Whether the Number is a Multiple of 7: function multipleOf7(num) { if (isNaN(num)) { console.log("Invalid Input"); } else { if (num % 7 === 0) { console.log(`${num} is a multiple of 7`); } else console.log(`${num} is not divisible by 7`); } } ================================================ FILE: DAY03/Questions.md ================================================ # DAY - 03 1. **Program to Calculate the Square and Cube of a Number:** Write a program where the user enters a number, and the program calculates its square and cube. For example: - **Input:** **`Enter a number: 3`** - **Output:** **`Square: 9, Cube: 27`** 2. **Program to Calculate the Area of a Circle and Triangle:** Write a program to calculate the area of a circle given its radius and a triangle given its base and height. For example: - **Input:** **`Radius: 5, Base: 10, Height: 4`** - **Output:** ```markdown Area of Circle: 78.5 Area of Triangle: 20 ``` 3. **Write a Program to Find the Quotient and Remainder of Two Integers:** Write a program where the user enters two integers (divisor and dividend) and calculates their quotient and remainder. For example: - **Input:** **`Dividend: 22, Divisor: 7`** - **Output:** ```markdown Quotient: 3 Remainder: 1 ``` ================================================ FILE: DAY03/Solutions.js ================================================ // # Program to Calculate the Square and Cube of a Number let num = parseInt(prompt("Enter a number", 0)); findSquareAndCube(num); function findSquareAndCube(num) { if (isNaN(num)) { console.log("Invalid Input"); return; } else { console.log(`Square of the ${num} : ${num * num}`); console.log(`Cube of the ${num} : ${num * num * num}`); } } // ----------------------------------------------------------------------------------------------------------------------- // # Program to Calculate the Area of a Circle and Triangle let radius = parseInt(prompt("Enter the radius of the circle", 1)); let base = parseInt(prompt("Enter the base of the triangle", 1)); let height = parseInt(prompt("Enter the heght of the triangle", 1)); AreaOfCircleAndTriangle(radius, base, height); function AreaOfCircleAndTriangle(radius, base, height) { if (isNaN(radius) || isNaN(base) || isNaN(height)) { console.log("Invalid Input"); return; } circleArea(radius); triangleArea(base, height); } function circleArea(radius) { let area = Math.round(Math.PI * radius * radius); console.log(`Area of the circle : ${area}`); } function triangleArea(base, height) { let area = Math.round(0.5 * base * height); console.log(`Area of the triangle : ${area}`); } // ----------------------------------------------------------------------------------------------------------------------- // # Write a Program to Find the Quotient and Remainder of Two Integers let divisor = parseInt(prompt("Enter the divisor", 1)); let dividend = parseInt(prompt("Enter the dividend", 1)); findQuotientAndRemainder(divisor, dividend); function findQuotientAndRemainder(divisor, dividend) { if (isNaN(divisor) || isNaN(dividend)) { console.log("Invalid Input"); return; } if (divisor === 0) { console.log("ERROR : Divide by Zero"); return; } let Quotient = Math.floor(dividend / divisor); let remainder = dividend % divisor; console.log(`Quotient : ${Quotient} and Remainder : ${remainder} `); } ================================================ FILE: DAY04/Questions.md ================================================ # DAY - 04 1. **Print the Multiplication Table of a Given Number:** Write a program where the user enters a number, and the program prints its multiplication table. For example: - **Input:** **`Enter a number: 5`** - **Output:** ```jsx 5 x 1 = 5 5 x 2 = 10 ... 5 x 10 = 50 ``` 2. **Write a Program to Make a Simple Calculator Using a Switch Case:** Write a program that acts as a calculator, taking two numbers and an operator (**`+`**, **`-`**, **`*`**, **`/`**) from the user, and performing the operation based on the operator. For example: - **Input:** **`Enter first number: 10, Operator: +, Second number: 20`** - **Output:** **`10 + 20 = 30`** 3. **Print a Number in Reverse Order:** Write a program where the user enters a number, and the program prints it in reverse order. For example: - **Input:** **`1234`** - **Output:** **`4321`** ================================================ FILE: DAY04/Solutions.js ================================================ //* Print the Multiplication Table of a Given Number let number = 5; function PrintTable(num) { for (let i = 1; i <= 10; i++) { console.log(`${num} x ${i} = ${num * i} `); } } PrintTable(number); // -------------------------------------------------------------------------------------------------------------------- //* Write a Program to Make a Simple Calculator Using a Switch Case let Operand1 = 12; let Operand2 = 13; let Operator = "*"; function Calculator() { switch (Operator) { case "+": console.log(`Addition: ${Operand1 + Operand2}`); break; case "-": console.log(`Subtraction: ${Operand1 - Operand2}`); break; case "*": console.log(`Multiplication: ${Operand1 * Operand2}`); break; case "/": console.log(`Division: ${(Operand1 / Operand2).toFixed(2)}`); break; default: console.log("Invalid Operator"); break; } } Calculator(Operand1, Operand2, Operator); // ---------------------------------------------------------------------------------------------------------------- //* Print a Number in Reverse Order let num = 1234; function PrintReverseNum(num) { let reverse = null; while (num > 0) { let rem = num % 10; reverse = reverse * 10 + rem; num = Math.floor(num / 10); } return reverse; } console.log(PrintReverseNum(num)); ================================================ FILE: DAY05/Questions.md ================================================ # DAY - 05 1. **Calculate the Sum of Digits of a Given Number:** Write a program that calculates the sum of the digits of a number entered by the user. For example: - **Input:** **`Enter a number: 1234`** - **Output:** **`Sum of digits: 10`** 2. **Write a Program to Check Whether a Character is a Vowel or Consonant:** Write a program to check whether a character entered by the user is a vowel (**`a, e, i, o, u`**) or a consonant. For example: - **Input:** **`Enter a character: e`** - **Output:** **`e is a vowel.`** 3. **Write a Program to Find the ASCII Value of a Character:** Write a program that takes a character as input and displays its ASCII value. For example: - **Input:** **`Enter a character: A`** - **Output:** **`ASCII value of A: 65`** ================================================ FILE: DAY05/Solutions.js ================================================ //* Calculate the Sum of Digits of a Given Number let number = 1234; function findSumOfDigits(num) { let sum = 0; while (num > 0) { let rem = num % 10; sum += rem; num = Math.floor(num / 10); } return sum; } console.log(`The Sum of Digits of ${number} :`, findSumOfDigits(number)); // ----------------------------------------------------------------------------------------------------------- //* Write a Program to Check Whether a Character is a Vowel or Consonant let char = "Z"; function checkCharacter(char) { if (char.length != 1 || !/[a-zA-Z]/.test(char)) { return "Invalid Input"; } let letter = char.toLowerCase(); if ("aeiou".includes(letter)) { return `${char} is an Vowel`; } else { return `${char} is a Consonant`; } } console.log(checkCharacter(char)); // ------------------------------------------------------------------------------------------------------------ //* Write a Program to Find the ASCII Value of a Character let Value = "@"; function findASCIIValue(val) { if (val === " " || val.length != 1) { return "Invalid Input"; } return `ASCII value of ${val}: ${val.charCodeAt(0)}`; } console.log(findASCIIValue(Value)); ================================================ FILE: DAY06/Questions.md ================================================ # DAY - 06 ## Pattern 1: Sqaure ``` * * * * * * * * * * * * * * * * * * * * * * * * * ``` ## Pattern 2: Right-angled trinagle ``` * * * * * * * * * * * * * * * ``` ## Pattern 3: Hallow Rectangle ``` * * * * * * * * * * * * * * * * ``` ================================================ FILE: DAY06/Solutions.js ================================================ //* Pattern - 1 function Pattern1(n) { for (let i = 1; i <= n; i++) { let rowPattern = ""; for (let j = 1; j <= n; j++) { rowPattern += "* "; } console.log(rowPattern); } } console.log("Pattern - 1"); Pattern1(5); // -------------------------------------------------------------------------------------- //* Pattern - 2 function pattern2(n) { for (let i = 1; i <= n; i++) { let rowPattern = " "; for (let j = 1; j <= i; j++) { rowPattern += "* "; } console.log(rowPattern); } } console.log("Pattern - 2"); pattern2(5); // -------------------------------------------------------------------------------------- //* Pattern - 3 function Pattern3(n) { for (let i = 1; i <= n; i++) { let rowPattern = " "; for (let j = 1; j <= n; j++) { if (i == 1 || i == n || j == 1 || j == n) { rowPattern += "* "; } else { rowPattern += " "; } } console.log(rowPattern.trim()); } } console.log("Pattern - 3"); Pattern3(5); ================================================ FILE: DAY07/Questions.md ================================================ # DAY - 07 ## Pattern 1: Inverted Right-angled triangle ``` * * * * * * * * * * * * * * * ``` ## Pattern 2: traingle ``` * * * * * * * * * * * * * * * * * * * * * * * * * ``` ## Pattern 3: Inverted traingle ``` * * * * * * * * * * * * * * * * * * * * * * * * * ``` ================================================ FILE: DAY07/Solutions.js ================================================ //* Pattern-1 : function Pattern1(n) { for (let i = 1; i <= n; i++) { let rowPattern = " "; for (let j = n; j >= i; j--) { rowPattern += "* "; } console.log(rowPattern.trim()); } } Pattern1(5); // --------------------------------------------------------------------------------------------------------------------------------------- // * Pattern - 2 : function Pattern2(n) { for (let i = 1; i <= n; i++) { // rows let rowPattern = " "; for (let j = 1; j <= n - i; j++) { // spaces rowPattern += ". "; } for (let k = 1; k <= 2 * i - 1; k++) { // starts rowPattern += "* "; } console.log(rowPattern.trim()); } } Pattern2(5); // --------------------------------------------------------------------------------------------------------------------------- //* Pattern - 3 function Pattern3(n) { for (let i = n; i >= 1; i--) { // rows let rowPattern = " "; for (let j = 1; j <= n - i; j++) { // spaces rowPattern += ". "; } for (let k = 1; k <= 2 * i - 1; k++) { // starts rowPattern += "* "; } console.log(rowPattern.trim()); } } Pattern3(10); ================================================ FILE: DAY08/Questions.md ================================================ # DAY - 08 ## Pattern 7: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 ## Pattern 8 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 ## Pattern 9 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 ================================================ FILE: DAY08/Solutions.js ================================================ //* Pattern - 1 function Pattern1(n) { for (let i = 1; i <= n; i++) { let rowPattern = " "; for (let j = 1; j <= i; j++) { rowPattern += `${j} `; } console.log(rowPattern); } } Pattern1(5); // ------------------------------------------------------------------------- //* Pattern - 2 function Pattern2(n) { for (let i = 1; i <= n; i++) { let rowPattern = " "; for (let j = 1; j <= i; j++) { rowPattern += `${i} `; } console.log(rowPattern); } } Pattern2(5); // ------------------------------------------------------------------------- //* Pattern - 3 function Pattern3(n) { for (let i = n; i >= 1; i--) { let rowPattern = " "; for (let j = 1; j <= i; j++) { rowPattern += `${j} `; } console.log(rowPattern); } } Pattern3(5); ================================================ FILE: DAY09/Questions.md ================================================ ## Pattern 1 ``` 1 1 1 2 2 1 1 2 3 3 2 1 1 2 3 4 4 3 2 1 ``` ## Pattern 2 ``` A A B A B C A B C D A B C D E ``` ## Pattern 3 ``` A B C D E A B C D A B C A B A ``` ================================================ FILE: DAY09/Solutions.js ================================================ //* Pattern - 1 function Pattern1(n) { for (let i = 1; i <= n; i++) { let rowPattern = " "; for (let j = 1; j <= i; j++) { rowPattern += `${j} `; } for (let k = 1; k <= 2 * (n - i); k++) { rowPattern += " "; } for (let l = i; l >= 1; l--) { rowPattern += `${l} `; } console.log(rowPattern); } } Pattern1(5); // -------------------------------------------------------------------------------------- //* Pattern - 2 function Pattern2(n) { for (let i = 1; i <= n; i++) { let rowPattern = " "; for (let j = 0; j < i; j++) { rowPattern += String.fromCharCode(65 + j) + " "; } console.log(rowPattern.trim()); } } Pattern2(5); // -------------------------------------------------------------------------------------- //* Pattern - 3 function Pattern3(n) { for (let i = n; i >= 1; i--) { let rowPattern = " "; for (let j = 0; j < i; j++) { rowPattern += String.fromCharCode(65 + j) + " "; } console.log(rowPattern.trim()); } } Pattern3(5); ================================================ FILE: DAY10/Questions.md ================================================ ## Pattern 1 ``` A B B C C C D D D D E E E E E ``` ## Pattern 2 ``` A A B A A B C B A A B C D C B A ``` ## **Program to Perform Swapping of Two Numbers:** Write a program to swap two numbers entered by the user. For example: - **Input:** **`Enter first number: 10, Enter second number: 20`** - **Output:** ``` Before swapping: a = 10, b = 20 After swapping: a = 20, b = 10 ``` ================================================ FILE: DAY10/Solutions.js ================================================ //* Pattern - 1 function Pattern1(n) { for (let i = 1; i <= n; i++) { let rowPattern = " "; for (let j = 1; j <= i; j++) { rowPattern += String.fromCharCode(65 + i - 1) + " "; } console.log(rowPattern.trim()); } } Pattern1(5); // --------------------------------------------------------------------------------------------------- //* Pattern - 2 function Pattern2(n) { for (let i = 0; i < n; i++) { let rowPattern = " "; for (let j = 0; j < n - i; j++) { rowPattern += `. `; } for (let k = 0; k < i; k++) { rowPattern += String.fromCharCode(65 + k) + " "; } for (let l = 0; l <= i; l++) { rowPattern += String.fromCharCode(65 + i - l) + " "; } console.log(rowPattern.trim()); } } Pattern2(4); // --------------------------------------------------------------------------------------------------- //* Question - 3 let number1 = 10; let number2 = 28; console.log("Before Swap"); console.log(`Number1 : ${number1}`); console.log(`Number2 : ${number2}`); function SwapTwoNumbers1(num1, num2) { let temp = null; temp = num1; num1 = num2; num2 = temp; console.log("After Swap"); console.log(`Number1 : ${num1}`); console.log(`Number2 : ${num2}`); } SwapTwoNumbers1(number1, number2); function SwapTwoNumbers2(num1, num2) { num1 = num1 + num2; num2 = num1 - num2; num1 = num1 - num2; console.log("After Swap"); console.log(`Number1 : ${num1}`); console.log(`Number2 : ${num2}`); } // SwapTwoNumbers2(number1, number2); ================================================ FILE: DAY11/Questions.md ================================================ # DAY - 11 1. **Write a Program to Find the Largest Number Among Three Numbers:** Write a program where the user enters three numbers, and the program finds and displays the largest number among them. For example: - **Input:** **`Enter three numbers: 12, 25, 7`** - **Output:** **`The largest number is: 25`** 2. **Write a Program to Check Whether a Year Entered by the User is a Leap Year:** Write a program to determine whether a given year is a leap year. For example: - **Input:** **`Enter a year: 2024`** - **Output:** **`2024 is a leap year.`** 3. **Write a Program to Calculate the Sum of the First N Natural Numbers:** Write a program where the user enters a number **`N`**, and the program calculates the sum of all natural numbers up to **`N`**. For example: - **Input:** **`Enter a number: 5`** - **Output:** **`The sum of the first 5 natural numbers is 15.`** ================================================ FILE: DAY11/Solutions.js ================================================ //* Program to Find the Largest Number Among Three Numbers function LargestAmongThreeNums(num1, num2, num3) { if (num1 > num2) { if (num1 > num3) { console.log(`${num1} is Largest`); } else { console.log(`${num3} is Largest`); } } else { if (num2 > num3) { console.log(`${num2} is Largest`); } else { console.log(`${num3} is Largest`); } } } LargestAmongThreeNums(-3, -2, -1); // -------------------------------------------------------------- //* Program to Check Whether a Year Entered by the User is a Leap Year function isLeapYear(year) { if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) { console.log(`${year} is a Leap year`); } else { console.log(`${year} is not a Leap Year`); } } isLeapYear(2024); // -------------------------------------------------------------- //* Program to Calculate the Sum of the First N Natural Numbers function SumOfFirstNnaturalNums(n) { let sum = 0; for (let i = 1; i <= n; i++) { sum += i; } return `Sum : ${sum}`; } console.log(SumOfFirstNnaturalNums(5)); ================================================ FILE: DAY12/Questions.md ================================================ # DAY - 12 1. **Factorial of a Number Using a For Loop:** Write a program to calculate the factorial of a number entered by the user using a **`for`** loop. For example: - **Input:** **`Enter a number: 4`** - **Output:** **`Factorial of 4 is 24.`** 2. **Print Fibonacci Series:** Write a program to print the Fibonacci series up to a number **`N`** entered by the user. For example: - **Input:** **`Enter the number of terms: 7`** - **Output:** **`Fibonacci series: 0 1 1 2 3 5 8`** 3. **Write a Program to Find the GCD or HCF of Two Numbers:** Write a program where the user enters two numbers, and the program calculates their greatest common divisor (GCD) or highest common factor (HCF). For example: - **Input:** **`Enter two numbers: 60, 48`** - **Output:** **`The GCD of 60 and 48 is 12.`** ================================================ FILE: DAY12/Solutions.js ================================================ //* Factorial of a Number Using a For Loop function FindFactorial(n) { let fact = 1; for (let i = 1; i <= n; i++) { fact *= i; } return fact; } console.log(FindFactorial(4)); // --------------------------------------------------------------------------------- //* Print Fibonacci Series function PrintFibonacciSeries(n) { let prev = 0, next = 1; let series = `${prev} ${next}`; for (let i = 2; i < n; i++) { let result = prev + next; series += ` ${result}`; prev = next; next = result; } console.log(series); } PrintFibonacciSeries(7); // --------------------------------------------------------------------------------- //* Write a Program to Find the GCD or HCF of Two Numbers function findHCF(num1, num2) { let hcf = 1; // let i = Math.min(num1, num2); i >= 1; i-- for (let i = 1; i < Math.min(num1, num2); i++) { if (num1 % i === 0 && num2 % i === 0) { hcf = i; } } return hcf; } console.log(findHCF(60, 48)); ================================================ FILE: DAY13/Questions.md ================================================ # DAY - 13 1. **Write a Program to Find the LCM of Two Numbers:** Write a program where the user enters two numbers, and the program calculates their least common multiple (LCM). For example: - **Input:** **`Enter two numbers: 4, 6`** - **Output:** **`The LCM of 4 and 6 is 12.`** 2. **Write a Program to Calculate the Power of a Number:** Write a program that takes a base and an exponent as input and calculates the power of the base raised to the exponent using both manual calculation and the **`pow()`** function. For example: - **Input:** **`Base: 2, Exponent: 3`** - **Output:** ```markdown Result using manual calculation: 8 Result using pow(): 8 ``` 3. **Program to Print Integers in Words:** Write a program that converts each digit of an integer entered by the user into its corresponding word representation. For example: - **Input:** **`Enter a number: 123`** - **Output:** **`One Two Three`** ================================================ FILE: DAY13/Solutions.js ================================================ //* Write a Program to Find the LCM of Two Numbers function findLCM(num1, num2) { if (num1 === 0 || num2 === 0) { return "LCM is not defined for zero."; } let lcm = null; let max = Math.max(Math.abs(num1), Math.abs(num2)); while (true) { if (max % num1 == 0 && max % num2 == 0) { lcm = max; break; } max++; } return lcm; } console.log(findLCM(5, 7)); // ----------------------------------------------------------------------------------------------------------- //* Write a Program to Calculate the Power of a Number function findPowerManual(base, expo) { let power = base ** expo; return power; } // console.log(findPowerManual(2, 3)); function findPowerBuiltIn(base, expo) { let power = Math.pow(base, expo); return power; } console.log(findPowerBuiltIn(2, 3)); // ----------------------------------------------------------------------------------------------------------- //* Program to Print Integers in Words function DigitToWord(num) { const digitToWord = [ "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", ]; let numStr = num.toString(); let result = " "; for (let i = 0; i < numStr.length; i++) { let char = numStr[i]; if (char === "-") { result += "Negative "; } else { result += digitToWord[parseInt(char)] + " "; } } return result.trim(); } console.log(DigitToWord(1028)); ================================================ FILE: DAY14/Questions.md ================================================ # DAY - 14 1. **Print Numbers in Words in Reverse Order Using a Switch Case:** Write a program that takes an integer, reverses it, and prints each digit as a word using a **`switch`** case. For example: - **Input:** **`Enter a number: 321`** - **Output:** **`One Two Three`** 2. **Write a Program to Display All Factors of a Number:** Write a program to find and print all factors of a number entered by the user. For example: - **Input:** **`Enter a number: 28`** - **Output:** **`Factors of 28: 1, 2, 4, 7, 14, 28`** 3. **Amstrong Number or Not:** Write a program to check if a number is an Armstrong number. For example: - **Input:** **`Enter a number: 153`** - **Output:** **`153 is an Armstrong number.`** ================================================ FILE: DAY14/Solutions.js ================================================ //* Print Numbers in Words in Reverse Order Using a Switch Case function NumToWordsReverse(num) { if (isNaN(num)) { console.log("Invalid Input"); return; } let result = ""; if (num < 0) { result += "Negative "; num = Math.abs(num); } while (num > 0) { let digit = num % 10; switch (digit.toString()) { case "0": result += "Zero "; break; case "1": result += "One "; break; case "2": result += "Two "; break; case "3": result += "Three "; break; case "4": result += "Four "; break; case "5": result += "Five "; break; case "6": result += "Six "; break; case "7": result += "Seven "; break; case "8": result += "Eight "; break; case "9": result += "Nine "; break; } num = Math.floor(num / 10); } return result; } console.log(NumToWordsReverse(-321)); // ----------------------------------------------------------- //* Write a Program to Display All Factors of a Number function PrintFactors(n) { let result = []; for (let i = 1; i <= n; i++) { if (n % i === 0) { result.push(i); } } return result; } console.log(PrintFactors(28)); // ---------------------------------------------------------- //* Amstrong Number or Not: function ValidAmstrong(num) { if (isNaN(num) || num < 0) { console.log("Invalid Input, Please enter a non-negative integer."); return; } let OriginalNum = num; let DigitCount = num.toString().length; let result = 0; while (num > 0) { let digit = num % 10; result += digit ** DigitCount; num = Math.floor(num / 10); } result === OriginalNum ? console.log(`${OriginalNum} is an Amstrong Number`) : console.log(`${OriginalNum} is not an Amstrong Number`); } ValidAmstrong(1634); ================================================ FILE: DAY15/Questions.md ================================================ # DAY - 15 1. **Check Whether a Number is Prime or Not:** Write a program that checks if a number entered by the user is a prime number. For example: - **Input:** **`Enter a number: 17`** - **Output:** **`17 is a prime number.`** 2. **Print Prime Numbers Within a Range:** Write a program to display all prime numbers between two intervals entered by the user. For example: - **Input:** **`Enter two numbers: 10, 30`** - **Output:** **`Prime numbers between 10 and 30: 11, 13, 17, 19, 23, 29`** 3. **Print Factorial Series:** Write a program that prints the factorial of numbers from 1 to **`N`**, where the user enters N. For example: - **Input:** **`Enter a number: 5`** - **Output:** ``` 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 ``` ================================================ FILE: DAY15/Solutions.js ================================================ //* Check Whether a Number is Prime or Not function ValidPrime(num) { if (num <= 1) { return `${num} is Not Prime`; } if (num == 2) { return `${num} is Prime`; } if (num % 2 === 0) { return `${num} is Not Prime`; } for (let i = 3; i <= Math.sqrt(num); i += 2) { if (num % i === 0) { return `${num} is Not Prime`; } } return `${num} is Prime`; } console.log(ValidPrime(5)); // ----------------------------------------------------------- //* Print Prime Numbers Within a Range function PrimeNumsInRange(start, end) { let result = []; for (let i = Math.max(start, 2); i <= end; i++) { let isPrime = true; for (let j = 2; j <= Math.sqrt(i); j++) { if (i % j === 0) { isPrime = false; break; } } if (isPrime) result.push(i); } return result; } console.log(PrimeNumsInRange(5, 15)); // ----------------------------------------------------------- //* Print Factorial Series function PrintFactorialSeries1(num) { for (let i = 1; i <= num; i++) { let fact = 1; for (let j = 1; j <= i; j++) { fact = fact * j; } console.log(`${i}! = ${fact}`); } } // PrintFactorialSeries1(5); function PrintFactorialSeries2(num) { let fact = 1; for (let i = 1; i <= num; i++) { fact = fact * i; console.log(`${i}! = ${fact}`); } } PrintFactorialSeries2(5); ================================================ FILE: DAY16/Questions.md ================================================ # DAY - 16 1. **Write a Program to Check Whether a Number is a Palindrome:** Write a program to determine if a number is a palindrome. For example: - **Input:** **`Enter a number: 121`** - **Output:** **`121 is a palindrome.`** 2. **Check if an Integer Can Be Expressed as the Sum of Two Prime Numbers:** Write a program to check if a number can be expressed as the sum of two prime numbers. Print all such combinations. For example: - **Input:** **`Enter a number: 34`** - **Output:** ``` 34 = 3 + 31 34 = 5 + 29 34 = 11 + 23 34 = 17 + 17 ``` 3. **Print All Digits and Alphabets Using a For Loop:** Write a program to print all digits (0–9) and alphabets (A–Z, a–z) using a **`for`** loop. For example: - **Output:** ```markdown Digits: 0 1 2 3 4 5 6 7 8 9 Alphabets: A B C ... Z a b c ... z ``` ================================================ FILE: DAY16/Solutions.js ================================================ //* Write a Program to Check Whether a Number is a Palindrome function ValidPalindrome(num) { if (isNaN(num)) { return "Invalid Input!"; } let OriginalNum = num; let reversedNum = 0; while (num > 0) { let rem = num % 10; reversedNum = reversedNum * 10 + rem; num = Math.floor(num / 10); } console.log(reversedNum); if (OriginalNum === reversedNum) { return `${OriginalNum} is a Valid Palindrome`; } return `${OriginalNum} is not a Valid Palindrome`; } console.log(ValidPalindrome(12)); // ---------------------------------------------------------------------- //* Check if an Integer Can Be Expressed as the Sum of Two Prime Numbers function isPrime(n) { if (n < 1) return false; for (let i = 2; i < Math.sqrt(n); i++) { if (n % i === 0) return false; } return true; } function SumOfTwoPrimes(N) { let Primes = []; for (let i = 2; i <= N / 2; i++) { let compliment = N - i; if (isPrime(i) && isPrime(compliment)) { Primes.push(`${N} = ${i} + ${compliment}`); // Primes.push(i, compliment); } } if (Primes.length === 0) { console.log(`${N} cannot be expressed as the sum of two prime numbers`); } else { console.log(Primes.join("\n")); } } SumOfTwoPrimes(34); // ------------------------------------------------------------------------- //* Print All Digits and Alphabets Using a For Loop function PrintNumbers() { let Digits = []; for (let i = 0; i < 10; i++) { Digits.push(i); } return Digits; } function PrintAlphabets() { let Alphabets = []; for (let i = "A".charCodeAt(0); i <= "Z".charCodeAt(0); i++) { Alphabets.push(String.fromCharCode(i)); } for (let i = "a".charCodeAt(0); i <= "z".charCodeAt(0); i++) { Alphabets.push(String.fromCharCode(i)); } return Alphabets; } console.log(PrintNumbers()); console.log(PrintAlphabets()); ================================================ FILE: DAY17/Questions.md ================================================ # DAY - 17 1. **Write a Program to Convert Binary Numbers to Decimal and Vice Versa Manually:** Write a program that uses user-defined functions to convert binary numbers to decimal and decimal numbers to binary. For example: - **Input:** **`Enter a binary number: 1010`** - **Output:** **`Decimal equivalent: 10`** - **Input:** **`Enter a decimal number: 10`** - **Output:** **`Binary equivalent: 1010`** 2. Pattern - 1 ``` * * * * * * * * * * * * * * * * * * * * * * * * * ``` 3. Pattern - 2 ``` * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ``` ================================================ FILE: DAY17/Solutions.js ================================================ //* Program to Convert Binary Numbers to Decimal and Vice Versa Manually: // Function to convert Binary to Decimal function binaryToDecimal(binary) { let decimal = 0; let position = 0; while (binary > 0) { let digit = binary % 10; // Extract the last digit decimal += digit * Math.pow(2, position); // Multiply by 2^position position++; binary = Math.floor(binary / 10); // Remove the last digit } return decimal; } // Function to convert Decimal to Binary function decimalToBinary(decimal) { let binary = ""; while (decimal > 0) { let remainder = decimal % 2; // Get remainder binary = remainder + binary; // Add remainder to the left decimal = Math.floor(decimal / 2); // Divide by 2 } return binary || "0"; // If input is 0, return "0" } // User Input and Output const binaryInput = 1010; console.log( `Binary ${binaryInput} -> Decimal: ${binaryToDecimal(binaryInput)}` ); const decimalInput = 10; console.log( `Decimal ${decimalInput} -> Binary: ${decimalToBinary(decimalInput)}` ); // ----------------------------------------------------------- //* Pattern - 1 function PrintPattern1(n) { for (let i = 1; i <= n; i++) { let rowPattern = ""; for (let j = 1; j <= i; j++) { rowPattern += "* "; } console.log(rowPattern.trim()); } for (let i = n - 1; i >= 1; i--) { let rowPattern = " "; for (let j = 1; j <= i; j++) { rowPattern += "* "; } console.log(rowPattern.trim()); } } PrintPattern1(5); // ---------------------------------------------------------- //* Pattern - 2 function PrintPattern2(n) { // Upper half of the pattern for (let i = 1; i <= n; i++) { let rowPattern = " ".repeat(n - i) + "* ".repeat(i * 2 - 1); console.log(rowPattern); // console.log(rowPattern.trim()); } // Lower half of the pattern for (let i = n - 1; i >= 1; i--) { let rowPattern = " ".repeat((n - i) * 2) + "* ".repeat(i * 2 - 1); console.log(rowPattern); } } PrintPattern2(5); ================================================ FILE: DAY17/notes.md ================================================ ## Binary to Decimal Conversion: ### Binary Number: - A binary number is made up of 0's and 1's and uses base 2. - To convert a binary number to decimal, multiply each binary digit (bit) by 2nd position, where the position starts from 0 (right to left). Add up all these values to get the decimal number --- ## Decimal to Binary Conversion: ### Decimal Number: - A number using base 10 (0-9 digits). - To convert to binary: Repeatedly divide the decimal number by 2. - Record the remainder at each step (this will be the binary digit). - Continue until the quotient becomes 0. - Read the remainders from bottom to top to get the binary number. --- ## repeat() method - The repeat() method in JavaScript is a built-in method for strings. - It allows a string to be repeated a specified number of times. ### Syntax: string.repeat(count); where - string: The string to repeat. - count: The number of times to repeat the string. This must be a non-negative integer. ================================================ FILE: DAY18/Questions.md ================================================ # DAY - 18 **Pattern - 1** ``` * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ``` **Pattern - 2** ``` * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ``` **Pattern - 3** ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ``` ================================================ FILE: DAY18/Solutions.js ================================================ //* Pattern - 1 function PrintPattern1(n) { for (let i = 1; i <= n; i++) { let rowPattern = ""; for (let j = 1; j <= i; j++) { rowPattern += "* "; } for (let k = 1; k <= 2 * (n - i); k++) { rowPattern += " "; } for (let j = 1; j <= i; j++) { rowPattern += "* "; } console.log(rowPattern); } for (let i = n - 1; i >= 1; i--) { let rowPattern = ""; for (let j = 1; j <= i; j++) { rowPattern += "* "; } for (let k = 1; k <= 2 * (n - i); k++) { rowPattern += " "; } for (let j = 1; j <= i; j++) { rowPattern += "* "; } console.log(rowPattern); } } PrintPattern1(5); function PrintPattern1Optimized(n) { for (let i = 1; i <= 2 * n - 1; i++) { // Determine the row index let rowIndex = i <= n ? i : 2 * n - i; // Left stars let leftStars = "* ".repeat(rowIndex); // Middle spaces let middleSpaces = " ".repeat(2 * (n - rowIndex)); // Right stars let rightStars = "* ".repeat(rowIndex); // Print the complete row console.log(leftStars + middleSpaces + rightStars); } } // PrintPattern1Optimized(5); // ----------------------------------------------------------- //* Pattern - 2 function PrintPattern2(n) { for (let i = n; i >= 1; i--) { rowPattern = ""; for (let j = 1; j <= i; j++) { rowPattern += "* "; } for (let k = 1; k <= 2 * (n - i); k++) { rowPattern += " "; } for (let l = 1; l <= i; l++) { rowPattern += "* "; } console.log(rowPattern); } for (let i = 1; i <= n; i++) { rowPattern = ""; for (let j = 1; j <= i; j++) { rowPattern += "* "; } for (let k = 1; k <= 2 * (n - i); k++) { rowPattern += " "; } for (let l = 1; l <= i; l++) { rowPattern += "* "; } console.log(rowPattern); } } PrintPattern2(5); // ---------------------------------------------------------- //* Pattern - 3 function PrintPattern3(n) { let num = 1; for (let i = 1; i <= n; i++) { let rowPattern = ""; for (let j = 1; j <= i; j++) { rowPattern += num + " "; num++; } console.log(rowPattern); } } PrintPattern3(5); ================================================ FILE: DAY19/Questions.md ================================================ # DAY - 19 ## Pattern 1: ``` 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1 ``` ## Pattern 2: ``` 4 4 4 4 4 4 4 4 3 3 3 3 3 4 4 3 2 2 2 3 4 4 3 2 1 2 3 4 4 3 2 2 4 3 4 4 3 3 3 3 3 4 4 4 4 4 4 4 4 ``` ## Pattern 3: ``` E D E C D E B C D E A B C D E ``` ================================================ FILE: DAY19/Solutions.js ================================================ //* Pattern - 1 function PrintPattern1(n) { for (let i = 1; i <= n; i++) { let rowPattern = ""; for (let j = 1; j <= i; j++) { if ((i + j) % 2 == 0) { rowPattern += 1 + " "; } else { rowPattern += 0 + " "; } } console.log(rowPattern); } } PrintPattern1(5); // -------------------------------------------------------------------------------- //* Pattern - 2 function PrintPattern2(n) { let size = 2 * n - 1; for (let i = 1; i <= size; i++) { let rowPattern = ""; for (let j = 1; j <= size; j++) { let value = n - Math.min( Math.min(i - 1, size - i), // Distance from top or bottom edge Math.min(j - 1, size - j) // Distance from left or right edge ); rowPattern += `${value} `; } console.log(rowPattern); } } PrintPattern2(4); // ------------------------------------------------------------------------------- //* Pattern - 3 function PrintPattern3(n) { let startChar = "E".charCodeAt(0); for (let i = 1; i <= n; i++) { let rowPattern = ""; let currentChar = startChar - i; for (let j = 1; j <= i; j++) { rowPattern += String.fromCharCode(currentChar + j) + " "; } console.log(rowPattern); } } PrintPattern3(5); ================================================ FILE: DAY20/Questions.md ================================================ # DAY - 20 ## Pattern 1 ``` * * * * * * * * * * * * ``` ## Pattern 2 ``` 1 1 2 1 1 2 3 2 1 ``` ## Pattern 3 ``` 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 ``` ================================================ FILE: DAY20/Solutions.js ================================================ //* Pattern - 1 function PrintPattern1(n) { // Top half of the diamond for (let i = 1; i <= n; i++) { let rowPattern = ""; rowPattern += " ".repeat(n - i); // Print stars and spaces for (let j = 1; j <= 2 * i - 1; j++) { if (j === 1 || j === 2 * i - 1) { rowPattern += "*"; } else { rowPattern += " "; } } console.log(rowPattern); } // Bottom half of the diamond for (let i = n - 1; i >= 1; i--) { let rowPattern = ""; rowPattern += " ".repeat(n - i); // Print stars and spaces for (let j = 1; j <= 2 * i - 1; j++) { if (j === 1 || j === 2 * i - 1) { rowPattern += "*"; } else { rowPattern += " "; } } console.log(rowPattern); } } PrintPattern1(4); // ---------------------------------------------------------- //* Pattern - 2 function PrintPattern2(n) { for (let i = 1; i <= n; i++) { let rowPattern = ""; // Print leading spaces rowPattern += ".".repeat(2 * (n - i)); // Print ascending numbers for (let j = 1; j <= i; j++) { rowPattern += j + " "; } // Print descending numbers for (let j = i - 1; j >= 1; j--) { rowPattern += j + " "; } console.log(rowPattern.trim()); } } PrintPattern2(3); // ---------------------------------------------------------- //* Pattern - 3 function PrintPattern3(n) { for (let i = 1; i <= n; i++) { let rowPattern = ""; for (let j = 1; j <= n; j++) { if ((i + j) % 2 == 0) { rowPattern += "0 "; } else { rowPattern += "1 "; } } console.log(rowPattern); } } PrintPattern3(4); ================================================ FILE: DAY21/Questions.md ================================================ # DAY - 21 1. **Perfect Number** Write a program to determine if a number is a perfect number. - **Input:** **`number = 6`** - **Output:** **`Perfect Number`** - Explanation: 6 is a perfect number because its divisors (1, 2, 3) sum up to 6. 2. **Largest Prime Factor** Write a program to find the largest prime factor of a given number. - **Input:** **`number = 28`** - **Output:** **`7`** 3. **Sum of the series of n terms** Write a program to calculate the sum of the series 1 + 1/2 + 1/3 + ... + 1/n up to the nth term. - **Input:** **`n = 4`** - **Output:** **`2.083333`** ================================================ FILE: DAY21/Solutions.js ================================================ //* Perfect Number function PerfectNum(n) { if (n <= 0) { return `Input must be Posivitve Number`; } let sum = 0; for (let i = 1; i < n; i++) { if (n % i === 0) { sum += i; } } sum === n ? console.log(`${n} is a Perfect Number`) : console.log(`${n} is Not a perfect number`); } PerfectNum(28); // ---------------------------------------------------------- //* Largest Prime Factor function isPrime(n) { if (n <= 1) return false; for (let i = 2; i < Math.sqrt(n); i++) { if (n % i == 0) return false; } return true; } function LargestPrimeFactor(num) { if (num <= 1) return "No prime factors"; let MaxPrime = -1; for (let i = 2; i < Math.sqrt(num); i++) { if (num % i == 0 && isPrime(i)) { MaxPrime = i; } } // Check if the remaining number is a prime factor // if (num > 1 && isPrime(num)) { // MaxPrime = num; // } return MaxPrime; } console.log(LargestPrimeFactor(13195)); // --------------------------------------------------------- //* Sum of Series of n terms function SumSeries(n) { if (n <= 0) { return `Input must be Posivitve Number`; } let sum = 0; for (let i = 1; i <= n; i++) { sum = sum + 1 / i; } return parseFloat(sum.toFixed(3)); } console.log(SumSeries(4)); ================================================ FILE: DAY22/Questions.md ================================================ # DAY - 22 1. **Print the Array in Sorted Order (Ascending and Descending):** Write a program to sort an array in ascending and descending order. For example: - **Input:** **`[5, 3, 8, 1]`** - **Output:** ``` Ascending: [1, 3, 5, 8] Descending: [8, 5, 3, 1] ``` 2. **Finding the Longest Sequence of Consecutive 1s in a Binary Array** Write a program to find the longest sequence of consecutive 1s in a binary array. - **Input:** binaryArray = [1, 1, 0, 1, 1, 1] - **Output:** 3 3. **Finding the Most Frequent Element in an Array** Write a program to find the most frequent element in an array. - **Input:** array = [1, 2, 2, 3, 3, 3] - **Output:** 3 ================================================ FILE: DAY22/Solutions.js ================================================ //* Print the Array in Sorted Order (Ascending and Descending) /* Built-In Methods Ascending Order : arr.sort((a, b) => a - b); Descending Order : arr.sort((a, b) => b - a); */ function SortAscendingOrder(arr) { for (let i = 0; i < arr.length - 1; i++) { for (let j = i + 1; j < arr.length; j++) { if (arr[i] > arr[j]) { let temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } return arr; } function SortDescendingOrder(arr) { for (let i = 0; i < arr.length - 1; i++) { for (let j = i + 1; j < arr.length; j++) { if (arr[i] < arr[j]) { let temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } return arr; } console.log(SortAscendingOrder([5, 3, 8, 1])); console.log(SortDescendingOrder([5, 3, 8, 1])); // --------------------------------------------------------------------------- //* Finding the Longest Sequence of Consecutive 1s in a Binary Array function LongConsequence1(arr) { let count = 0; for (let i = 0; i < arr.length; i++) { if (arr[i] == 1) { count++; } else { count = 0; } } return count; } console.log(LongConsequence1([1, 1, 0, 1, 1, 1, 1])); // -------------------------------------------------------------------------- //* Finding the Most Frequent Element in an Array // Return the most frequent number, else returns -1 function MostFrequentElement(arr) { let FrequentNum = -1; let MaxCount = 0; for (let i = 0; i < arr.length; i++) { let count = 0; for (let j = 0; j < arr.length; j++) { if (arr[i] == arr[j]) { count++; } } if (MaxCount < count) { MaxCount = Math.max(MaxCount, count); MaxCount > 1 ? (FrequentNum = arr[i]) : (FrequentNum = -1); } } return FrequentNum; } console.log(MostFrequentElement([1, 2, 3, 4, 5])); ================================================ FILE: DAY23/Questions.md ================================================ # DAY - 23 1. **Find the Missing Number in an Array** - Given an array of numbers from 1 to n with one number missing, find the missing number. - **Input:** **[1, 2, 4, 5, 6]** - **Output:** **Missing Number: 3** 2. **Find the Majority Element in an Array** - Find the element that appears more than n/2 times in the array (if any). - **Input:** **[3, 3, 4, 2, 4, 4, 2, 4, 4]** - **Output:** **Majority Element: 4** 3. **Reverse an Array** - Reverse the order of elements in the given array. - **Input:** **[1, 2, 3, 4, 5]** - **Output:** **[5, 4, 3, 2, 1]** ================================================ FILE: DAY23/Solutions.js ================================================ //* Missing Number function FindMissingNum(arr) { let MissingNum = null; let n = arr.length + 1; let TotalSum = (n * (n + 1)) / 2; let ActualSum = arr.reduce((acc, currNum) => acc + currNum, 0); MissingNum = TotalSum - ActualSum; return MissingNum; } console.log(FindMissingNum([1, 2, 4, 5, 6])); // ----------------------------------------------------------------- //* Majority Element function FindMajorityElement(arr) { let MajorityCount = arr.length / 2; let MajorityElem = 0; for (let i = 0; i < arr.length; i++) { let count = 0; for (let j = 0; j < arr.length; j++) { if (arr[i] == arr[j]) { count++; } } if (count > MajorityCount) { MajorityCount = count; MajorityElem = arr[i]; } } return MajorityElem; } console.log(FindMajorityElement([3, 3, 4, 2, 4, 4, 2, 4, 4])); // --------------------------------------------------------------- //* Reverse an Array /* arr.reverse() method returns a new array with the desired result, but it also modifies the existing array as well arr.toReversed() method returns a new array with the desired result, but it will not modify the existing array. */ function ReverseArray(arr) { // let reversedArr = arr.reverse(); let reversedArr = arr.toReversed(); // console.log(arr); console.log(reversedArr); } ReverseArray([1, 2, 3, 4, 5]); ================================================ FILE: DAY24/Questions.md ================================================ # DAY - 24 1. **Find the Second Largest Element in an Array** - Find the second largest element in the array. - **Input:** **[10, 20, 4, 45, 99]** - **Output:** **Second Largest: 45** 2. **Remove Duplicates from an Array** - Remove all duplicates from the given array and return the unique elements.. - **Input:** **[1, 2, 2, 3, 4, 1, 5]** - **Output:** **[1, 2, 3, 4, 5]** 3. **Move Zeros to the End of an Array** - Move all zeros in the array to the end while maintaining the relative order of non-zero elements. - **Input:** **[0, 1, 2, 0, 3, 4, 0]** - **Output:** **[1, 2, 3, 4, 0, 0, 0]** ================================================ FILE: DAY24/Solutions.js ================================================ //* Find the Second Largest Element in an Array function FindSecondLargest(arr) { if (arr.length < 2) { return "Array must have atleast two elements"; } let FirstMax = -Infinity; let SecondMax = -Infinity; for (let i = 0; i < arr.length; i++) { if (arr[i] > FirstMax) { SecondMax = FirstMax; FirstMax = arr[i]; } else if (arr[i] > SecondMax && arr[i] < FirstMax) { SecondMax = arr[i]; } } return SecondMax; } console.log(FindSecondLargest([10, 20, 4, 45, 99])); // ----------------------------------------------------------------- //* Remove Duplicates from an Array function RemoveDuplicates(arr) { let result = []; for (let i = 0; i < arr.length; i++) { let elem = arr[i]; if (!result.includes(elem)) { result.push(elem); } } return result; } console.log(RemoveDuplicates([1, 2, 2, 3, 4, 1, 5])); // ---------------------------------------------------------------- //* Move Zeros to the End of an Array function MoveZeroEnd(arr) { let result = []; let count = 0; for (let i = 0; i < arr.length; i++) { if (arr[i] == 0) { count++; } } for (let i = 0; i < arr.length; i++) { if (arr[i] != 0) { result.push(arr[i]); } } for (let i = 0; i < count; i++) { result.push(0); } return result; } console.log(MoveZeroEnd([0, 1, 2, 0, 3, 4, 0])); ================================================ FILE: DAY25/Questions.md ================================================ # DAY - 25 1. **Find the Frequency of Each Element in an Array** Calculate the frequency of each element in the array. - **Input: [1, 2, 2, 3, 1, 4, 5, 1]** - **Output: {1: 3, 2: 2, 3: 1, 4: 1, 5: 1}** 2. **Check Palindrome** Determine if a string reads the same backward as forward. - **Input: "madam"** - **Output: "Palindrome"** 3. **Count Words in a String** Count the number of words in a sentence. - **Input: "I love programming"** - **Output: 3** ================================================ FILE: DAY25/Solutions.js ================================================ //* Find the Frequency of Each Element in an Array function FindFrequencyofElements(arr) { let frequency = {}; for (let num of arr) { if (frequency[num]) { frequency[num]++; } else { frequency[num] = 1; } } return frequency; } console.log(FindFrequencyofElements([1, 2, 2, 3, 1, 4, 5, 1])); // --------------------------------------------------------------------- //* Check Palindrome function checkPalindromString(str) { let OriginalStr = str; let reverseStr = ""; let ptrJ = str.length - 1; for (let i = 0; i < str.length; i++) { if (str.charAt(i) == str.charAt(ptrJ)) { reverseStr = reverseStr + str.charAt(i); } ptrJ--; } if (reverseStr === OriginalStr) { return `"${OriginalStr}" is a Palindrome`; } else { return `"${OriginalStr}" is not a Palindrome`; } } console.log(checkPalindromString("madam")); // --------------------------------------------------------------------- //* Count Words in a String function FindWordsCount(str) { return str.split(" ").length; } console.log(FindWordsCount("I love programming")); ================================================ FILE: DAY26/Questions.md ================================================ # DAY - 27 1. **Longest Word in a Sentence** Find the longest word in a given sentence. - **Input: "The quick brown fox"** - **Output: "quick"** 2. **Find the First Non-Repeating Character** Identify the first character that does not repeat in the string. - **Input: "swiss"** - **Output: "w"** 3. **Find All Substrings of a String** Print all possible substrings of a string. - **Input: "abc"** - **Output: ["a", "b", "c", "ab", "bc", "abc"]** ================================================ FILE: DAY26/Solutions.js ================================================ //* Longest Word in a Sentence function LongestWord(sentence) { let sentenceArr = sentence.split(" "); let MaxCount = 0; let LongWord = ""; for (let i = 0; i < sentenceArr.length; i++) { if (sentenceArr[i].length > MaxCount) { MaxCount = sentenceArr[i].length; LongWord = sentenceArr[i]; } } return LongWord; } console.log(LongestWord("The quick brown fox")); // ---------------------------------------------------------------------------- //* Find the First Non-Repeating Character function NonRepeatingChar(str) { let frequency = {}; let NRC = ""; for (let char of str) { frequency[char] = (frequency[char] || 0) + 1; } for (let ch of str) { if (frequency[ch] == 1) { NRC = ch; break; } } return NRC; } console.log(NonRepeatingChar("swiss")); // ---------------------------------------------------------------------------- //* Find All Substrings of a String function PrintAllSubstrings(str) { let result = []; for (let i = 0; i < str.length; i++) { for (let j = i + 1; j <= str.length; j++) { result.push(str.substring(i, j)); } } return result; } function PrintAllSubstrings2(str) { let result = []; // add all single chat at once for (let i = 0; i < str.length; i++) { result.push(str.charAt(i)); } // Add substrings of length and above in sequence for (let i = 2; i <= str.length; i++) { for (let j = 0; j <= str.length - i; j++) { result.push(str.substring(j, j + i)); } } return result; } // console.log(PrintAllSubstrings("abc")); console.log(PrintAllSubstrings2("abc")); ================================================ FILE: DAY27/Questions.md ================================================ # DAY 27 1. **Check Anagrams** Determine if two strings are anagrams of each other. - **Input: "listen", "silent"** - **Output: "Anagrams"** 2. **Check if Two Strings are Rotations of Each Other** Check if one string is a rotation of another. NOTE : the order of characters matters in rotations. - **Input: "abcd", "cdab"** - **Output: "Yes"** 3. **Remove All Non-Alphabetic Characters** Remove all characters that are not letters. - **Input: "abc123!@#"** - **Output: "abc"** ================================================ FILE: DAY27/Solutions.js ================================================ //* Check Anagrams /* - An anagram string refers to a pair of strings that contain the exact same characters in the same frequency, but their order can be different. - Essentially, one string can be rearranged to form the other. - If the two input strings are identical to each other then, they are called "Trivial Anagrams" */ function CheckAnagrams(str1, str2) { if (str1.length !== str2.length) { return "Not Anagrams"; } else if (str1 === str2) { return "Trivial Anagrams"; } // Sort and compare let sortedStr1 = str1.split("").sort().join(""); let sortedStr2 = str2.split("").sort().join(""); return sortedStr1 === sortedStr2 ? "Anagrams" : "Not Anagrams"; } console.log(CheckAnagrams("listen", "silent")); // -------------------------------------------------------------------------- //* Check if Two Strings Have the Same Set of Characters /* - If str2 is a rotation of str1, then appending str1 to itself will contain str2 as a substring. */ function ValidRotationStrings(str1, str2) { if (str1.length !== str2.length) { return "NO"; } else if (str1 === str2) { return "YES"; } let concatenated = str1 + str1; return concatenated.includes(str2) ? "YES" : "NO"; } console.log(ValidRotationStrings("abcdd", "cdab")); // -------------------------------------------------------------------------- //* Remove All Non-Alphabetic Characters function RemoveNonAlphabets(str) { return str.replace(/[^a-zA-Z]/g, ""); } console.log(RemoveNonAlphabets("abc123!@#")); ================================================ FILE: DAY28/Questions.md ================================================ # DAY - 28 1. **Find Duplicate Characters in a String** Identify all characters that appear more than once in a string. - **Input: "programming"** - **Output: ["r", "g", "m"]** 2. **Count Vowels and Consonants** Count the number of vowels and consonants in a string. - **Input: "hello"** - **Output: Vowels: 2, Consonants: 3** 3. **Matrix Addition** Add two matrices of the same dimensions. - **Input:** ``` A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]] ``` - **Output:** ``` [[6, 8], [10, 12]] ``` ================================================ FILE: DAY28/Solutions.js ================================================ //* Find Duplicate Characters in a String function FindDuplicatesChars(str) { let result = []; for (let i = 0; i < str.length; i++) { let char = str.charAt(i); let count = 0; for (let j = 0; j < str.length; j++) { if (char === str.charAt(j)) { count++; } } if (count > 1 && !result.includes(char)) { result.push(char); } } console.log(result); } FindDuplicatesChars("programming"); // ----------------------------------------------------------------------- //* Count Vowels and Consonants function CountVowelsAndConsonants(str) { let StrLen = str.length; let Vowels = 0; for (let i = 0; i < StrLen; i++) { let char = str.charAt(i).toLowerCase(); if ( char === "a" || char === "e" || char === "i" || char === "o" || char === "u" ) { Vowels++; } } console.log(`Vowels:${Vowels} and Consonants: ${StrLen - Vowels}`); } CountVowelsAndConsonants("hello"); // ---------------------------------------------------------------------- //* Matrix Addition /* - To perform Addition, both matrices should have same no.of elements in row and column respectively. - Matrix.length => No.of rows in the matrix - Matrix[0].length => No.of columns in the first row */ function MatrixAddition(matrixA, matrixB) { if ( matrixA.length !== matrixB.length || matrixA[0].length !== matrixB[0].length ) { return "Two Matrices size must be same to perform Addition."; } let result = []; for (let i = 0; i < matrixA.length; i++) { let row = []; for (let j = 0; j < matrixA[i].length; j++) { row.push(matrixA[i][j] + matrixB[i][j]); } result.push(row); } return result; } // Sample Matrices let matA = [ [1, 2], [3, 4], ]; let matB = [ [5, 6], [7, 8], ]; console.log(MatrixAddition(matA, matB)); ================================================ FILE: DAY29/Questions.md ================================================ # DAY - 29 1. **Matrix Multiplication** Multiply two matrices if the number of columns in the first matrix equals the number of rows in the second. - **Input:** ``` A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]] ``` - **Output:** ``` [[19, 22], [43, 50]] ``` 2. **Search an Element in a Matrix** Search for a given element in a matrix and return its position. - **Input:** ``` A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], Target = 5 ``` - **Output:** ``` Position: (1, 1) (0-based index) ``` 3. **Matrix Transpose** Find the transpose of a matrix (convert rows to columns and vice versa). - **Input:** ``` A = [[1, 2, 3], [4, 5, 6]] ``` - **Output:** ``` [[1, 4], [2, 5], [3, 6]] ``` ================================================ FILE: DAY29/Solutions.js ================================================ //* Matrix Multipication /* # Matrix Multiplication Rules: - The no.of rows in the matrixA should be equal to the no.of columns matrixB. - The no.of columns in the matrixA should be equal to the no.of rows in the matrixB. */ function MatrixMultiplication(matrixA, matrixB) { if (matrixA[0].length !== matrixB.length) { return "Invalid Inputs, for this Question"; } let rowSize = matrixA.length; let columnSize = matrixB[0].length; let commonSize = matrixB.length; let result = []; for (let i = 0; i < rowSize; i++) { let row = []; for (let j = 0; j < columnSize; j++) { let sum = 0; for (let k = 0; k < commonSize; k++) { sum += matrixA[i][k] * matrixB[k][j]; } row.push(sum); } result.push(row); } return result; } let MatA = [ [1, 2], [3, 4], ]; let MatB = [ [5, 6], [7, 8], ]; console.log(MatrixMultiplication(MatA, MatB)); //---------------------------------------------------------------- //* Search an Element in a Matrix function SearchElementInMatrix(Matrix, target) { for (let i = 0; i < Matrix.length; i++) { for (let j = 0; j < Matrix[i].length; j++) { if (Matrix[i][j] === target) { return `Element is found at ${i} row, ${j} column`; } } } return "Element Not Found!"; } let MatrixA = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], ]; console.log(SearchElementInMatrix(MatrixA, 7)); // -------------------------------------------------------------- //* Matrix Transpose /* - If a matrix A has dimensions 𝑚×𝑛 (with 𝑚 rows and 𝑛 columns), its transpose 𝐴^𝑇 will have dimensions 𝑛×𝑚 (with 𝑛 rows and 𝑚 columns). - In the transpose matrix, the element at position 𝐴[𝑖][𝑗] in the original matrix becomes 𝐴^𝑇[𝑗][𝑖] */ function MatrixTranspose(matrix) { let rowSize = matrix.length; let columnSize = matrix[0].length; let TransposeMatrix = []; for (let i = 0; i < columnSize; i++) { let row = []; for (let j = 0; j < rowSize; j++) { row.push(matrix[j][i]); } TransposeMatrix.push(row); } return TransposeMatrix; } let Matrix = [ [1, 2, 3], [4, 5, 6], ]; console.log(MatrixTranspose(Matrix)); ================================================ FILE: DAY30/Questions.md ================================================ # DAY - 30 1. **Object Keys and Values** Print all the keys and values of an object. - **Input:** ``` let ``` - **Output:** ``` Keys: ["name", "age", "city"], Values: ["John", 25, "New York"] ``` 2. **Merge Two Objects** Combine the properties of two objects into one. - **Input:** ``` let obj1 = { name: "John", age: 25 }; let obj2 = { city: "New York", country: "USA" }; ``` - **Output:** ``` { name: "John", age: 25, city: "New York", country: "USA" } ``` 3. **Swap Keys and Values** Create a new object where the keys and values are swapped. - **Input:** ``` let obj = { name: "John", age: 25, city: "New York" }; ``` - Output: ``` { John: "name", 25: "age", "New York": "city" } ``` ================================================ FILE: DAY30/Solutions.js ================================================ //* Object Keys and Values let obj = { name: "John", age: 25, city: "New York" }; let obj1 = { name: "John", age: 25 }; let obj2 = { city: "New York", country: "USA" }; // ------------------------------------------------------------------------------------------ function PrintKeysValues(Obj) { console.log("Keys : ", Object.keys(Obj)); console.log("Values: ", Object.values(Obj)); } PrintKeysValues(obj); // ------------------------------------------------------------- //* Merge two Objects function MergeObjects(Obj1, Obj2) { return Object.assign({}, Obj1, Obj2); } console.log(MergeObjects(obj1, obj2)); // ------------------------------------------------------------- //* Swap Keys and Values function SwapKeysValues(Obj) { let result = {}; for (key in Obj) { result[Obj[key]] = key; } return result; } console.log(SwapKeysValues(obj)); ================================================ FILE: DAY31/Questions.md ================================================ # DAY - 31 1. **Compare Two Objects** Check if two objects have the same keys and values. - **Input:** ``` let obj1 = { a: 1, b: 2, c: 3 }; let obj2 = { a: 1, b: 2, c: 3 }; ``` - **Output:** true 2. **Convert an Array of Objects to a Single Object** Create an object where each element of the array becomes a property. - **Input:** ``` let arr = [ { id: "a", value: 1 }, { id: "b", value: 2 }, { id: "c", value: 3 }, ]; ``` - **Output:** ``` { a: 1, b: 2, c: 3 } ``` 3. **Group Objects by a Property** Group an array of objects by a specified property. - **Input:** ``` let arr = [ { category: "fruit", name: "apple" }, { category: "fruit", name: "banana" }, { category: "vegetable", name: "carrot" }, ]; ``` - **Output:** ``` { fruit: [{ category: "fruit", name: "apple" }, { category: "fruit", name: "banana" }], vegetable: [{ category: "vegetable", name: "carrot" }] } ``` ================================================ FILE: DAY31/Solutions.js ================================================ let obj1 = { a: 1, b: 2, c: 3 }; let obj2 = { a: 1, b: 2, c: 3 }; let arr1 = [ { id: "a", value: 1 }, { id: "b", value: 2 }, { id: "c", value: 3 }, ]; let arr2 = [ { category: "fruit", name: "apple" }, { category: "fruit", name: "banana" }, { category: "vegetable", name: "carrot" }, ]; // ----------------------------------------------------------------- //* Compare Two Objects function CompareTwoObjects(Obj1, Obj2) { if (Object.keys(Obj1).length !== Object.keys(Obj2)) { return false; } for (let key in Obj1) { if (Obj1[key] !== Obj2[key]) { return false; } } return true; } console.log(CompareTwoObjects(obj1, obj2)); // -------------------------------------------------------------------- //* Convert an Array of Objects to a Single Object function ConvertToObject(arr) { let result = {}; for (let i = 0; i < arr.length; i++) { result[arr[i].id] = arr[i].value; } return result; } function ConvertToObject2(arr) { let result = arr.map((item) => [item.id, item.value]); // console.log(result); result = Object.fromEntries(result); return result; } console.log(ConvertToObject(arr1)); // console.log(ConvertToObject2(arr1)); // -------------------------------------------------------------------- //* Group Objects by Property function GroupObjects(arr) { let Grouped = {}; for (let i = 0; i < arr.length; i++) { let key = arr[i].category; if (!Grouped[key]) { Grouped[key] = []; } Grouped[key].push(arr[i]); } return Grouped; } function GroupObjects2(arr) { return arr.reduce((Grouped, item) => { let key = item.category; if (!Grouped[key]) { Grouped[key] = []; } Grouped[key].push(item); return Grouped; }, {}); } console.log(GroupObjects(arr2)); // console.log(GroupObjects2(arr2)); ================================================ FILE: DAY32/Questions.md ================================================ # DAY - 32 1. **Clone an Object** Create a shallow copy of an object. - **Input:** ``` let obj = { name: "John", age: 25, city: "New York" }; ``` - **Output:** ``` { name: "John", age: 25, city: "New York" } ``` 2. **Flatten a Nested Object** Convert a deeply nested object into a single-level object. - **Input:** ``` let obj = { a: 1, b: { c: 2, d: { e: 3 } } }; ``` - **Output:** ``` { a: 1, "b.c": 2, "b.d.e": 3 } ``` 3. **Sum of N Natural Numbers using Recursion** Write a Program to Find the Sum of N Natural Numbers using Recursion - **Input:** ``` Enter a number: 5 ``` - **Output:** ``` The sum of the first 5 natural numbers is: 15 ``` ================================================ FILE: DAY32/Solutions.js ================================================ let obj1 = { name: "John", age: 25, city: "New York" }; let obj2 = { a: 1, b: { c: 2, d: { e: 3 } } }; // ----------------------------------------------------------------- //* Clone an Object function CloneObject(Obj) { // using spread operator let ObjCopy1 = { ...Obj }; // using Object.assign(target, obj) let ObjCopy2 = Object.assign({}, Obj); return ObjCopy2; } console.log(CloneObject(obj1)); // ----------------------------------------------------------------- //* Flatten a Nested Object function FlattenNestedObject(Obj) { let result = {}; let keysToProcess = Object.entries(Obj); while (keysToProcess.length > 0) { // get the first key value pair let [currentkey, value] = keysToProcess.shift(); if (typeof value === "object" && value !== null) { // If the value is an object, iterate over its keys for (let subkey in value) { let newkey = `${currentkey}.${subkey}`; // flatten the key keysToProcess.push([newkey, value[subkey]]); } } else { // If it's not an object, add it to the result result[currentkey] = value; } } return result; } console.log(FlattenNestedObject(obj2)); // ---------------------------------------------------------------- //* Sum of N Natural Numbers using Recursion function SumOfNRecursion(N) { // Base condition if (N === 1) { return 1; } // recurrence relation return N + SumOfNRecursion(N - 1); } console.log(SumOfNRecursion(5)); ================================================ FILE: DAY33/Questions.md ================================================ # DAY - 33 1. **Factorial of a Number Using Recursion** The factorial of a number is the product of all positive integers less than or equal to the number. - **Input: n = 5** - **Output: 120 (since 5!=5×4×3×2×1)** 2. **Calculates the Power of a Number Using Recursion** Write a Program that Calculates the Power of a Number Using Recursion - **Input: base = 2, exponent = 3** - **Output: 8 (since 2^3 => 2 x 2 x 2 = 8)** 3. **Fibonacci Series Using Recursion** The Fibonacci series is a sequence where each number is the sum of the two preceding ones. The sequence starts with 0 and 1. This program calculates the nth Fibonacci number recursively. - **Input: n = 5** - **Output: 0, 1, 1, 2, 3** ================================================ FILE: DAY33/Solutions.js ================================================ //* Factorial of a Number Using Recursion function FactorialRecursion(N) { if (N === 1) { return 1; } return N * FactorialRecursion(N - 1); } console.log(FactorialRecursion(5)); // -------------------------------------------------------------------- //* Calculates the Power of a Number Using Recursion function PowerOfNum(base, exponent) { if (exponent === 0) { return 1; } return base * PowerOfNum(base, exponent - 1); } console.log(PowerOfNum(2, 3)); // --------------------------------------------------------------------- //* Fibonacci Series Using Recursion function FibonacciSeriesRecursion(n, series = []) { // Base case: Series starts with 0 if (n == 0) { return [0]; } // Base case: Series for n = 1 is [0, 1] if (n == 1) { return [0, 1]; } let prevSeries = FibonacciSeriesRecursion(n - 1, series); let nextNum = prevSeries[prevSeries.length - 1] + prevSeries[prevSeries.length - 2]; prevSeries.push(nextNum); return prevSeries; } console.log(FibonacciSeriesRecursion(5)); ================================================ FILE: DAY34/Questions.md ================================================ # DAY - 34 1. **Check if a String is a Palindrome** Check whether a given string is a palindrome using recursion. - **Input: str = "radar"** - **Output: true** 2. **Find GCD of Two Numbers** Calculate the greatest common divisor (GCD) of two numbers using recursion. - **Input: a = 56, b = 98** - **Output: 14** 3. **Binary Representation of a Number** Find the binary representation of a given number using recursion. - **Input: num = 10** - **Output: "1010"** ================================================ FILE: DAY34/Solutions.js ================================================ //* Check if a String is a Palindrome function checkPlaindromeRecursion(str, start = 0, end = str.length - 1) { // base case : Single character or empty string if (start >= end) { return "true"; } if (str.charAt(start) !== str.charAt(end)) { return false; } return checkPlaindromeRecursion(str, start + 1, end - 1); } console.log(checkPlaindromeRecursion("radar")); // ---------------------------------------------------------------------- //* Find GCD of Two Numbers function FindGCDRecursion(num1, num2) { if (num2 == 0) { return num1; } return FindGCDRecursion(num2, num1 % num2); } console.log(FindGCDRecursion(56, 98)); // --------------------------------------------------------------------- //* Binary Representation of a Number function BinaryRepresentationRecursion(n) { // base condition if (n === 0) { return ""; } let quotient = Math.floor(n / 2); let result = n % 2; return BinaryRepresentationRecursion(quotient) + result; } console.log(BinaryRepresentationRecursion(10)); ================================================ FILE: readme.md ================================================ # LogicBuilding101 - Welcome to **LogicBuilding101**, a curated collection of **101+1 must-do problems** designed to build your programming logic from scratch. - This repository serves as a foundational resource for anyone who wants to sharpen their problem-solving skills before diving into Data Structures and Algorithms (DSA). ## Overview - This repository is structured to take you on a journey from the basics of programming to slightly advanced concepts, focusing on logic-building exercises. - Over **34 days**, with a daily commitment of solving 3 problems, you can develop a strong programming foundation. ### Problem Categories 1. **Basic Math Problems** 2. **Basic Patterns** 3. **Intermediate Math Problems** 4. **Medium Patterns** 5. **Arrays** 6. **Matrix** 7. **Strings** 8. **Objects** 9. **Basic Recursion** ### Why LogicBuilding101? - Develop **core programming skills**. - Understand basic and intermediate concepts of programming. - Lay a strong foundation for **DSA preparation**. - Practice a diverse set of problems from simple **math** to **recursion**. --- ## Repository Structure The repository is divided into **daily problem sets**, with each day containing 3 problems: ``` LogicBuilding101/ ├── Day01/ │ ├── Questions.md │ ├── Solutions.js ├── Day02/ │ ├── Questions.md │ ├── Solutions.js ... ├── Day34/ │ ├── Questions.md │ ├── Solutions.js ``` ### Questions File Structure Each Questions file contains: - **Problem Name**: The title of the problem. - **Description**: A detailed explanation of the problem. - **Input/Output**: Sample input and output examples. --- ## How to Use This Repo 1. Clone the repository: ```bash git clone https://github.com/upendhar10/LogicBuilding101.git ``` 2. Start with Day 1 and progress at your own pace. 3. Solve the problems in your preferred programming language. 4. Check your logic and solutions with the provided examples. --- ## Acknowledgments - A huge thanks to the programming community for inspiring this project. Let's build a strong foundation together! - If you found this repo valuable, don't forget to **STAR** this repo. Thanks in advance! --- ## License This project is licensed under the MIT License. Feel free to use and share!