C++ Articles

Page 8 of 597

Amazing stuff with system() in C / C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 941 Views

The system() function in C allows you to execute operating system commands directly from your C program. This function is available on Windows, Linux, and macOS, making it a powerful tool for interacting with the system shell and running command-line programs. Syntax #include int system(const char *command); Note: The examples below use system-specific commands that cannot be executed in an online compiler. They are provided for educational purposes to demonstrate system() function usage. Example 1: Getting Network Configuration This example shows how to retrieve IP configuration details on a Windows ...

Read More

A Puzzle on C/C++ R-Value Expressions?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 230 Views

Here we will see one puzzle about R-value expressions in C. Suppose there is a program which is given below, we have to tell what will be the output and why? Syntax ~expression; // R-value: computes but doesn't store variable = ~expression; // L-value: stores the result Example 1: R-value Expression In this example, the complement operation is performed but not assigned to any variable − #include int main() { int x = 0xab; ~x; /* ...

Read More

Argument Coercion in C/C++?

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

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 More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 338 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 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 More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 768 Views

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 More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 266 Views

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 More

C/C++ Program for Largest Sum Contiguous Subarray?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 539 Views

An array of integers is given. We have to find the sum of all contiguous elements whose sum is largest. This problem is known as the Maximum Subarray Problem and is efficiently solved using Kadane's Algorithm. Using dynamic programming, we store the maximum sum up to the current element. This helps find the optimal contiguous subarray with maximum sum. Syntax int maxSubarraySum(int arr[], int n); Algorithm: Kadane's Algorithm The algorithm maintains two variables − Input: An array of integers. {-2, -3, 4, -1, -2, 1, 5, -3} Output: Maximum Sum of ...

Read More

C/C++ program to shutdown a system?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 901 Views

Here we will see how we can shut down the system by writing a simple C program. The shutdown process varies in different operating systems. If we are Linux user, we can use this terminal command to shut down − shutdown -P now If we are using Windows system, we can use this command − c:\windows\system32\shutdown /i Note: These programs require administrator/root privileges to execute successfully. On Linux, you may need to run with sudo. On Windows, run the program as administrator. Syntax int system(const char *command); ...

Read More

C/C++ Program to Count set bits in an integer?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 1K+ Views

Here we will see how we can count the number of set bits in an integer. Set bits are the bits that have a value of 1 in the binary representation of a number. For example, the number 13 has binary representation 1101, which contains three set bits, so the count will be 3. To solve this problem, we will shift the number to the right and check if the least significant bit (LSB) is 1. If it is, we increment our count. This process continues until the number becomes 0. Syntax int countSetBits(int n); ...

Read More

C/C++ Program to Count Inversions in an array using Merge Sort?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 1K+ Views

The inversion count in an array indicates how many changes are required to convert the array into its sorted form. When an array is already sorted, it needs 0 inversions. When the array is sorted in reverse order, the number of inversions is maximum. We can efficiently solve this problem using a modified merge sort algorithm to achieve O(n log n) time complexity. Syntax int merge(int arr[], int temp[], int left, int mid, int right); int mergeSort(int arr[], int temp[], int left, int right); int countInversions(int arr[], int n); Algorithm The approach uses a ...

Read More
Showing 71–80 of 5,962 articles
« Prev 1 6 7 8 9 10 597 Next »
Advertisements