Write a function that takes a number b, and a number N, and returns true/false indicating whether N is a power of b, ie bk=N for some non negative integer k. The function returns true if N can be expressed as a power of b, and false otherwise.
Use the following function signature :
bool isPower(int b,int N).
The following code will be there, but won’t appear in your editor :
main_program{
int b,N;
cin>>b>>N;
if(isPower(b,N))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
This invisible code will test your function. This code will read the values b and N from the test case and print out “Yes” if your function returns true and “No” otherwise.
You don’t need to write/copy the main program. You just need to write the isPower function, without the main_program or any of the header files.
You don’t need to write/copy the main program. You just need to write the isPower function, without the main_program or any of the header files.
Note : Ensure that the name of the function is isPower and it takes the two parameters and returns true or false without printing anything.
Explanation of Sample Testcase 1
Input : b=2, N=1024
Output : 1024 can be expressed as 210. So the function returns true and Yes gets printed out by
the invisible code.
SOLUTION:
Will be posted soon! :)
Comments
Post a Comment