coding task 8

This commit is contained in:
SinusFox
2023-05-31 09:02:17 +02:00
parent 0b44293624
commit e1417143f2
2 changed files with 37 additions and 0 deletions
+32
View File
@@ -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;
}
}
}