sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 20 of 98

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

Sum of the first N terms of the series 2, 6, 12, 20, 30.... in c programming

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

In C programming, we can find the sum of the series 2, 6, 12, 20, 30… by analyzing its pattern. Each term can be expressed as n + n² where n is the position. Syntax sum = n*(n+1)/2 + n*(n+1)*(2*n+1)/6 Series Analysis Let's analyze the given series − Series: 2, 6, 12, 20, 30... Term 1: 2 = 1 + 1² = 1 + 1 Term 2: 6 = 2 + 2² = 2 + 4 Term 3: 12 = 3 + 3² = ...

Read More

Sum of first n natural numbers in C Program

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

In C programming, finding the sum of the first n natural numbers is a common problem that can be solved using different approaches. The sum of first n natural numbers means adding all positive integers from 1 to n (i.e., 1 + 2 + 3 + ... + n). For example, if n = 5, then the sum would be: 1 + 2 + 3 + 4 + 5 = 15 Syntax sum = n * (n + 1) / 2 We have two main methods to calculate this sum − Method ...

Read More

C Program for simple interest?

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

Simple Interest is the product of principal amount, rate of interest and the time duration (in years) divided by 100. It is a straightforward method to calculate the interest earned or paid on a loan or investment. Syntax Simple Interest = (Principal × Rate × Time) / 100 Where: Principal − The initial amount of money Rate − The interest rate per year (in percentage) Time − The time period (in years) Example Let's calculate simple interest with principal = 5000, rate = 4%, and time = 5 years − ...

Read More

Area of a leaf inside a square in C Program?

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

To find the area of a leaf inside a square, we need to split it into parts and find the area of each part, then add the areas together. The leaf shape is formed by the intersection of two quarter circles within a square. Syntax area = a * a * (PI / 2 - 1); Where a is the side length of the square and PI is approximately 3.14159265. Mathematical Approach To calculate the area, we split the leaf into two identical parts. For one part (AECA), we find the area of ...

Read More

Area of largest Circle inscribed in N-sided Regular polygon in C Program?

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

In geometry, finding the area of the largest circle inscribed in an N-sided regular polygon is a common problem. The inscribed circle (incircle) is the largest circle that fits entirely inside the polygon, touching all sides. Syntax r = a / (2 * tan(π / n)) Area = π * r² Where: r is the radius of the inscribed circle a is the side length of the polygon n is the number of sides Mathematical Derivation A regular N-sided polygon can be divided into N equal triangles from the center. Each ...

Read More

Area of Incircle of a Right Angled Triangle in C Program?

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

To find the area of the incircle (inscribed circle) of a right angled triangle, we use the formula for the inradius and then calculate the area. The inradius r of a right angled triangle is given by r = (P + B − H) / 2, where P is the perpendicular, B is the base, and H is the hypotenuse. The area of a circle is given by Area = π*r2, where π = 3.14159 and r is the radius of the circle. Base (B) Height (P) ...

Read More

Area of a square inscribed in a circle which is inscribed in an equilateral triangle in C Program?

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

The program finds the area of a square inscribed in a circle which is inscribed in an equilateral triangle. When a circle is inscribed in an equilateral triangle of side length a, the radius of the circle is a/(2√3). The diameter of the inscribed circle becomes the diagonal of the square: d = 2 * r = a/√3. Using the formula for the area of a square given its diagonal (1/2) * d², we get: Area = (1/2) * (a²/3) = a²/6. ...

Read More
Showing 191–200 of 975 articles
« Prev 1 18 19 20 21 22 98 Next »
Advertisements