Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 3 of 81

Maximum difference of sum of elements in two rows in a matrix in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 364 Views

We are given a matrix and the task is to find the greatest difference between the sum of elements in two rows of a matrix. Suppose we have a matrix M[i,j] with i rows and j columns. Let the rows be R0 to Ri-1. The difference will be calculated by subtracting the (sum of elements of Ry) - (sum of elements of Rx), where x

Read More

Program for sum of geometric series in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 6K+ Views

In C programming, calculating the sum of a geometric series involves finding the total of terms where each term is obtained by multiplying the previous term by a constant ratio. A geometric series follows the pattern: a, ar, ar2, ar3, ..., where 'a' is the first term, 'r' is the common ratio, and 'n' is the number of terms. Syntax float sumGeometric(float a, float r, int n); Parameters a − First term of the geometric series r − Common ratio between successive terms n − Number of terms in the series ...

Read More

Program for triangular patterns of alphabets in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 385 Views

In C programming, triangular patterns of alphabets are commonly used to demonstrate nested loops and character manipulation. This pattern starts with a full line of consecutive alphabets and removes one character from the beginning in each subsequent line. Syntax for (i = 1; i

Read More

Profit and loss Problems using C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 3K+ Views

In C programming, profit and loss problems involve calculating the financial gain or loss from a transaction based on the cost price and selling price. Given a cost price (cp) and selling price (sp), we need to determine whether a profit was earned, a loss was suffered, or there was no profit nor loss. Syntax // Basic profit and loss calculation if (selling_price > cost_price) { profit = selling_price - cost_price; } else if (cost_price > selling_price) { loss = cost_price - selling_price; } else { ...

Read More

Product of given N fractions in reduced form in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 276 Views

Given the numerator and denominator of N fractions, the task is to find the product of all N fractions and output the result in reduced form. The product of fractions is calculated by multiplying all numerators together and all denominators together, then reducing the resulting fraction to its simplest form. For example, if we have fractions 4/5 and 3/4, their product would be (4×3)/(5×4) = 12/20, which reduces to 3/5. Fraction Multiplication: 4/5 × 3/4 = (4×3)/(5×4) = 12/20 = 3/5 4 5 ...

Read More

Program to Add Two Complex Numbers in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 10K+ Views

Given are two complex numbers in the form of a1 + ib1 and a2 + ib2, the task is to add these two complex numbers in C programming. Complex numbers are those numbers which can be expressed in the form of "a + ib" where "a" and "b" are real numbers and "i" is the imaginary unit which satisfies i² = −1. Since no real number satisfies this equation, it is called the imaginary unit. Syntax struct complex { int real; int imaginary; }; struct complex addComplex(struct ...

Read More

Product of middle row and column in an odd square matrix in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 296 Views

Given a square matrix, mat[row][column] where row and column are equal and are of odd length, the task is to find the product of middle row and middle column of that matrix. The matrix must have odd dimensions so there's always a clear middle row and column. 1 2 3 4 5 ...

Read More

Program to compare two fractions in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 776 Views

In C programming, comparing two fractions requires cross-multiplication to avoid floating-point precision issues. Given two fractions with numerators and denominators, we need to determine which fraction has the greater value. Syntax struct Fraction { int nume, deno; }; struct Fraction greater(struct Fraction first, struct Fraction second); Approach To compare fractions a/b and c/d, we use cross-multiplication: if a*d > b*c, then a/b > c/d. This avoids floating-point division and maintains precision. Example 1: Basic Fraction Comparison This example compares 4/5 and 3/4 using cross-multiplication − ...

Read More

Program to check if an array is sorted or not (Iterative and Recursive) in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 4K+ Views

Given an array arr[] with n number of elements, our task is to check whether the given array is in sorted order or not. If it is in sorted order then print "The array is in sorted order", else print "The array is not in sorted order". To solve this problem we can use iterative or recursive approach, we will be discussing both. Syntax int isSorted(int arr[], int n); Method 1: Iterative Approach In iterative approach, we use loops to traverse the array and compare adjacent elements ? #include ...

Read More

Program to check if a string contains any special character in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 7K+ Views

In C programming, checking if a string contains special characters is a common validation task. Special characters are those that are neither alphabetic nor numeric, such as symbols like !@#$%^&*() etc. Syntax int checkSpecialCharacter(char str[], int length); Method 1: Using Character Comparison This method iterates through each character and compares it against a predefined set of special characters − #include #include int checkSpecialCharacter(char str[], int n) { int i; for (i = 0; i < n; i++) { ...

Read More
Showing 21–30 of 809 articles
« Prev 1 2 3 4 5 81 Next »
Advertisements