C Articles

Page 59 of 96

C program to Find the Largest Number Among Three Numbers

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

This program takes three numbers and finds the largest among them. We will use conditional statements to compare the numbers and determine which one has the maximum value. Syntax if (condition1) { if (condition2) { // statements } else { // statements } } else { if (condition3) { // statements } else ...

Read More

C Program for the compound interest?

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

Compound interest is the interest calculated on both the principal amount and the previously earned interest. Unlike simple interest, compound interest grows exponentially because the interest earned in each period is added to the principal for the next calculation period. Syntax Compound Interest = Principal * pow((1 + Rate/100), Time) - Principal Amount = Principal * pow((1 + Rate/100), Time) Example: Calculate Compound Interest Here's a complete C program to calculate compound interest using the mathematical formula − #include #include int main() { float principal, ...

Read More

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 375 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 642 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 303 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 395 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
Showing 581–590 of 953 articles
« Prev 1 57 58 59 60 61 96 Next »
Advertisements