C Program to Find the Value of cos(x) Using Series

This C program computes the value of cos(x) by summing its Taylor series up to a given accuracy, then checks the result against the built-in cos() library function. It’s a great exercise in loops, floating-point arithmetic, and how mathematical functions are actually approximated inside a computer. The Cosine Series The Taylor series for cosine (with …

C program to find the value of sin(x)

This C program computes the value of sin(x) by summing its Taylor series up to a given accuracy, then compares the result with the built-in sin() library function. It’s a classic exercise in loops, floating-point math, and how a computer approximates trigonometric functions. The Sine Series The Taylor series for sine (with x in radians) …

GCD and LCM of Two Numbers in C – Euclid’s Algorithm

The GCD (Greatest Common Divisor) and LCM (Least Common Multiple) of two integers in C are most efficiently found using Euclid’s algorithm. The algorithm repeatedly replaces the larger number with the remainder of dividing the two numbers until the remainder is zero — what remains is the GCD. The LCM then follows from the identity …

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 …