March 17th, 2013, 10:39 PM
Hello all, I'm stuck with a problem for my homework.
Write a for loop that calculates the total of the following series of numbers:
(1/30) + (2/29) + (3/28) + ... (30/1)
So far I got this:
int numerator, denomenator;
for(int numerator = 1; int numerator <= 30; numerator++
for(int denomerator = 30; int denomenator >= 1; denomenator--
I'm kind of lost on how to print out the fractions without outputing a decimal point. Thanks for the help!
March 18th, 2013, 07:17 AM
Try using only one loop. Have a separate variable that starts at 30 and is decremented by 1 for the denominator.
Build a String of the parts that you want to display vs having an arithmetic expression:
3 + "/" + 4
March 18th, 2013, 08:44 AM
Are you just printing out the fractions themselves or you adding the fractions?