sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 20 of 98

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 393 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 732 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 390 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 257 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 205 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

C vs BASH Fork bomb?

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

A fork bomb is a Denial of Service (DoS) attack that exploits the fork() system call to create an exponentially growing number of processes, eventually exhausting system resources. Both BASH and C can implement fork bombs, but they work differently. Syntax pid_t fork(void); BASH Fork Bomb The classic BASH fork bomb is a compact one-liner − :(){ :|: & };: This code works as follows: :() − Defines a function named : { :|: & } − Function body that pipes itself to itself and runs in background ...

Read More

Sum of squares of first n natural numbers in C Program?

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

In C programming, finding the sum of squares of the first n natural numbers means calculating 12 + 22 + 32 + ... + n2. This is a common mathematical problem that can be solved using different approaches. Example: For n = 5, the sum is 12 + 22 + 32 + 42 + 52 = 1 + 4 + 9 + 16 + 25 = 55 Syntax // Using loops for(int i = 1; i

Read More

Write you own Power without using multiplication(*) and division(/) operators in C Program

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

Power function is calculated using repeated multiplication i.e. 5n is 5*5*5… n times. To implement this without using multiplication(*) and division(/) operators, we will use nested loops that add numbers repeatedly to simulate multiplication. Syntax int power(int base, int exponent); Example: Using Nested Loops This approach uses nested loops where the outer loop runs for the exponent value and the inner loop performs repeated addition to simulate multiplication − #include int power(int base, int exponent) { if (exponent == 0) { ...

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