C program to find the sum of ‘N’ natural numbers.

The natural numbers are the positive integers: 1, 2, 3, 4, 5, … Their sum from 1 to N can be computed two ways: a simple loop that adds each number, or the Gauss formula N×(N+1)/2 that gives the answer in O(1) time without any loop. This post shows both, explains why the formula works, …

C Program to Check Whether a Given Integer is Positive or Negative

A number is positive if it is greater than zero, negative if it is less than zero, and zero is neither. This is one of the most fundamental checks in programming — it shows up in input validation, physics simulations, financial calculations, and signal processing. This program handles all three cases with a clear if-else …

C Program to Check Whether a Given Integer is Odd or Even

An integer is even if it is divisible by 2 with no remainder, and odd if dividing by 2 leaves a remainder of 1. Zero is even. Negative integers follow the same rule: −4 is even, −7 is odd. This program uses the modulo operator % to determine parity in a single if-else check. Number …

C Program to Find the Area of a Circle Given the Radius

The area of a circle is A = π r² and the circumference is C = 2πr, where r is the radius. This program computes both from a user-supplied radius. Key points: use radius * radius instead of pow(radius, 2) (no need for the math library for a simple square), define π as a high-precision …

C Program To Swap Two Variables

Swapping two variables is one of the most common operations in sorting, data structure manipulation, and algorithm implementation. There are three standard methods: using a temporary variable (clearest), arithmetic (no temp, but overflow risk), and XOR bit manipulation (no temp, no overflow, but tricky for same-variable self-swap). All three produce the same result — understanding …