C Program for Matrix Addition, Subtraction and Trace

This program reads two matrices of the same order, computes either their sum or difference (user’s choice), and then finds the trace of the result. The trace of a matrix is the sum of its main diagonal elements (positions where row index equals column index). It is defined for any matrix, not just square ones …

C Program to Evaluate Polynomial Using Horner Method

A polynomial of degree N is an expression of the form: P(x) = ANxN + AN-1xN-1 + … + A1x + A0 The naïve way to evaluate this requires computing each power xk separately, which takes O(N²) multiplications in total. Horner’s method rewrites the polynomial as a nested product that requires only N multiplications and …

C Program to find the average of largest two of the given numbers in the array.

This program reads N integers and finds the two largest values without sorting the array, then computes their average. The key technique: maintain two variables — first (the largest seen so far) and second (the second-largest). Scan each new element and update these two variables in one pass. Time complexity: O(n). Space: O(1) — no …

C program to input real numbers and find the mean, variance and standard deviation

Given N real numbers, this program computes three fundamental descriptive statistics: the mean (arithmetic average), the variance (how spread out the values are from the mean), and the standard deviation (the square root of variance — in the same units as the data). These are the first three statistics taught in any probability or data …

C Program to Find the Value of cos(x) Using Series

This C program computes the value of cos(x) by summing its Taylor series up to a given accuracy, then checks the result against the built-in cos() library function. It’s a great exercise in loops, floating-point arithmetic, and how mathematical functions are actually approximated inside a computer. The Cosine Series The Taylor series for cosine (with …

C program to find the value of sin(x)

This C program computes the value of sin(x) by summing its Taylor series up to a given accuracy, then compares the result with the built-in sin() library function. It’s a classic exercise in loops, floating-point math, and how a computer approximates trigonometric functions. The Sine Series The Taylor series for sine (with x in radians) …