C Program to Sort N Numbers in Descending Order

Sorting in descending order means arranging elements from largest to smallest. The only difference from ascending bubble sort is the direction of the comparison: ascending uses arr[j] > arr[j+1] (swap when left is larger), while descending uses arr[j] < arr[j+1] (swap when left is smaller). This program fixes the original which used void main, a …

C Program to multiply given number by 4 using bitwise operators

C Program to multiply given number by 4 using bitwise operators. Bitwise operators allows to cahnge or edit the specific bits within an integer. Program will multiply a given number by 4 using left shift(<<) bitwise operator. Read more about C Programming Language . /************************************************************ You can use all the programs on www.c-program-example.com* for personal …

C Program to check if a given matrix is an identity matrix

The identity matrix (also called the unit matrix) is a square matrix in which every element on the main diagonal is 1, and all off-diagonal elements are 0. It is the multiplicative identity for matrix multiplication: for any matrix A, multiplying by the identity matrix I gives IA = AI = A. This program reads …

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 Find Length of a String Without strlen

The standard library’s strlen() counts characters in a string by walking from the first character until it reaches the null terminator (‘\0’) — the zero byte that marks the end of every C string. Implementing strlen() yourself is a classic exercise that teaches exactly how strings work in C. The original post had two serious …