sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 17 of 98

C/C++ Program for the n-th Fibonacci number?

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

The Fibonacci sequence is a series where the next term is the sum of the previous two terms. The first two terms of the Fibonacci sequence are 0 followed by 1. In this problem, we will find the nth number in the Fibonacci series. For this we will calculate all the numbers and print the n terms. Syntax // Basic approach using loop for (i = 1; i

Read More

10's Complement of a decimal number?

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

The 10's complement of a decimal number is a mathematical operation used in digital systems to simplify arithmetic operations, particularly subtraction. It is calculated by subtracting the given number from 10n, where n is the total number of digits in the number. The 10's complement can be found in two ways − Method 1: Calculate 9's complement first, then add 1 Method 2: Direct calculation using formula: 10n - number Syntax int tensComplement = pow(10, digitCount) - number; Method 1: Using 9's Complement First find the 9's complement by subtracting ...

Read More

Average of Squares of n Natural Numbers?

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

Given a number n, we need to find the average of the squares of the first n natural numbers. We calculate the square of each number from 1 to n, sum all these squares, and divide by n to get the average. Syntax average = (1² + 2² + 3² + ... + n²) / n Example Let's calculate the average of squares for the first 3 natural numbers − #include int main() { int n = 3; int sum = 0; /* Calculate sum of squares */ for(int i = 1; i

Read More

Add 1 to the number represented as array (Recursive Approach)?

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

Given an array which is a collection of non-negative numbers represented as an array of digits, add 1 to the number (increment the number represented by the digits). The digits are stored such that the most significant digit is the first element of the array. To add 1 to the number represented by digits − Start from the rightmost digit (last element of the array) If the last digit is less than 9, simply add 1 to it If the last digit is 9, make it 0 and carry 1 to the next position Continue this process ...

Read More

A square matrix as sum of symmetric and skew-symmetric matrix ?

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

A square matrix can be expressed as the sum of a symmetric matrix and a skew-symmetric matrix. This decomposition is unique and provides insight into the structure of any square matrix. Symmetric Matrix − A matrix whose transpose is equal to the matrix itself (A = AT). Skew-symmetric Matrix − A matrix whose transpose is equal to the negative of the matrix (A = -AT). Syntax A = (1/2)(A + A^T) + (1/2)(A - A^T) Where: (1/2)(A + A^T) is the symmetric part (1/2)(A - A^T) is the skew-symmetric part ...

Read More

Sum of square of first n odd numbers

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

The sum of squares of first n odd numbers is a mathematical series where we calculate the squares of the first n odd numbers and add them together. The first n odd numbers are: 1, 3, 5, 7, 9, 11, ... and their squares form the series: 12, 32, 52, 72, 92, 112, ... which equals 1, 9, 25, 49, 81, 121, ... Syntax sum = n(2n+1)(2n-1)/3 = n(4n² - 1)/3 Where n is the count of odd numbers to consider. Method 1: Using Loop Iteration This approach calculates each odd number, squares it, and adds to the sum − #include int main() { int n = 4; int sum = 0; for (int i = 1; i

Read More

Sum of all subsets of a set formed by first n natural numbers

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

A set is a collection of data elements. A subset of a set is a set formed by selecting some or all elements from the parent set. For example, B is a subset of A if all elements of B exist in A. Here we need to find the sum of all subsets of a set formed by first n natural numbers. This means we need to find all possible subsets and then add up all their elements. Understanding the Problem Let's take an example with N = 3: Set = {1, 2, 3} All ...

Read More

Sum of series with alternate signed squares of AP

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

An arithmetic progression (AP) is a series of numbers in which the difference between two consecutive terms is the same. The difference is calculated by subtracting the first term from the second. Let's take a sample sequence to understand AP − 5, 7, 9, 11, 13, 15, . . . The common difference (d) of this arithmetic progression is 2. This means every succeeding element differs from the former one by 2. The first term (a) of this series is 5. The general formula for finding the nth term is an = a + (n-1) × d ...

Read More

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

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 551 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 302 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
Showing 161–170 of 975 articles
« Prev 1 15 16 17 18 19 98 Next »
Advertisements