Functions in C Factorial Power Binary GCD and LCM
Functions in C Factorial Power Binary GCD and LCM
by Simran Bera
Factorial Calculation Using
Recursion
Function Logic Input Validation
Recursively multiplies Handles negative inputs by
numbers down to 1 or 0. showing an error message.
Output
Displays factorial with formatted output.
Power Function for Exponentiation
Positive Exponent Negative Exponent
Edge Case
Handles zero input by printing 0.
Finding GCD Using Euclidean
Algorithm
Step 1
1
Replace larger number by remainder of division.
Step 2
2
Repeat until remainder is zero.
Step 3
3
Last non-zero remainder is the GCD.
Calculating LCM Using GCD
LCM is calculated by multiplying numbers and dividing by their GCD.
Formula
LCM(a,b) = (a * b) / GCD(a,b)
Efficiency
Uses GCD function to simplify calculation.
User Interaction in Programs
Input Prompts Input Validation
Programs ask users for Checks for valid inputs like
numbers to process. non-negative numbers.
Output Display
Results are printed clearly with context.
Summary of C Function Programs
Factorial Power Binary Conversion GCD & LCM
Recursive function with Handles positive and Converts decimal to binary Uses Euclidean algorithm
input checks. negative exponents. using arrays. and formula.