C Program to reverse the first n characters in a file.

This program reads a filename and a count n from the command line, reads the first n characters from the file, reverses them in-place using a two-pointer swap, and prints the result. It demonstrates combining command-line argument parsing, file I/O with fread(), and in-place string reversal in a single practical program. The original post used …

C Program to perform complex numbers operations using structure.

Complex number operations in C using structures demonstrate how to pair two related values — a real part and an imaginary part — into a single user-defined type. Complex numbers are written as a + bi, where a is the real component and b is the imaginary component (i = √−1). They appear in signal …

C Program to Demonstrate global and internal variables.

Variable scope controls where in a program a variable can be accessed. In C, a variable’s scope is determined by where it is declared: variables declared outside all functions have file scope (global), while variables declared inside a function or block have block scope (local). A third kind — static local variables — persist between …

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 Find Sum and Average of an Array

C Program to Find Sum and Average of an Array This program reads N integers (positive, negative, and zero) into an array and computes three values: the sum of negatives, the sum of positives, and the average of all elements. Algorithm Read N (array size) from the user. Read N integers into the array one …

C Program To Find The Roots Of Quadratic Equation

A quadratic equation has the form ax² + bx + c = 0, where a ≠ 0. Its roots are found with the quadratic formula: x = (−b ± √(b²−4ac)) / 2a. The value under the square root — b²−4ac — is called the discriminant (D) and determines what type of roots exist: Discriminant Roots …