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
Server Side Programming Articles
Page 584 of 2109
Python Program for nth multiple of a number in Fibonacci Series
The Fibonacci series is a sequence where each number is the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34... In this article, we'll find the position of the nth multiple of a given number k in the Fibonacci series. Problem Statement Given a number k and a value n, we need to find the position of the nth multiple of k in the Fibonacci series. For example, if k=4 and n=5, we find the 5th number in the Fibonacci series that is divisible by 4. Understanding the Approach ...
Read MoreFind sum of even factors of a number in Python Program
Finding the sum of even factors of a number involves identifying all numbers that divide evenly into the given number, then summing only the even factors. What are Factors? Factors are numbers that completely divide a given number, leaving zero as remainder. For example, the factors of 12 are: 1, 2, 3, 4, 6, and 12. For even factors, we only consider factors that are divisible by 2. If the given number is odd, it will have no even factors (except possibly 1, which isn't even). Example Analysis Let's examine the factors of 60: ...
Read MorePython Program for Efficient program to print all prime factors of a given number
In this article, we will learn about an efficient solution to find and print all prime factors of a given number. Prime factors are prime numbers that divide the given number exactly. Problem statement − We are given a number, we need to find all the prime factors of a given number. Algorithm Approach The efficient solution follows these steps: First, divide the number by 2 as much as possible Then check odd numbers from 3 up to √n If any remainder exists greater than 2, it's also a prime factor Example ...
Read MorePython program to find uncommon words from two Strings
In this article, we will learn how to find uncommon words from two strings. Uncommon words are words that appear exactly once across both strings combined. Problem statement − We are given two strings, we need to get the uncommon words from the given strings. Understanding Uncommon Words A word is considered uncommon if it appears exactly once when we combine both strings. For example: String 1: "hello world" String 2: "world python" Uncommon words: "hello", "python" (each appears once) "world" appears twice, so it's not uncommon Using Dictionary to Count Word Frequency ...
Read MorePython program to find number of local variables in a function
In this article, we will learn how to find the number of local variables in a function using Python's built-in code object attributes. Problem statement − We are given a function, and we need to display the number of local variables defined within that function. Understanding Local Variables Local variables are variables that are defined inside a function and can only be accessed within that function's scope. Python stores information about functions in code objects, which include the count of local variables. Using __code__.co_nlocals Every function in Python has a __code__ attribute that contains a ...
Read MorePython Program to Count trailing zeroes in factorial of a number
In this article, we will learn how to count the number of trailing zeros in the factorial of a given number without actually computing the factorial itself. Problem statement − We are given an integer n, we need to count the number of trailing zeros in n! (factorial of n). Understanding the Concept Trailing zeros are produced by factors of 10, and 10 = 2 × 5. In any factorial, there are always more factors of 2 than factors of 5, so we only need to count the factors of 5. ...
Read MorePython Program to Count set bits in an integer
In this article, we will learn how to count set bits (1's) in the binary representation of an integer. A set bit refers to a bit position that contains the value 1. Problem statement − We are given an integer n, we need to count the number of 1's in the binary representation of the number. For example, the number 15 in binary is 1111, which has 4 set bits. Method 1: Using Iterative Approach This approach uses bitwise AND operation to check each bit ? def count_set_bits(n): count = ...
Read MorePython Program to Count number of binary strings without consecutive 1'
In this article, we will learn about counting binary strings of length N that don't contain consecutive 1's. This is a classic dynamic programming problem that follows the Fibonacci pattern. Problem statement − We are given a positive integer N, and we need to count all possible distinct binary strings of length N such that no two consecutive 1's exist in the string. Approach We can solve this using dynamic programming by considering two cases ? a[i] = number of valid strings of length i ending with 0 b[i] = number of valid strings of ...
Read MorePython Program to Count Inversions in an array
In this article, we will learn about counting inversions in an array. An inversion occurs when a larger element appears before a smaller element in an array. Problem statement − We are given an array, we need to count the total number of inversions and display it. Inversion count represents how far an array is from being sorted. For example, in array [2, 3, 8, 6, 1], the pairs (2, 1), (3, 1), (8, 6), (8, 1), and (6, 1) are inversions. What is an Inversion? An inversion is a pair of indices (i, j) where ...
Read MoreFind Circles in an Image using OpenCV in Python
The OpenCV platform provides a cv2 library for Python. This can be used for various shape analyses which is useful in Computer Vision. To identify the shape of a circle using OpenCV we can use the cv2.HoughCircles() function. It finds circles in a grayscale image using the Hough transform. Common Approaches Some of the common methods to find circles in an image using OpenCV are as follows − Circle detection using Hough transform OpenCV ...
Read More