C Program to Compare Two Strings – Manual and strcmp()

This C program compares two strings and reports whether they are equal, or which one comes first in dictionary (lexicographic) order. Comparison works character by character: walk both strings together until two characters differ or a string ends, then decide from that first difference. This page shows a manual character-by-character implementation and the standard library …

C Program to demonstrate time functions.

The time.h library in C provides functions for getting the current date and time, formatting it for display, and converting between representations. The central type is time_t — typically a 32-bit or 64-bit integer counting seconds since the Unix epoch (1970-01-01 00:00:00 UTC). Five key functions cover the most common time operations: time(), ctime(), localtime(), …

C #define Macro – Object-Like, Function-Like, and Conditional Macros

C preprocessor directives are instructions that run before compilation. The preprocessor reads your source file, processes every line that starts with #, and hands the result to the compiler. Understanding them well means smaller code, safer constants, conditional compilation for different platforms, and header files that include safely more than once. Object-Like Macros — #define …

C Program to Find Second Largest and Second Smallest Element in an Array

Finding the second largest and second smallest elements in an array can be done in a single pass through the data — O(n) time, O(1) space — without sorting. The key is maintaining four running extremes: largest, second_largest, smallest, second_smallest. The original program sorted the array first (O(n²) with bubble sort), then accessed fixed indices …

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