Sum of Elements in a Matrix in C – Row, Column, and Total

A matrix is a 2D array of numbers arranged in rows and columns. Finding the sum of its elements — row by row, column by column, or all at once — is one of the most common matrix operations and a good exercise in nested loops and function design. This post shows two approaches: a …

C Program to Sort N Elements Using Selection Sort — With Step-by-Step Example

Selection Sort works by repeatedly finding the minimum element from the unsorted portion of the array and placing it at the beginning. After each pass, the sorted portion grows by one element from the left. It always performs exactly O(n²) comparisons regardless of input order — unlike Bubble or Insertion Sort, there is no early …

C program to check whether a given string is palindrome or not

A palindrome is a word, sentence, or sequence that reads the same forward and backward — ignoring differences in capitalization for word-level palindromes. Examples: “racecar”, “GADAG”, “level”, “9009”. The most efficient check uses a two-pointer approach: one pointer starts at the left end, one at the right, and they advance toward each other until they …

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