From e1417143f28e2cf79090e9dd89bb11fac7815f67 Mon Sep 17 00:00:00 2001 From: SinusFox Date: Wed, 31 May 2023 09:02:17 +0200 Subject: [PATCH] coding task 8 --- 8_Power_Calculator/8_Power_Calculator.c | 32 +++++++++++++++++++++++++ 8_Power_Calculator/8_Power_Calculator.h | 5 ++++ 2 files changed, 37 insertions(+) create mode 100644 8_Power_Calculator/8_Power_Calculator.c create mode 100644 8_Power_Calculator/8_Power_Calculator.h diff --git a/8_Power_Calculator/8_Power_Calculator.c b/8_Power_Calculator/8_Power_Calculator.c new file mode 100644 index 0000000..149d214 --- /dev/null +++ b/8_Power_Calculator/8_Power_Calculator.c @@ -0,0 +1,32 @@ +#include "8_Power_Calculator.h" + +void main() { + unsigned long base, power; + + // input + printf("Please type in the base: "); + scanf("%i", &base); + printf("\nPlease type in the power: "); + scanf("%i", &power); + + // calculate + Calculate(&base, &power); + + // output + printf("\nThe number is: %i.", base); + + return 0; +} + +void Calculate(unsigned long* base, unsigned long* power) { + unsigned long baseOriginal = *base; + if (*power == 0) { // power zero + *base = 1; + return; + } + if (*power > 0) { // power positive + for (unsigned int i = 1; i < *power; i++) { + *base *= baseOriginal; + } + } +} diff --git a/8_Power_Calculator/8_Power_Calculator.h b/8_Power_Calculator/8_Power_Calculator.h new file mode 100644 index 0000000..3013847 --- /dev/null +++ b/8_Power_Calculator/8_Power_Calculator.h @@ -0,0 +1,5 @@ +// libraries +#include + +//functions +void Calculate(unsigned long*, unsigned long*);