I am a high school student and I saw a while ago that is better to multiply than to divide. Since then, without any proof found that it is true or not and without knowing how to do find it by myself at the moment, I tried to modify my codes for that slightly better time.
Here is a problem where I wanted to find the biggest digit in a number using recursion.
This one is working.
#include <iostream>
using namespace std;
int minn = 9;
int digit(int n)
{
if(minn > n % 10)
minn = n % 10;
if(!(n / 10))
return minn;
else
return digit(n / 10);
}
int main()
{
int x;
cin >> x;
cout << digit(x);
return 0;
}
But this is not working.
#include <iostream>
using namespace std;
int minn = 9;
int digit(int n)
{
if(minn > n % 10)
minn = n % 10;
if(!(n * 0.1))
return minn;
else
return digit(n / 10);
}
int main()
{
int x;
cin >> x;
cout << digit(x);
return 0;
}
The only difference is that the broken one use if(!(n * 0.1)) not if(!(n / 10)).
Can someone clarify it for me or anyone who is seeking help what is the difference between x * 0.1 and x / 10?
Thank you all for clicking the question and that you tried to help!