C++ Articles

Page 7 of 597

C/C++ Program for the n-th Fibonacci number?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 1K+ Views

The Fibonacci sequence is a series where the next term is the sum of the previous two terms. The first two terms of the Fibonacci sequence are 0 followed by 1. In this problem, we will find the nth number in the Fibonacci series. For this we will calculate all the numbers and print the n terms. Syntax // Basic approach using loop for (i = 1; i

Read More

C/C++ Program to Count number of binary strings without consecutive 1’s?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 467 Views

In this article, we will learn how to count all distinct binary strings of length n such that no two 1's appear consecutively. We'll explore this problem using both recursive and dynamic programming approaches in C. What is a Binary String? A binary string is a sequence of characters that contains only '0' and '1'. It represents information in base-2 format. For example, "0101" is a binary string of length 4. We are given a positive integer n, and our task is to count all possible distinct binary strings of length n that do not contain consecutive ...

Read More

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

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 579 Views

The odd-even sort, also known as brick sort, is a comparison-based sorting algorithm that divides the sorting process into two alternating phases: odd phase and even phase. This technique is similar to bubble sort but operates on different index pairs in each phase, making it suitable for parallel processing. The odd phase compares and swaps elements at odd indices (1, 3, 5...) with their adjacent elements, while the even phase works on even indices (0, 2, 4...) with their adjacent elements. Syntax void oddEvenSort(int arr[], int n); How It Works The algorithm alternates ...

Read More

C/C++ Program for Number of solutions to Modular Equations?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 193 Views

We have a given number of coins and we need to arrange them to form a pyramid of maximum height. The coins are arranged such that the first row contains 1 coin, the second row contains 2 coins, the third row contains 3 coins, and so on. 1 2 3 4 5 ...

Read More

C/C++ Program for nth Catalan Number?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 681 Views

Catalan numbers are a sequence of natural numbers that occur in various counting problems, often involving recursively-defined objects. The nth Catalan number can be calculated using the recursive formula or dynamic programming approaches. Syntax C(n) = (2n)! / ((n+1)! * n!) C(n) = C(0)*C(n-1) + C(1)*C(n-2) + ... + C(n-1)*C(0) Mathematical Properties Catalan numbers have several interpretations − Cn is the number of Dyck words of length 2n (strings with n X's and n Y's where no prefix has more Y's than X's) Cn counts valid parentheses combinations with n pairs Cn ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 932 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 226 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 321 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 737 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
Showing 61–70 of 5,962 articles
« Prev 1 5 6 7 8 9 597 Next »
Advertisements