This project is a custom implementation of the mathematical Exponentiation function in C. Instead of relying on the standard <math.h> library's pow() function, this algorithm demonstrates how to calculate powers using fundamental control flow structures.
The algorithm computes the result of
-
Time Complexity:
$O(n)$ - Linear time relative to the exponent size. -
Space Complexity:
$O(1)$ - Uses a single accumulator variable.
- Input: Accepts an integer
baseand an integerexponent. - Initialization: Sets the accumulator (
sonuc) to 1 (the identity element for multiplication). - Iteration: Loops
exponenttimes.- In each step, updates:
accumulator = accumulator * base
- In each step, updates:
- Output: Prints the final calculated value.
- Compile the code:
gcc main.c -o power_calc
- Run the executable:
./power_calc
- Enter the base and exponent when prompted.
This repository demonstrates accumulator logic and loop structures in C programming.