Server Side Programming Articles

Page 958 of 2109

Sum of series 2/3 – 4/5 + 6/7 – 8/9 + ...... upto n terms

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 560 Views

In C programming, we can calculate the sum of the series 2/3 − 4/5 + 6/7 − 8/9 + ...... up to n terms. This is an alternating series where each term has the form (-1)n+1 * (2*n) / (2*n + 1). Syntax double calculateSeriesSum(int n); Understanding the Series Pattern The series follows this pattern − First term: 2/3 (positive) Second term: -4/5 (negative) Third term: 6/7 (positive) Fourth term: -8/9 (negative) For the nth term: (-1)n+1 * (2*n) / (2*n + 1) Example: Calculate Series Sum Here's a complete C program to calculate the sum of this series − #include double calculateSeriesSum(int n) { double sum = 0.0; int sign = 1; for (int i = 1; i

Read More

Sum of series 1^2 + 3^2 + 5^2 + . . . + (2*n – 1)^2

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 312 Views

A series is a sequence of numbers that follow a specific mathematical pattern. The series 1² + 3² + 5² + ... + (2*n-1)² represents the sum of squares of the first n odd numbers. This series has a special property − it follows the formula: Sum = n²(2n² - 1)/3. However, we can also calculate it using loops by adding each term individually. Syntax Sum = n²(2n² - 1)/3 // Or using loop: sum += (2*i - 1) * (2*i - 1) Method 1: Using Loop This approach calculates the sum by iterating through each odd number and adding its square − #include int main() { int i, n, sum = 0; n = 7; for (i = 1; i

Read More

C Program for Selection Sort?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 105K+ Views

The selection sort is a simple sorting algorithm that works by finding the smallest element from the unsorted portion of the array and placing it at the beginning. This process is repeated until the entire array is sorted. Syntax void selectionSort(int arr[], int n) { for (int i = 0; i < n-1; i++) { int minIndex = i; for (int j = i+1; j < n; j++) { ...

Read More

C/C++ Program to Count number of binary strings without consecutive 1’s?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 495 Views

In this article, we will learn how to count all distinct binary strings of length n such that no two 1's appear consecutively. We'll explore this problem using both recursive and dynamic programming approaches in C. What is a Binary String? A binary string is a sequence of characters that contains only '0' and '1'. It represents information in base-2 format. For example, "0101" is a binary string of length 4. We are given a positive integer n, and our task is to count all possible distinct binary strings of length n that do not contain consecutive ...

Read More

C/C++ Program for the Odd-Even Sort (Brick Sort)?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 601 Views

The odd-even sort, also known as brick sort, is a comparison-based sorting algorithm that divides the sorting process into two alternating phases: odd phase and even phase. This technique is similar to bubble sort but operates on different index pairs in each phase, making it suitable for parallel processing. The odd phase compares and swaps elements at odd indices (1, 3, 5...) with their adjacent elements, while the even phase works on even indices (0, 2, 4...) with their adjacent elements. Syntax void oddEvenSort(int arr[], int n); How It Works The algorithm alternates ...

Read More

C/C++ Program for Number of solutions to Modular Equations?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 211 Views

We have a given number of coins and we need to arrange them to form a pyramid of maximum height. The coins are arranged such that the first row contains 1 coin, the second row contains 2 coins, the third row contains 3 coins, and so on. 1 2 3 4 5 ...

Read More

Add minimum number to an array so that the sum becomes even in C programming

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 291 Views

Given an array, we need to add the minimum positive number to make the sum of all array elements even. The key insight is that we only need to analyze the parity (odd/even nature) of numbers to determine the minimum addition required. Syntax int findMinimumToAdd(int arr[], int n); Method 1: Calculate Total Sum Calculate the sum of all elements in the array, then check if the sum is even. If the sum is already even, add 2 (minimum positive even number). If the sum is odd, add 1 to make it even − ...

Read More

Arithmetic Mean in C programming

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 3K+ Views

Arithmetic mean is the sum of a collection of numbers divided by the number of numbers in the collection. It is one of the most commonly used measures of central tendency in statistics and mathematics. Syntax mean = (sum of all numbers) / (count of numbers) Basic Properties of Arithmetic Mean If each observation is increased by p, the mean increases by p. If each observation is decreased by p, the mean decreases by p. If each observation is multiplied by p, the mean is multiplied by p. If each observation is divided ...

Read More

C/C++ Program for nth Catalan Number?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 685 Views

Catalan numbers are a sequence of natural numbers that occur in various counting problems, often involving recursively-defined objects. The nth Catalan number can be calculated using the recursive formula or dynamic programming approaches. Syntax C(n) = (2n)! / ((n+1)! * n!) C(n) = C(0)*C(n-1) + C(1)*C(n-2) + ... + C(n-1)*C(0) Mathematical Properties Catalan numbers have several interpretations − Cn is the number of Dyck words of length 2n (strings with n X's and n Y's where no prefix has more Y's than X's) Cn counts valid parentheses combinations with n pairs Cn ...

Read More

C Program to Multiply two Floating Point Numbers?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 868 Views

In C, multiplying two floating-point numbers is a fundamental arithmetic operation. Floating-point numbers can represent real numbers with decimal points, such as 4320.0, -3.33, or 0.01226. The term "floating point" refers to the fact that the decimal point can "float" to support a variable number of digits before and after it. Syntax float result = float_num1 * float_num2; double result = double_num1 * double_num2; Floating Point Data Types Type Size Range Precision float 4 bytes ±1.18 x 10-38 to ±3.4 x 1038 6-7 digits double ...

Read More
Showing 9571–9580 of 21,090 articles
« Prev 1 956 957 958 959 960 2109 Next »
Advertisements