Server Side Programming Articles

Page 591 of 2109

Python Program for Fibonacci numbers

Pavitra
Pavitra
Updated on 25-Mar-2026 779 Views

The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. In this article, we will learn different approaches to compute the nth Fibonacci number in Python. Problem statement − Our task is to compute the nth Fibonacci number. The sequence Fn of Fibonacci numbers is given by the recurrence relation: Fn = Fn-1 + Fn-2 with seed values: F0 = 0 and F1 = 1 We have two main approaches to solve this problem: Recursive approach Dynamic programming approach Using Recursive ...

Read More

Python Program for Difference between sums of odd and even digits

Pavitra
Pavitra
Updated on 25-Mar-2026 690 Views

In this article, we will learn how to find the difference between the sum of odd digits and sum of even digits in a number, and check if this difference equals zero. Problem Statement − Given an integer, we need to calculate if the difference between the sum of odd digits and sum of even digits is 0 or not. Method 1: Brute Force Approach The straightforward approach calculates the sum of all even and odd digits separately, then finds their difference ? def difference_odd_even_digits(n): n = abs(n) # Handle ...

Read More

Python Program for cube sum of first n natural numbers

Pavitra
Pavitra
Updated on 25-Mar-2026 3K+ Views

In this article, we will learn how to calculate the cube sum of first n natural numbers using two different approaches. The cube sum series is: 1³ + 2³ + 3³ + 4³ + ... + n³. Problem statement − Given an input n, we need to print the sum of series 1³ + 2³ + 3³ + 4³ + ... + n³ till n-th term. Here we will discuss two approaches to solve this problem ? Brute-force approach using loops Mathematical solution using the sum formula Using Loop (Iterative Approach) This approach ...

Read More

Python Program for compound interest

Pavitra
Pavitra
Updated on 25-Mar-2026 640 Views

In this article, we will learn how to calculate compound interest using Python. Compound interest is the interest calculated on both the initial principal and the accumulated interest from previous periods. Problem statement − We are given three input values: principal amount, interest rate, and time period. We need to compute the compound interest. Formula The formula for calculating compound interest is: Compound Interest = P × (1 + R/100)^T Where: P is the principal amount (initial investment) R is the annual interest rate (in percentage) T is the time period (in ...

Read More

Python Program to Print Matrix in Z form

Pavitra
Pavitra
Updated on 25-Mar-2026 455 Views

A Z-form traversal of a square matrix follows a specific pattern: traverse the first row, then the main diagonal (excluding elements already printed), and finally the last row. This creates a Z-like path through the matrix. Understanding Z-Form Pattern For a matrix of size n×n, Z-form traversal involves three steps − Print all elements of the first row Print diagonal elements from top-right to bottom-left (excluding corners) Print all elements of the last row ...

Read More

Python Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!

Pavitra
Pavitra
Updated on 25-Mar-2026 3K+ Views

In this article, we will learn how to calculate the sum of the mathematical series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!, where each term is the ratio of a number to its factorial. Problem statement − Given an integer input n, we need to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n! Understanding the Series This series has an interesting mathematical property − as n approaches infinity, the sum converges to the mathematical constant e (approximately 2.718). Each term follows the pattern i/i! where i ranges from ...

Read More

Python Program to find the area of a circle

Pavitra
Pavitra
Updated on 25-Mar-2026 836 Views

In this article, we will learn how to calculate the area of a circle using Python. Given the radius of a circle, we need to find its area using a simple mathematical formula. The area of a circle can be calculated using the following formula ? Area = π × r² Where π (pi) is approximately 3.14159 and r is the radius of the circle. Method 1: Using a Simple Function Let's implement a basic function to calculate the area ? def findArea(r): PI = 3.14159 ...

Read More

Python Program for simple interest

Pavitra
Pavitra
Updated on 25-Mar-2026 2K+ Views

In this article, we will learn how to calculate simple interest using Python. Simple interest is a method to calculate the interest charge on a loan or deposit. Simple interest is calculated by multiplying the principal amount by the interest rate and the time period. Unlike compound interest, it doesn't include interest on previously earned interest. Formula The mathematical formula for simple interest is: Simple Interest = (P × T × R) / 100 Where: P = Principal amount (initial money) T = Time period (in years) R = Rate of interest ...

Read More

Python Program for Selection Sort

Pavitra
Pavitra
Updated on 25-Mar-2026 2K+ Views

In this article, we will learn about the selection sort algorithm and its implementation in Python. Selection sort is a simple comparison-based sorting algorithm that works by finding the minimum element from the unsorted portion and placing it at the beginning. How Selection Sort Works The selection sort algorithm maintains two subarrays during execution: The subarray which is already sorted (initially empty) The subarray which is unsorted (initially the entire array) During each iteration, selection sort finds the minimum element from the unsorted subarray and swaps it with the first element of the unsorted ...

Read More

Python Program for Product of unique prime factors of a number

Pavitra
Pavitra
Updated on 25-Mar-2026 1K+ Views

In this article, we will learn how to find the product of all unique prime factors of a given number. For example, if the number is 12, its prime factors are 2 and 3, so the product would be 2 × 3 = 6. Problem statement − Given a number n, we need to find the product of all of its unique prime factors and return it. Example Input: num = 11 Output: Product is 11 Explanation: Here, the input number is 11 having only 1 prime factor and it is 11. And hence their product ...

Read More
Showing 5901–5910 of 21,090 articles
« Prev 1 589 590 591 592 593 2109 Next »
Advertisements