C Program to Demonstrate the increment and decrement operators

C program which demonstrates the working of increment(++) and decrement(–) operators. Increment operator ++ adds 1 to its operand and Decrement operator — subtracts 1 from its operand. These operators may be used either as a prefix operator or post-fix operator. Read more here: Increment and decrement operators The Program [gist id=”edcbcb339781cb831a2143821b0f32ce”] Sample Output Related programs …

GCD and LCM Using Recursion in C – Euclidean Algorithm

This C program finds GCD and LCM using recursion with the Euclidean algorithm. The GCD (Greatest Common Divisor) is the largest number that divides both inputs with no remainder. The LCM (Least Common Multiple) is the smallest number divisible by both. Once the GCD is known, the LCM follows from a simple identity: GCD(a, b) …

Factorial Program in C – Iterative and Recursive with Output

The factorial program in C is one of the most common exercises for learning recursion and loops. The factorial of a non-negative integer n, written n!, is the product of all positive integers from 1 to n. By definition, 0! = 1. This page covers two approaches — iterative and recursive — with compile-verified code, …

C Program to demonstrate the ‘fgets’ function.

Program to demonstrate the ‘fgets’ function. The program will count the number of lines in a file. This is a function of the UNIX command ‘wc’. Read more about C Programming Language . /************************************************************ You can use all the programs on www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial …

Combinations and Permutations in C (nCr and nPr)

Combinations and permutations in C are computed using two related formulas. A combination C(n, r) counts the number of ways to choose r items from n items where order does not matter. A permutation P(n, r) counts the number of ways to arrange r items chosen from n items where order matters. C(n, r) = …

C Preprocessor Directives – #define, #if, #ifdef, #ifndef with Examples

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 …