Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Arnab Chakraborty
Page 18 of 377
Area of a circle inscribed in a rectangle which is inscribed in a semicircle?
Let us consider a semicircle with radius R. A rectangle of length l and breadth b is inscribed in that semicircle. Now a circle with radius r is inscribed in the rectangle. We need to find the area of the inner circle. R l b r ...
Read MoreArc length from given Angle?
Here we will see how to calculate the arc length from a given angle. When a circle with radius r is given and we know the angle x in degrees, we can find the arc length using a simple formula. r L x° Here r is the radius and x is the angle in degrees. We need to find the value of L (arc length). The formula is − Syntax L = ...
Read MoreAn interesting solution to get all prime numbers smaller than n?
Here we will see how to generate all prime numbers that are less than n using Wilson's theorem. According to Wilson's theorem, if a number k is prime, then ((k - 1)! + 1) mod k will be 0. This approach provides a mathematical foundation for prime detection. Note: This method is primarily of theoretical interest because factorial calculations grow extremely large, making it impractical for larger values of n in standard programming languages. Syntax void genAllPrimes(int n); // Generates all prime numbers less than n using Wilson's theorem Algorithm Begin ...
Read MoreAn Interesting Method to Generate Binary Numbers from 1 to n?
Here we will see one interesting method for generating binary numbers from 1 to n. This approach uses a queue data structure to generate binary representations in sequence. Initially the queue holds the first binary number '1'. We repeatedly remove elements from the queue, print them, then append '0' and '1' to create the next binary numbers and insert them back into the queue. Algorithm genBinaryNumbers(n) Begin define empty queue insert "1" into the queue while n is not 0, do delete ...
Read MoreAn efficient way to check whether n-th Fibonacci number is multiple of 10?
Here we will see one efficient way to check whether the nth Fibonacci term is multiple of 10 or not. Suppose the Fibonacci terms are {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987}. So here 15th (counting from 0) Fibonacci term is divisible by 10. One easiest method is generating Fibonacci numbers up to given term, and check whether it is divisible by 10 or not. But this solution is not good, because it will not work for larger terms due to overflow and time complexity issues. Approach ...
Read MoreAmazing stuff with system() in C / C++?
The system() function in C allows you to execute operating system commands directly from your C program. This function is available on Windows, Linux, and macOS, making it a powerful tool for interacting with the system shell and running command-line programs. Syntax #include int system(const char *command); Note: The examples below use system-specific commands that cannot be executed in an online compiler. They are provided for educational purposes to demonstrate system() function usage. Example 1: Getting Network Configuration This example shows how to retrieve IP configuration details on a Windows ...
Read MoreAll possible strings of any length that can be formed from a given string?
In this section we will see how to generate all possible strings of any length from a given string. This approach takes each combination of characters to make strings and then generates all permutations of each combination. For example, if the string is "ABC", then it will generate − {A, B, C, AB, BA, BC, CB, CA, AC, ABC, ACB, BAC, BCA, CAB, CBA} Syntax void printAllString(char str[]); Algorithm printAllString(str) Begin n := length of the string str count is 2^n – 1 ...
Read MoreAll possible numbers of N digits and base B without leading zeros?
Here we will see one problem where we have N and base B. Our task is to count all N digit numbers of base B without any leading zeros. So if N is 2 and B is 2, there will be four numbers: 00, 01, 10, 11. Only two of them are valid for this problem − 10 and 11, as they have no leading zeros. If the base is B, then there are 0 to B − 1 different digits. So BN number of different N digit values can be generated (including leading zeros). Numbers with leading zero ...
Read MoreAll possible co-prime distinct element pairs within a range [L, R]?
Here we will see how to count the number of co-prime pairs from a given range, where each number appears in at most one pair. Before discussing the logic, let us understand what co-prime numbers are. Co-prime numbers are two numbers that have no common positive divisors other than 1. In other words, the GCD (Greatest Common Divisor) of these two numbers is 1. For example, if the lower and upper limits are 1 and 6, then there are three possible pairs: (1, 2), (3, 4), and (5, 6). Each of these pairs consists of consecutive numbers, which ...
Read MoreAll possible binary numbers of length n with equal sum in both halves?
In this problem, we generate all possible binary numbers of length n where the sum of digits in the left half equals the sum of digits in the right half. For example, in the 6-bit number "100001", the left half "100" has sum 1 and the right half "001" also has sum 1, making them equal. Syntax void genAllBinEqualSumHalf(int n, char left[], char right[], int diff); Algorithm The algorithm uses recursion with backtracking − Base Case 1: When n = 0, if difference is 0, print the concatenated result Base Case 2: ...
Read More