Found 1401 Articles for C

Addition of two numbers without propagating Carry?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

393 Views

Here we will see one problem, where we will add two n digit numbers but the carry will not be propagated. We can understand this concept through an example −So we can see that here only digits are getting added and answer is placed. Here is one trick. We have to scan the numbers from right to left. So the sum of 3+2 = 6 will be calculated first, but it will be placed at the end. So we will use stack to store intermediate results.AlgorithmnoPropagateCarry(a, b)begin    size = max of length of a and length of b   ... Read More

C/C++ Program to Find reminder of array multiplication divided by n ?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

183 Views

Here we will see how to calculate the remainder of array multiplication after dividing the result by n. The array and the value of n are supplied by the user. Suppose the array is like {12, 35, 69, 74, 165, 54} so the multiplication will be (12 * 35 * 69 * 74 * 165 * 54) = 19107673200. Now if we want to get the remainder after diving this by 47 it will be 14.As we can see this problem is very simple. we can easily multiply the elements then by using modulus operator, it can get the result. ... Read More

C/C++ Program to find Product of unique prime factors of a number?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

470 Views

In this section we will see how we can get the product of unique prime factor of a number in an efficient way. There is a number say n = 1092, we have to get product of unique prime factors of this. The prime factors of 1092 are 2, 2, 3, 7, 13. So the unique prime factors are {2, 3, 7, 13}, the product is 546. To solve this problem, we have to follow this rule −When the number is divisible by 2, then multiply 2 with product, and divide the number by 2 repeatedly, then next 2s will ... Read More

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

Arnab Chakraborty
Updated on 01-Jul-2020 14:31:25

376 Views

Here we will see how the brick sort works. The Brick sort is one modification of bubble sort. This algorithm is divided into two parts. These parts are odd part and even parts. In the odd part we will use the bubble sort on odd indexed items, and in the even part we will use the bubble sort on even indexed elements. Let us see the algorithm to get the idea.AlgorithmbrickSort(arr, n)begin    flag := false    while the flag is not true, do       flag := true       for i := 1 to n-2, increase ... Read More

C/C++ Program for Finding the vertex, focus and directrix of a parabola?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

108 Views

Here we will see how to find the vertex, focus directrix of a parabola using C or C++ program. To get these parameters we need the general equation of a parabola. The general formula is −𝑦 = 𝑎𝑥2 + 𝑏𝑥 + 𝑐The values of a, b and c are given.The formula for the vertex −The formula for the focus −The formula for the Directrix - y −Example Live Demo#include using namespace std; void getParabolaDetails(float a, float b, float c) {    cout

Absolute distinct count in a sorted array?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

96 Views

In this section we will see how to count how many of elements whose absolute values are distinct? Suppose in an array there are few elements like {5, 5, 6, -5, 8, 2, -2, 1}, so there are 8 elements. But there are 5 elements {5, 6, 8, 2, 1} which are distinct. The -5 and 5 are not considered as different, they are same as their absolute value is same.To solve this problem, we will use the Set data-structure. In set duplicate elements are not allowed. And when we are inserting item into the set, we will push only ... Read More

Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

128 Views

Here we will see how we can find the absolute difference between the sum of all prime numbers and all non-prime numbers of an array. To solve this problem, we have to check whether a number is prime or not. One possible way for primality testing is by checking a number is not divisible by any number between 2 to square root of that number. So this process will take 𝑂(√𝑛) amount of time. Then get the sum and try to find the absolute difference.AlgorithmdiffPrimeNonPrimeSum(arr)begin    sum_p := sum of all prime numbers in arr    sum_np := sum of ... Read More

Absolute Difference between the Product of Non-Prime numbers and Prime numbers of an Array?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

118 Views

Here we will see how we can find the absolute difference between the product of all prime numbers and all non-prime numbers of an array. To solve this problem, we have to check whether a number is prime or not. One possible way for primality testing is by checking a number is not divisible by any number between 2 to square root of that number. So this process will take 𝑂(√𝑛) amount of time. Then get the product and try to find the absolute difference.AlgorithmdiffPrimeNonPrimeProd(arr)begin    prod_p := product of all prime numbers in arr    prod_np := product of ... Read More

Absolute difference between the first X and last X Digits of N?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

345 Views

Here we will see how to get the differences between first and last X digits of a number N. The number and X are given. To solve this problem, we have to find the length of the number, then cut the last x digits using modulus operator. After that cut all digits from the number except first x digits. Then get the difference, and return the result. Let the number is N = 568424. The X is 2 so first two digits are 56, and last two digits are 24. The difference is (56 - 24) = 32.AlgorithmdiffFirstLastDigits(N, X)begin   ... Read More

Absolute difference between sum and product of roots of a quartic equation?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

171 Views

In this section we will see how to get the absolute difference between the sum of the roots and the products of the root of a quartic equation?The quartic equation is like 𝑎𝑥4+𝑏𝑥3+𝑐𝑥2+𝑑𝑥+𝑒We can solve the equation and then try to get the product and sum of the roots by some normal process, but that takes much time and that approach is not so efficient. In this kind of equation, we have two formulae. The Sum of roots are always −𝑏∕𝑎 and the product of roots are always 𝑒∕𝑎 . So we have to find only the value of ∣−𝑏∕𝑎− ... Read More

Advertisements