Category Archives: Program

What is a Program? – Here’s Everything You Need to Know

A computer program, or simply a program, is a sequence of instructions that instructs the system to perform a particular task. For example, we use Google Maps to find a specific location and directions to that location. This application is instructed to do so via a program. If you want to explore more about a program or a… Read More »

Missing Numbers

Problem Given an integer array in which all numbers occur twice except 2. Find those two numbers. Sample Input 1, 2, 2, 3, 4, 4 Sample Output 1 3 Explanation 1 and 3 occur once Approach Let’s look at some properties of XOR: a ⊕ b = b ⊕ a and a ⊕ (b ⊕ c) = (a… Read More »

Add elements of two arrays into a new array

Problem Given two arrays of positive integers, add their elements into a new array. You should add both arrays, one by one starting from the 0th index, and split the sum into individual digits if it is a multi-digit number. Sample Input [23, 5, 2, 7, 87] [4, 67, 2, 8] Sample Output [2, 7, 7, 2, 4,… Read More »

Check if an array is formed by consecutive integers

Problem Given an unsorted array of numbers, check if the array consists of consecutive numbers only. Sample Input [1, 2, 3, 4] Sample Output YES Approach 1 You can sort the array and check if all adjacent elements have absolute difference as 1. If any pair with a difference other than 1 is found, return False. This approach… Read More »

Write a Program to calculate area of a circle, a rectangle or a triangle depending upon user’s choice

Problem Statement  We need to write a program in C, C++, and Python, that is capable of returning the area of a circle, rectangle, and triangle based on the user choice and input. First, the user has the choice to select the geometry for which he/she wants to calculate the area. Then based on the geometry shape selected… Read More »

Write a Program to print the truth table for XY+Z

Problem Statement We need to write a program that can print a truth table for the logic XY+Z. The XY+Z logic shows a AND operator between X and Y, and an OR operator between XY and Z. Algorithm The algorithm for this logic is pretty simple. We just need to create a nested three-level loop where the outermost… Read More »

Problem Statement We need to write a program in C, C++, and Python, that creates a loading bar on the console window. All these three programming languages support third-party packages or libraries to print a loading progress bar, but we will use the basic coding to implement one of our own. Algorithm The idea behind creating a process… Read More »

Write a Program to Print the Following Pattern

Problem Statement We need to write a script in C, C++, and Python that can print the following pattern of Alphabets based on the user’s entered letter. Input  letter = F Output A AB ABC ABCD ABCDE ABCDEF Algorithm Ask the user to enter the height of the pattern h which ranges between 1 to 26 (A to… Read More »

Write a Program to Print the Following Triangle

Problem Statement 1 We need to write a program in C, C++, and Python that can print the following triangle pattern, based on the user entered height. Let say the height of the triangle is 8 Input: height =8 Output * ** *** **** ***** ****** ******* ******** Algorithm The algorithm of this problem is pretty straightforward. Ask… Read More »

Write a Program to Print Three Numbers in Descending Order

Let’s say that we have three numbers and we need to sort them in descending order. How would we do that? Well, the answer is that we will use the if-else statement. Every high-level programming language supports if-else statements. In this programming tutorial, we will learn how to print three numbers in descending order. The program that we… Read More »