Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 970 of 2109
Arrange given numbers to form the biggest number?
Here we will see how to generate the biggest number by rearranging the given numbers. Suppose there are {45, 74, 23} given, the program will find the largest number, that is 744523. Each digit will not be rearranged individually, but the whole numbers will be placed optimally to form the largest possible number. To solve this problem, we use custom string comparison logic. The comparing function takes two numbers a and b, then concatenates them to form "ab" and "ba". Whichever concatenation gives the larger value determines the sorting order. Syntax int compare(const void *a, const ...
Read MoreArgument Coercion in C/C++?
Argument coercion in C is a technique where the compiler automatically converts function arguments from one data type to another during function calls. This follows the argument promotion rule − lower data types can be implicitly converted to higher data types, but not vice versa. The reason is that converting higher data types to lower ones may result in data loss. Syntax return_type function_name(parameter_type param); // Arguments are automatically coerced to match parameter types Type Promotion Hierarchy The following SVG shows the implicit conversion hierarchy in C − ...
Read MoreArea of triangle formed by the axes of co-ordinates and a given straight line?
In coordinate geometry, we can find the area of a triangle formed by the x-axis, y-axis, and a given straight line. When a straight line intersects both coordinate axes, it creates a triangle with the origin as one vertex. Syntax double calculateTriangleArea(double a, double b, double c); Mathematical Formula For a straight line with equation ax + by + c = 0, the intercept form is − x/(-c/a) + y/(-c/b) = 1 The x-intercept is -c/a and y-intercept is -c/b. The area of the triangle formed ...
Read MoreWhat's the difference between sizeof and alignof?
In C, understanding the difference between sizeof and _Alignof operators is crucial for memory layout optimization. The sizeof operator returns the total size of a type in bytes, while _Alignof (introduced in C11) returns the alignment requirement of a type. Syntax sizeof(type) _Alignof(type) Key Differences The sizeof operator returns the total memory space occupied by a type, including any padding bytes added for alignment. The _Alignof operator returns the alignment boundary requirement − the address where the type should be placed for optimal access. Example: Basic Data Types For primitive data types, ...
Read MoreAddition of two numbers without propagating Carry?
Addition of two numbers without propagating carry is a digit-wise addition where each position is added independently without carrying over to the next position. For example, adding 7583 and 9642 gives 1611125 (7+9=16, 5+6=11, 8+4=12, 3+2=5). Addition Without Carry Propagation 7 5 8 3 + 9 6 4 2 ...
Read MoreC/C++ Program to Find reminder of array multiplication divided by n ?
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 dividing 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 ...
Read MoreC/C++ Program to find Product of unique prime factors of a number?
In this section we will see how we can get the product of unique prime factors 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}, and the product is 546. Syntax int uniquePrimeProduct(int n); Algorithm To solve this problem, we have to follow this approach − Handle factor 2: When the number is divisible ...
Read MoreC/C++ Program for Finding the vertex, focus and directrix of a parabola?
A parabola is a U-shaped curve that can be described by a quadratic equation. In C programming, we can find key properties of a parabola including its vertex, focus, and directrix using mathematical formulas. The general equation of a parabola is − Syntax y = ax² + bx + c Where a, b, and c are coefficients and a ≠ 0. ...
Read MoreAbsolute distinct count in a sorted array?
In this article, we will learn how to count the number of elements whose absolute values are distinct in an array. For example, in the array {5, 5, 6, -5, 8, 2, -2, 1}, there are 8 elements total, but only 5 distinct absolute values: {5, 6, 8, 2, 1}. Note that -5 and 5 are considered the same since their absolute values are identical. Syntax int absoluteDistinctCount(int arr[], int n); Algorithm To solve this problem, we use a simple approach − 1. Create a boolean array to mark visited absolute values ...
Read MoreAbsolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array?
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 if a number is not divisible by any number between 2 to square root of that number. This process will take O(√n) amount of time for each number. Syntax int diffPrimeNonPrimeSum(int arr[], int n); Algorithm begin sum_p := sum of ...
Read More