Found 26504 Articles for Server Side Programming

Haskell Program to find the GCD using library function

Akhil Sharma
Updated on 13-Mar-2023 14:50:14

237 Views

In Haskell, we will find the GCD using library function like gcd, div function and recursion. In the first example, we are going to use gcd (a b) function and in the second example, we are going to use (a `div` b) function. In third example, we are going to use recursion. Method 1: Finding the GCD using gcd function In this method, the gcd function takes two integers as input and returns the greatest common divisor of these two numbers. This function is defined in the Prelude library. Algorithm Step 1 − Program execution will be started from ... Read More

Haskell Program to check the given number is an EVEN number using library function

Akhil Sharma
Updated on 13-Mar-2023 14:48:37

1K+ Views

In Haskell, we can use library function like mod, even and quot to check whether, the given number is an EVEN number or not. In this article we are going to have examples that are using n `mod` 2 == 0 even function as well as n `quot` 2 == 0 function. Algorithm Step 1 − The isEven function is defined using mod function as, isEven n = n `mod` 2 == 0. Step 2 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main ... Read More

Perfect Power (1, 4, 8, 9, 16, 25, 27, …)

Eva Sharma
Updated on 10-Mar-2023 12:35:48

1K+ Views

A Perfect Power is a Natural Number that is the product of equal natural factors. It can also be defined as an integer that can be expressed as a square power or a higher power of another integer greater than one. For example, 4 can be expressed as the product of 2*2. 27 can be expressed as the product of 3*3*3. Hence, 4 and 27 are perfect powers. Problem Statement Given a number n, find the count of perfect numbers which are less than or equal to n. Example 1 Input = 14 Output = 3 Explanation 1 ... Read More

Legendre’s Conjecture: Concept, Algorithm, Implementation in C++

Eva Sharma
Updated on 10-Mar-2023 12:31:11

286 Views

The Legendre’s Conjecture states that at least one prime number always exists between two consecutive natural numbers' squares. Mathematically, there is always a prime number p between any two numbers n2 and (n+1)2. n is a natural number. A conjecture means a conclusion that doesn't has mathematical proof. Hence, Legendre's Conjecture is just a statement with no mathematical proof. Problem Statement For a number n, print the number of primes in the range of n2 to (n+1)2 from 1 to n. Examples Input: 4 Output: For i = 1: Total primes in the range 1 and 4 = 2 ... Read More

Form a Number Using Corner Digits of Powers

Eva Sharma
Updated on 10-Mar-2023 12:17:23

163 Views

What are Corner digits? The corner digits of a number refer to the rightmost and the leftmost digits. For example, the corner digits of 1234 are 1 and 4. The corner digits of a single-digit number will be the number twice. For example, the corner digits of 2 will be 2 and 2. Problem Statement For given two numbers, n, and x, form a number using the corner digits of all the powers of n from 1 and x, i.e., n1, n2....nx. Examples Input: n = 2, x = 4 Output: 22448816 Explanation 21 = 2. Corner digits = ... Read More

Decimal Equivalent of Gray Code and Its Inverse

Eva Sharma
Updated on 10-Mar-2023 12:08:16

1K+ Views

Gray code or reflected binary code is a form of a binary representation of numbers in which two consecutive numbers only differ by one bit. For example, the gray code of 1 is 001, while the gray code of 2 is 011. Gray code is usually used in error correction because it prevents some data errors that can happen in the usual binary representations while state changes. Gray code is also helpful in k-maps, communication, etc., because of its unique property. Prerequisite Study decimal, binary and gray code notations before reading further. Problem Statement 1 Given a decimal number n, ... Read More

Cube Free Numbers smaller than n

Eva Sharma
Updated on 10-Mar-2023 12:01:22

375 Views

Cube-free numbers are those numbers that have no cubic divisors. A cubic divisor refers to an integer that is a cube and divides the number with zero remainders. For example, 8 is a cubic divisor of 16 since 8 is a cube of 2 (2*2*2 = 8), and 8 divides 16 with the remainder of zero. Thus, 8 and 16 both are not cube-free numbers. Problem Statement Find all the cube-free numbers less than a given number, n. Example Let's understand the problem with an example. Let n = 15, Thus, we have to find all the numbers less than ... Read More

Square pyramidal number (Sum of Squares)

Eva Sharma
Updated on 10-Mar-2023 11:58:22

324 Views

A Square Pyramidal Number means the Sum of the Square of Natural Numbers. Natural Numbers include all the numbers from 1 to infinity. For example, the first 4 Square pyramidal numbers are 1, 5, 14, 30. For better perception, consider the fact: If we take spheres of numbers equal to the square pyramidal numbers, starting from one, and stack them in descending order, they create a pyramid. Problem Statement Given a number Sum. If Sum is the sum of the squares of first “n” natural numbers, return n, otherwise return false. Example 1 Input = 30 Output = 4 ... Read More

Pandas series Vs. single-column DataFrame

Premansh Sharma
Updated on 10-Mar-2023 14:09:06

12K+ Views

Introduction This article compares and contrasts Python's Pandas library's single-column DataFrames and Pandas Series data structures. The goal of the paper is to clearly explain the two data structures, their similarities and differences. To assist readers in selecting the best alternative for their particular use case, it contains comparisons between the two structures and practical examples on aspects like data type, indexing, slicing, and performance. The essay is appropriate for Python programmers at the basic and intermediate levels who are already familiar with Pandas and wish to get a deeper grasp of these two key data structures. What is Pandas? ... Read More

Handling duplicate values from datasets in python

Premansh Sharma
Updated on 10-Mar-2023 18:00:38

6K+ Views

Introduction The handling of duplicate values in datasets using Python is covered in this article. It defines duplicate values, shows how to spot them in a Pandas DataFrame, and offers many solutions for dealing with them, including removing duplicates, maintaining the first or last occurrence, and substituting alternative values for duplicates. The need of managing duplicate values is emphasized throughout the paper to support correct data analysis and machine learning models. In every project involving data analysis or machine learning, cleansing the data is a crucial step. The occurrence of duplicate values in datasets is one of the most prevalent ... Read More

Advertisements