Help in 2 programs required???
Well we got an assignment of 20 questions, i am able to solve 18 of them but these 2 questions are getting off my brain, can anyone please help me to make these
15. Write an algorithm that inputs two fractions in the form a/b and c/d, and outputs their sum in the form p/q cancelled down to its simplest form.  19. FRACTIONS TO DECIMALS: Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator, that prints out the decimal representation. If the decimal representation has a repeating sequence of digits, it should be indicated by enclosing it in brackets. For example, 1/3 = .33333333...is denoted as .(3), and 41/333 = .123123123...is denoted as .(123). Typical conversions are: 1/3 = .(3) 22/5 = 4.4 1/7 = .(142857) 3/8 = .375 45/56 = .803(571428) Test your program with the fractions above and the fraction 11/59. Sample Run ENTER N,D : 1,7 1/7 = .(142857) 
Re: Help in 2 programs required???
Well, how would you do them on paper?
If a/b=14/20 and c/d=16/36, what's p/q (I got 103/90)? Show your working, and we can help you translate that working into an algorithm. Also show how far you got and where you're stuck, and we can help you with the next step. Same goes for the second one. This one's a lot more interesting! Seems the key to this is to start with the long division algorithm you followed way back, you know where you write it out and solve it as follows: Code:
14...etc 
Re: Help in 2 programs required???
Quote:
Code:
#include <stdio.h> 
Re: Help in 2 programs required???
sorry cut that printf and end; label statement in the last

Re: Help in 2 programs required???
ooh i got that lcm part clear out, i just want now how to reduce the form p/q

Re: Help in 2 programs required???
well, if p/q is 16/20, what's the lcm, and what's the final result?

Re: Help in 2 programs required???
if p/q is the result, it's not final we have to reduce it like 16/20 = 4/5(final result)

Re: Help in 2 programs required???
lcm=least common multiple according to the Wiki, which is 2, but 8/10 isn't the simplest form.

Re: Help in 2 programs required???
Yes, that's right. So how would you do that on paper?

Re: Help in 2 programs required???
suppose i enter 8/12 + 6/8, now if i do it on paper it's lcm is 24, which my code is giving and the result is 34/24(which my code is giving), this is not the simplest form, it can further be divided, and reduced to 17/12, which i wanted, so how to reduce 34/24

All times are GMT +5.5. The time now is 02:37. 