sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 19 of 98

Ways to paint N paintings such that adjacent paintings don't have same colors in C programming

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

In this problem, you are given N paintings and we have M colors to paint them with. We need to find the number of ways to paint the paintings such that no two adjacent paintings have the same color. The program's output can have very large values, so we calculate the answer in standard modulo 109 + 7. Syntax long long paintWays(int n, int m); long long power(long long base, long long exp, long long mod); Mathematical Formula The formula to find the number of ways is − Ways = m ...

Read More

Surface Area and Volume of Hexagonal Prism in C programming

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

The surface area of any figure is the total area that its surface covers. A hexagonal prism is a three-dimensional figure that has a hexagon at both its ends. In mathematics, a hexagonal prism is defined as a three-dimensional figure with 8 faces, 18 edges, and 12 vertices. It consists of two hexagonal bases connected by rectangular faces. a ...

Read More

Superperfect Number in C programming

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

A superperfect number is a positive integer that satisfies a specific mathematical condition involving the sum of divisors function. This concept was introduced by D. Suryanarayana in 1969 as a generalization of perfect numbers. Syntax sig(sig(n)) = 2n Where sig(n) is the divisor summatory function that calculates the sum of all positive divisors of n (including 1 and n itself). Example 1: Checking if 16 is Superperfect Let's verify that 16 is a superperfect number by calculating sig(sig(16)) and comparing it with 2×16 − sig(16) = 1 + 2 + 4 ...

Read More

Super Prime in c programming

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

A super-prime number is a prime number that occupies a prime position in the sequence of all prime numbers. For example, if we list all prime numbers as 2, 3, 5, 7, 11, 13, ..., then the super-primes are the primes at positions 2, 3, 5, 7, 11, etc. So 3 (at position 2), 5 (at position 3), and 11 (at position 5) are super-primes. Syntax void superPrimes(int n); bool sieveOfEratosthenes(int n, bool isPrime[]); Example: Finding Super-Primes Less Than 50 This program uses the Sieve of Eratosthenes to find all primes, then identifies super-primes ...

Read More

Sums of ASCII values of each word in a sentence in c programming

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

In C programming, calculating the sum of ASCII values of each word in a sentence involves finding the ASCII value of each character and adding them up word by word. This technique is useful for text processing and string analysis tasks. Syntax int asciiValue = (int)character; // or simply int asciiValue = character; Example Here's how to calculate the sum of ASCII values for each word in a sentence − #include #include void calculateWordSums(char str[]) { int wordSum = 0; int ...

Read More

Sum triangle from an array in C programming

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

The sum triangle from an array is a triangle that is made by decreasing the number of elements of the array one by one. The new array that is formed contains integers that are the sum of adjacent integers of the existing array. This procedure continues until only one element remains in the array. Let's take an example to explain the concept better − Array = [3, 5, 7, 8, 9] Output [106] [47, 59] [20, 27, 32] [8, 12, 15, 17] [3, 5, 7, 8, 9] Explanation For ...

Read More

C Programming for sum of the series 0.6, 0.06, 0.006, 0.0006, ...to n terms

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

The given series 0.6, 0.06, 0.006, 0.0006, ... is a geometric progression where each term is obtained by dividing the previous term by 10. To find the sum of this series, we apply the formula for the sum of a geometric progression where the common ratio r < 1 (r = 0.1 in our case). Syntax Sum = a * (1 - r^n) / (1 - r) where a = first term, r = common ratio, n = number of terms Mathematical Formula For the given series − First term (a) = ...

Read More

C Programming for Sum of sequence 2, 22, 222, .........

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

Given is a sequence: 2, 22, 222, 2222… and we need to find the sum of this sequence. We need to derive a mathematical formula to calculate the sum efficiently. Syntax sum = 2 * (pow(10, n) - 1 - (9 * n)) / 81; Mathematical Derivation The formula derivation follows these steps − sum = [2 + 22 + 222 + 2222 + ...] sum = 2 * [1 + 11 + 111 + 1111 + ...] sum = 2/9 * [9 + 99 + 999 + 9999 + ...] sum ...

Read More

Sum of the numbers up to N that are divisible by 2 or 5 in c programming

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

Finding the sum of numbers up to N that are divisible by 2 or 5 can be efficiently calculated using the inclusion-exclusion principle. Instead of iterating through all numbers, we use mathematical formulas to compute the sum in O(1) time complexity. Syntax sum = sum_divisible_by_2 + sum_divisible_by_5 - sum_divisible_by_10 Mathematical Approach The solution uses three formulas based on arithmetic progression − Sum of numbers divisible by 2: Sum2 = ((n / 2) * (4 + (n / 2 - 1) * 2)) / 2 Sum of numbers divisible by 5: Sum5 = ...

Read More

Sum of the nodes of a Singly Linked List in C Program

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

A singly linked list is a data structure where each node contains two parts: the data value and a pointer to the next node. To find the sum of all elements in a singly linked list, we traverse each node and add its value to a sum variable. For example Suppose we have a linked list: 2 −> 27 −> 32 −> 1 −> 5 sum = 2 + 27 + 32 + 1 + 5 = 67 Syntax struct Node { int data; struct ...

Read More
Showing 181–190 of 975 articles
« Prev 1 17 18 19 20 21 98 Next »
Advertisements