Hello,
I am beginning to learn how to program and am just wondering how to reduce fractions. I think you're supposed to use a for loop but I don't know the for loop statement or the body of the loop. My variables I have so far that are needed are unsimplen for the un-simplified numerator, unsimpled for the un-simplified denominator, simplen for the simplified numerator, and simpled for simplified denominator. If doing this involves a function or structure, just tell me as I don't know how to program those yet. Thanks in advance.
Well I could but its about 600 lines long and most of those lines have nothing to do with what I'm trying to figure out. Do you still want me to post it?
It wasn't a horrible try, but a little too simplistic. Also converting, and then going back and converting again isn't always the best way. Here is something that should work for you, I tested a few numbers and they were always right so give it a shot and let me know how it works for you.
1 2 3 4 5
for (int i = unsimplen; i > 0; i --)
if ((unsimplen % i == 0) && (unsimpled % i == 0)) {
unsimplen /= i;
unsimpled /= i;
}