C Articles

Page 25 of 96

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 500 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 the Product of Non-Prime numbers and Prime numbers of an Array?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 251 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 Sum of Non-Prime numbers and Prime numbers of an Array?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 282 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 distinct count in a sorted array?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 239 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

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 217 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#include using namespace std; void getParabolaDetails(float a, float b, float c) {    cout

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 304 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

Addition of two numbers without propagating Carry?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 569 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

What's the difference between sizeof and alignof?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 791 Views

Here we will see what are the differences of sizeof and the alignof operator in C++. The alognof() operator is introduced in C++11.The alignof() operator is used to get the alignment in bytes. It requires instances of type. the type is either complete type or a reference type. There is another operator called the sizeof() operator, that returns the size of one type. For normal datatypes the sizeof and the alignof returns the same value. For some user defined datatype, the alignof returns some different value. Let us see the example to get the idea.Example#include using namespace std; struct MyStruct{ ...

Read More

Area of triangle formed by the axes of co-ordinates and a given straight line?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 172 Views

Here we will see how to get the area of a triangle formed by the x and y axis and another straight line. The diagram will be look like below. The equation of the straight line is −𝑎𝑥+𝑏𝑦+𝑐=0The line is cutting the x-axis at the point B, and cutting the y-axis at the point A. The intercept form will be like below −So the x-intercept is −𝑐∕𝑎 and y-intercept is −𝑐∕𝑏 . So the area of the triangle isExample#include #include using namespace std; double areaTriangle(double a, double b, double c){    return fabs((c*c) / (2*a*b)); } main() {    double ...

Read More

Argument Coercion in C/C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Here we will see about the argument coercion in C or C++. The Argument Coercion is one technique by which the compiler can implicitly convert the arguments from one type to another type. It follows argument promotion rule. If one argument is lower datatype, that can be converted into higher datatypes, but the reverse is not true. The reason is if one higher datatype is converted into a lower datatype, it may loss some data.Let us see one pyramid that can express how the implicit conversion takes place.Example#include using namespace std; double myAdd(double a, double b){    return a+b; } ...

Read More
Showing 241–250 of 953 articles
« Prev 1 23 24 25 26 27 96 Next »
Advertisements