C Articles

Page 33 of 96

Maximum money that can be withdrawn in two steps in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 314 Views

We are given two lockers, say L1 and L2 that have some amount of money in the form of coins. L1 has A coins and L2 has B number of coins in it. We have to withdraw money or coins from the lockers such that the money drawn out is maximum. Each time the coins are drawn from any locker, it is replaced by coins 1 less than its previous count. If we draw A coins from L1 then it will be replaced by A-1 coins and if we draw B coins from L2 then it will be replaced by ...

Read More

Maximum difference between the group of k-elements and rest of the array in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 663 Views

We are given an array of integers of size N and a number k. The array consists of integers in random order. The task is to find the maximum difference between the group of k-elements and rest of the array. The array will be divided into two parts. The first part is a group of k-elements taken out and the second part is the rest of the elements of the array. We have to select k elements such that the difference between the sum of elements in both groups is maximum. If k is smaller ( half of array ...

Read More

Maximum difference between two elements such that larger element appears after the smaller number in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 2K+ Views

We are given an array of integers of size N. The task is to find the maximum difference between two elements such that the larger element appears after the smaller number. That is, Arr[j] − Arr[i] is maximum such that j > i. Input: Arr[] = {2, 1, 3, 8, 3, 19, 21} Output: The maximum difference is 20 Explanation: The maximum difference is between 21 and 1, and 21 appears after 1 in the array. Syntax int maxDifference(int arr[], int n); Approach The optimal approach uses a single ...

Read More

Maximum difference between two subsets of m elements in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 940 Views

The task is to find the maximum difference between the sum of two subsets, each containing m elements from an array. We need to find the subset with the highest sum and the subset with the lowest sum, then calculate their difference. Syntax int find_diff(int arr[], int length, int m); Algorithm The approach to solve this problem is − Sort the array in ascending order Sum the first m elements (lowest subset) Sum the last m elements (highest subset) Return the difference between highest and lowest sums Example 1: Basic ...

Read More

Maximum difference of sum of elements in two rows in a matrix in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 377 Views

We are given a matrix and the task is to find the greatest difference between the sum of elements in two rows of a matrix. Suppose we have a matrix M[i,j] with i rows and j columns. Let the rows be R0 to Ri-1. The difference will be calculated by subtracting the (sum of elements of Ry) - (sum of elements of Rx), where x

Read More

Program for sum of geometric series in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 6K+ Views

In C programming, calculating the sum of a geometric series involves finding the total of terms where each term is obtained by multiplying the previous term by a constant ratio. A geometric series follows the pattern: a, ar, ar2, ar3, ..., where 'a' is the first term, 'r' is the common ratio, and 'n' is the number of terms. Syntax float sumGeometric(float a, float r, int n); Parameters a − First term of the geometric series r − Common ratio between successive terms n − Number of terms in the series ...

Read More

Program for triangular patterns of alphabets in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 399 Views

In C programming, triangular patterns of alphabets are commonly used to demonstrate nested loops and character manipulation. This pattern starts with a full line of consecutive alphabets and removes one character from the beginning in each subsequent line. Syntax for (i = 1; i

Read More

Profit and loss Problems using C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 3K+ Views

In C programming, profit and loss problems involve calculating the financial gain or loss from a transaction based on the cost price and selling price. Given a cost price (cp) and selling price (sp), we need to determine whether a profit was earned, a loss was suffered, or there was no profit nor loss. Syntax // Basic profit and loss calculation if (selling_price > cost_price) { profit = selling_price - cost_price; } else if (cost_price > selling_price) { loss = cost_price - selling_price; } else { ...

Read More

Product of given N fractions in reduced form in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 288 Views

Given the numerator and denominator of N fractions, the task is to find the product of all N fractions and output the result in reduced form. The product of fractions is calculated by multiplying all numerators together and all denominators together, then reducing the resulting fraction to its simplest form. For example, if we have fractions 4/5 and 3/4, their product would be (4×3)/(5×4) = 12/20, which reduces to 3/5. Fraction Multiplication: 4/5 × 3/4 = (4×3)/(5×4) = 12/20 = 3/5 4 5 ...

Read More

Program to Add Two Complex Numbers in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 10K+ Views

Given are two complex numbers in the form of a1 + ib1 and a2 + ib2, the task is to add these two complex numbers in C programming. Complex numbers are those numbers which can be expressed in the form of "a + ib" where "a" and "b" are real numbers and "i" is the imaginary unit which satisfies i² = −1. Since no real number satisfies this equation, it is called the imaginary unit. Syntax struct complex { int real; int imaginary; }; struct complex addComplex(struct ...

Read More
Showing 321–330 of 953 articles
« Prev 1 31 32 33 34 35 96 Next »
Advertisements