C Articles - Page 47 of 134

Maximum number of chocolates to be distributed equally among k students in C

Sunidhi Bansal
Updated on 14-Aug-2020 08:00:34

1K+ Views

We are given a number of chocolates present in consecutive boxes in the form of an array and a number k which represents the number of students among which these chocolates will be distributed. The task here is to choose consecutive boxes such that the sum of chocolates present in them can be equally distributed among k students. Also we have to make sure that the number of chocolates is maximum.For this we will traverse the array from left to right and start adding the number of chocolates and divide the sum by k. If it is fully divided with ... Read More

Maximum money that can be withdrawn in two steps in C

Sunidhi Bansal
Updated on 14-Aug-2020 07:58:45

250 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
Updated on 14-Aug-2020 07:56:45

588 Views

We are given with 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 size) ... Read More

Maximum difference between first and last indexes of an element in array in C

Sunidhi Bansal
Updated on 14-Aug-2020 07:54:28

579 Views

We are given with an array of integers of size N. The array consists of integers in random order. The task is to find the maximum difference between the first and last indexes of an element in the array. We have to find a number which appears twice in the array and the difference between its indexes is maximum. If there are more such pairs then we will store the maximum such difference between the indexes.Input Arr[] = { 2, 1, 3, 1, 3, 2, 5, 5 }.Output −Maximum difference between first and last indexes of an element in array − ... Read More

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

Sunidhi Bansal
Updated on 14-Aug-2020 07:52:29

2K+ Views

We are given with an array of integers of size N. The array consists of integers in random order. 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 between two elements such that the larger element appears after the smaller number − 20Explanation − The maximum difference is between 21 and 1 and 21 appears after 1 in the array.Input Arr[] = {18, 2, 8, 1, 2, 3, 2, ... Read More

Maximum difference between two subsets of m elements in C

Sunidhi Bansal
Updated on 14-Aug-2020 07:13:21

869 Views

The task is to find the greatest difference between the sum of m elements in an array. Suppose we have an array and a number m, then we will first find the sum of highest m numbers and then subtract the sum of lowest m numbers from it to get the maximum difference. So the main thing is to find two subsets of m numbers which have the highest sum and lowest sum.Let’s now understand what we have to do using an example −Input arr = {1, 2, 3, 4, 5} ; m=3Output Maximum difference here is : 6Explanation − Here the ... Read More

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

Sunidhi Bansal
Updated on 14-Aug-2020 07:11:14

317 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 xMD. If it is so, update MD. Else check is RSum[row]

Program for sum of geometric series in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:35:00

6K+ Views

Given three inputs first one is “a” which is for the first term of geometric series second is “r” which is the common ratio and “n” which are the number of series whose sum we have to find.Geometric series is a series which have a constant ratio between its successive terms. Using the above stated inputs “a”, “r” and “n” we have to find the geometric series i.e., a, ar, 𝑎𝑟2 , 𝑎𝑟3 , 𝑎𝑟4 , … and their sum, i.e., a + ar + 𝑎𝑟2+ 𝑎𝑟3 + 𝑎𝑟4 +…Inputa = 1 r = 0.5 n = 5Output1.937500Inputa = 2 ... Read More

Program for triangular patterns of alphabets in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:32:35

332 Views

Given a number n, the task is to print the triangular patterns of alphabets of the length n. First print the n characters then decrement one from the beginning in each line.The triangular pattern of alphabet will be like in the given figure below −Input − n = 5Output Input − n = 3Output Approach used below is as follows to solve the problemTake input n and loop i from 1 to n.For every i iterate j from i to n for every j print a character subtract 1 and add the value of j to ‘A’ .AlgorithmStart In function int pattern( ... Read More

Profit and loss Problems using C

Sunidhi Bansal
Updated on 13-Aug-2020 08:29:46

3K+ Views

Given a certain cost price(cp) and a selling price(sp) of an unknown product or a service, our task is to find the profit earned or loss suffered using a C program where if the profit is earned should print “Profit” and it’s amount or if the loss is suffered “Loss” and its respective amount or if there is not profit no loss then print “No profit nor Loss”.To find the profit or the loss we generally see whether the selling price(sp) or the price/amount at which a certain thing is sold or the cost price(cp) at which a certain thing ... Read More

Advertisements