C Example: GCD and LCM: Euclid's algorithm, iterative and recursive
Provides both iterative and recursive Euclid's algorithm for GCD, then computes LCM as a/gcd*b with long long and boundary checks to avoid multiplication overflow. Tests 48/18, 17/5, 0/9, a negative pair and 1071/462.
🖥 Run OnlineGCC 10.2 · C11 standard · click ▶ to run · Copy code
🖨 Reference OutputMatches the online run in a standard C11 environment
a= 48 b= 18 gcd_iter= 6 gcd_rec= 6 lcm=144 a= 17 b= 5 gcd_iter= 1 gcd_rec= 1 lcm=85 a= 0 b= 9 gcd_iter= 9 gcd_rec= 9 lcm=0 a= -24 b= 36 gcd_iter= 12 gcd_rec= 12 lcm=72 a=1071 b= 462 gcd_iter= 21 gcd_rec= 21 lcm=23562
🧩 Keep Learning