sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 18 of 98

C Program for Selection Sort?

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

The selection sort is a simple sorting algorithm that works by finding the smallest element from the unsorted portion of the array and placing it at the beginning. This process is repeated until the entire array is sorted. Syntax void selectionSort(int arr[], int n) { for (int i = 0; i < n-1; i++) { int minIndex = i; for (int j = i+1; j < n; j++) { ...

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 194 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

Add minimum number to an array so that the sum becomes even in C programming

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

Given an array, we need to add the minimum positive number to make the sum of all array elements even. The key insight is that we only need to analyze the parity (odd/even nature) of numbers to determine the minimum addition required. Syntax int findMinimumToAdd(int arr[], int n); Method 1: Calculate Total Sum Calculate the sum of all elements in the array, then check if the sum is even. If the sum is already even, add 2 (minimum positive even number). If the sum is odd, add 1 to make it even − ...

Read More

Arithmetic Mean in C programming

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

Arithmetic mean is the sum of a collection of numbers divided by the number of numbers in the collection. It is one of the most commonly used measures of central tendency in statistics and mathematics. Syntax mean = (sum of all numbers) / (count of numbers) Basic Properties of Arithmetic Mean If each observation is increased by p, the mean increases by p. If each observation is decreased by p, the mean decreases by p. If each observation is multiplied by p, the mean is multiplied by p. If each observation is divided ...

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

C Program to Multiply two Floating Point Numbers?

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

In C, multiplying two floating-point numbers is a fundamental arithmetic operation. Floating-point numbers can represent real numbers with decimal points, such as 4320.0, -3.33, or 0.01226. The term "floating point" refers to the fact that the decimal point can "float" to support a variable number of digits before and after it. Syntax float result = float_num1 * float_num2; double result = double_num1 * double_num2; Floating Point Data Types Type Size Range Precision float 4 bytes ±1.18 x 10-38 to ±3.4 x 1038 6-7 digits double ...

Read More

C Program to Check if a Given String is a Palindrome?

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

A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward. Words such as "madam" or "racecar" or the number "10801" are palindromes. To check if a string is a palindrome, we need to compare characters from both ends moving toward the center. If the first character matches the last, second matches second-last, and so on, then the string is a palindrome. Syntax int isPalindrome(char str[]); // Returns 1 if palindrome, 0 otherwise Example 1: Using Character Comparison This approach compares characters from both ends ...

Read More

Write a program to Delete a Tree in C programming

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

To delete a tree in C programming, we need to traverse each node and free the memory allocated to them. The key is to delete nodes in the correct order − children must be deleted before their parents to avoid memory leaks and dangling pointers. Post-order traversal is ideal for this operation as it visits children before the parent node. Syntax void deleteTree(struct node* root) { if (root == NULL) return; deleteTree(root->left); deleteTree(root->right); free(root); } How Post-order Traversal Works ...

Read More
Showing 171–180 of 975 articles
« Prev 1 16 17 18 19 20 98 Next »
Advertisements