C Program to Check if Two Matrices Are Equal

Two matrices are equal if and only if they have the same dimensions (same number of rows and same number of columns) and every corresponding pair of elements is equal: A[i][j] == B[i][j] for all i, j. If the dimensions differ, equality is impossible. This program checks both conditions. The original had void main(), exit(1) …

C Program to Compute x^n — Fast Recursive Exponentiation

Computing x raised to the power n (written xn) naively requires n multiplications. Binary exponentiation (also called fast power or exponentiation by squaring) reduces this to O(log n) multiplications by halving the exponent at each step: if n is even, compute xn/2 and square it; if n is odd, multiply x by xn-1. The original …

C Program to convert days to years, weeks and days

This program converts a given number of days into years, weeks, and remaining days using integer division and modulo arithmetic. The formula uses 365 days per year and 7 days per week (leap years are ignored). It is a straightforward exercise in chained division and remainder operations. The original post used void main() and broken …

C Program to compute the surface area and volume of a cube

A cube is a three-dimensional shape with six equal square faces. Given the side length s, the surface area is 6s² (six faces, each with area s²) and the volume is s³. This program reads the side length and computes both values using only basic arithmetic — no need for pow() and the -lm flag …

C Program to accept a string and a substring and check if the substring is present in the given string

Checking whether one string contains another is one of the most common string operations in C. The standard library provides strstr() in <string.h> — it returns a pointer to the first occurrence of the substring in the main string, or NULL if not found. The position of the match is calculated by subtracting the start …