for (int i = 0; i <= 100; i++) {
for (int j = 1; j <= 100; j++) {
if (((i / j) * 1000) == (int)(real * 1000)) {
numerator = i;
denominator = j;
} else if (((i / j) * 1000) == -(int)(real * 1000)) {
numerator = -i;
denominator = j;
}
}
}
this is the code I have right now to approximate some decimal (real) with a fraction, it seemingly works however the loop will continue after finding an approximation and thus leads to bigger fracions. How can I fix this? While loop?