Author: devangini123

πŸŒ™ Problem Statement: Write a program to print all even numbers from an array. Example: Input: [10, 3, 5, 2, 7, 6, 9] Output: 10 2 6 Approach: Iterate through each element in the array. Check if the element is divisible by 2. If yes, print the element (it’s even). Visualisation: JavaScript Python Java C++ C C# let arr = [10, 3, 5, 2, 7, 6, 9]; for (let i = 0; i < arr.length; i++) { if (arr[i] % 2 === 0) { console.log(arr[i]); } } arr = [10, 3, 5, 2, 7, 6, 9] for num in arr:…

Read More

πŸŒ™ Problem Statement: Write a function that accepts a number and checks whether it is Even or Odd. If the number is divisble by 2, it’s an Even number. Otherwise, it’s an Odd number. Test the function with inputs 18 and 5. Example Input: 18 β†’ Output: Even Number Input: 5 β†’ Output: Odd Number Approach Create a function that takes a number. If number % 2 === 0, return “Even”. Else return “Odd”. Visualisation: Explanation: ● Accept the input number in the function. ● Check if the number modulo 2 equals 0. ● If yes, print or return “Even”.…

Read More

πŸŒ™ Problem Statement: Write a program that accepts a number (age) and checks whether the person is eligible to vote. A person is eligible if their age is 18 or more. Example: Input: 20 Process: Check if 20 β‰₯ 18 β†’ Eligible Output: You are eligible to vote. Approach: Take input from the user (or define a variable). Use a conditional statement to check if age is 18 or above. If yes, print β€œYou are eligible to vote.” Otherwise, print β€œYou are not eligible to vote.” Visualisation: Explanation: ● Accept age as input. ● Use if age >= 18 to…

Read More

πŸŒ™ Problem Statement: Write a function that takes an integer and returns its square. Call this function and prints the result. Square(x) is a function that computes the square of a number. It returns the result instead of printing it. Example: Input: 3 Process: square(3) = 3 Γ— 3 = 9 Output: The square is: 9 Approach: Define a function that takes one integer as input. Compute the square of the number (multiply it by itself). Return the result from the function. Call the function and print the returned value. Visualisation: Explanation: ● Square(x) is a function that takes an…

Read More

πŸŒ™ Problem Statement: Write a Program that defines a function to calculate the sum of two integers and prints the result. Call this function by passing two integer values. Approach: Define a function that takes two numbers as input. Add the two numbers inside the function. Call the function with two integers & print the result. Example: Input: 5, 3 Process: a + b => 5 + 3 = 8 Output: 8 Visualisation: Explanation: ● Sum(a, b) is a function that takes two arguments. ● Adds them and stores the result in a variable named add. ● Prints the result.…

Read More