c logarithm check if number is base
#include <stdio.h>
#include <math.h>
int isPowerOf(int base, int num) {
if (base <= 1 || num <= 0) {
return 0;
}
double logarithmResult = log(num) / log(base);
return (logarithmResult == (int)logarithmResult);
}
int main() {
int base, num;
printf("Enter the base: ");
scanf("%d", &base);
printf("Enter the number to check: ");
scanf("%d", &num);
if (isPowerOf(base, num)) {
printf("%d is a power of %d.\n", num, base);
} else {
printf("%d is not a power of %d.\n", num, base);
}
return 0;
}