Check if a number is a power of another number | CPP program to check given number number y is power of x ; logarithm function to calculate value ; compare to the result1 or result2 both are equal ; Driven program
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; bool isPower ( int x , int y ) { int res1 = log ( y ) / log ( x ) ; return ( res1 == res2 ) ; } int main ( ) { cout << isPower ( 27 , 729 ) << endl ; return 0 ; }