sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 16 of 98

C/C++ Program to Find the sum of Series with the n-th term as n^2 – (n-1)^2

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

This program finds the sum of a mathematical series where the n-th term is defined as Tn = n2 - (n-1)2. We need to calculate the sum Sn = T1 + T2 + T3 + ... + Tn modulo (109 + 7). Syntax result = ((n % mod) * (n % mod)) % mod; Mathematical Derivation First, let's simplify the term Tn − Tn = n2 - (n-1)2 Tn = n2 - (n2 - 2n + 1) Tn = n2 - n2 + 2n - 1 Tn = 2n - 1 ...

Read More

Add n binary strings?

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

In C programming, adding n binary strings involves performing binary addition on multiple binary numbers represented as strings. We need to add all binary strings together to produce a single binary result. The approach uses binary addition logic with carry propagation, adding all strings one by one to get the final result. Syntax char* addBinaryStrings(char* binary1, char* binary2); char* addNBinaryStrings(char** binaryArray, int n); Example: Adding Multiple Binary Strings This example demonstrates adding three binary strings using a helper function that adds two binary strings at a time − #include #include ...

Read More

Add all greater values to every node in a given BST?

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

In this problem, we need to modify each node in a Binary Search Tree (BST) by adding the sum of all greater node values to the current node's value. This transforms the BST while maintaining its structure but changing the node values. Syntax void addGreaterValues(struct Node* root, int* sum); Problem Statement Given a Binary Search Tree, we need to add to each node the sum of all node values that are greater than the current node value. Input BST 10 5 ...

Read More

Add 1 to a number represented as a linked list?

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

The linked list representation of a number stores each digit in a separate node, where the first node contains the most significant digit and the last node contains the least significant digit. For example, the number 202345 is represented as (2→0→2→3→4→5). To add 1 to this linked list represented number, we need to handle carry propagation from the least significant digit. If the last digit is less than 9, we simply increment it. Otherwise, we propagate the carry to the next digits. Syntax struct Node* addOne(struct Node* head); Algorithm The algorithm follows these ...

Read More

A Number Link Game?

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

Number Link is a logic puzzle where players must connect matching numbers on a grid using continuous paths. The paths cannot cross or branch, and each number must be at the endpoint of exactly one path. This implementation generates a random Number Link puzzle and its solution using a union-find data structure. Syntax struct _node { struct _node *parent; int rank; int path_number; int endpoint; }; Algorithm Overview The algorithm works by generating random paths first, then creating ...

Read More

C program to calculate the value of nPr?

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

Permutations, nPr can also be represented as P(n, r), is a mathematical formula to find the number of ways to arrange r objects from n objects where order matters. The formula of P(n, r) is n! / (n − r)!. The number of permutations on a set of n elements is given by n! where "!" represents factorial. Syntax nPr = n! / (n - r)! Where: n is the total number of objects r is the number of objects to be selected ! denotes factorial Example Let's calculate P(5, ...

Read More

C program to Find the Largest Number Among Three Numbers

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

This program takes three numbers and finds the largest among them. We will use conditional statements to compare the numbers and determine which one has the maximum value. Syntax if (condition1) { if (condition2) { // statements } else { // statements } } else { if (condition3) { // statements } else ...

Read More

C Program for the compound interest?

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

Compound interest is the interest calculated on both the principal amount and the previously earned interest. Unlike simple interest, compound interest grows exponentially because the interest earned in each period is added to the principal for the next calculation period. Syntax Compound Interest = Principal * pow((1 + Rate/100), Time) - Principal Amount = Principal * pow((1 + Rate/100), Time) Example: Calculate Compound Interest Here's a complete C program to calculate compound interest using the mathematical formula − #include #include int main() { float principal, ...

Read More

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

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 982 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

10's Complement of a decimal number?

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

The 10's complement of a decimal number is a mathematical operation used in digital systems to simplify arithmetic operations, particularly subtraction. It is calculated by subtracting the given number from 10n, where n is the total number of digits in the number. The 10's complement can be found in two ways − Method 1: Calculate 9's complement first, then add 1 Method 2: Direct calculation using formula: 10n - number Syntax int tensComplement = pow(10, digitCount) - number; Method 1: Using 9's Complement First find the 9's complement by subtracting ...

Read More
Showing 151–160 of 975 articles
« Prev 1 14 15 16 17 18 98 Next »
Advertisements