+ 1

How to make a program that answers logxY

it is alogarithm program and the user will give the base and number, X is the base and Y is number

25th Mar 2017, 11:16 AM
Rami Abdalla
Rami Abdalla - avatar
1 Antwort
+ 2
Well logxY answers the question "by what number do you need to involute x that it would be equal to Y?" Let's say the answer is z. Therefore I built this program that works with ints: #include <iostream> #include <cmath> #include <climits> using namespace std; int main() { int x = 0; int y = 0; int z = INT_MIN; cin >> x >> y; if((x == 1) || (x < 0) || (y < 0)) return 0; //since x can't be equal to 1, less than 0 and y can't be less than 0 while(true) { if(pow(x, z) == y) break; z++; } cout << z; return 0; }
25th Mar 2017, 2:08 PM
Zablas
Zablas - avatar