0% found this document useful (0 votes)
2 views8 pages

Functions in C Factorial Power Binary GCD and LCM

This document presents C programs that utilize functions for key computations, including factorial calculation, power functions, decimal to binary conversion, and finding GCD and LCM. Each function includes input validation and specific logic for handling various cases. The summary highlights the recursive nature of the factorial function, the handling of both positive and negative exponents in the power function, and the efficiency of GCD in calculating LCM.

Uploaded by

papercloudds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Functions in C Factorial Power Binary GCD and LCM

This document presents C programs that utilize functions for key computations, including factorial calculation, power functions, decimal to binary conversion, and finding GCD and LCM. Each function includes input validation and specific logic for handling various cases. The summary highlights the recursive nature of the factorial function, the handling of both positive and negative exponents in the power function, and the efficiency of GCD in calculating LCM.

Uploaded by

papercloudds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Functions in C: Factorial,

Power, Binary, GCD & LCM


This presentation covers C programs using functions for key computations.

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

Multiplies base by itself repeatedly. Calculates reciprocal of positive power.


Decimal to Binary Conversion
Conversion Method Output
Divides decimal by 2, stores Prints binary digits in
remainders. reverse order.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy