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)
|
Mentor
|
![]() |
| 8Nov2008,14:09 | #2 |
|
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
----------
7)1.0000000
7
---
30
28
--
2...etc
|
|
Go4Expert Member
|
|
| 8Nov2008,15:11 | #3 |
|
Quote:
Originally Posted by xpi0t0s Code:
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c,d,i,lcm;
char ch;
clrscr();
printf("Enter 1st fraction: ");
scanf("%d%c%d",&a,ch,&b);
printf("Enter 2nd fraction: ");
scanf("%d%c%d",&c,ch,&d);
printf("Result: %d / %d",den,lcm);
end:;
getch();
}
|
|
Go4Expert Member
|
|
| 8Nov2008,15:14 | #4 |
|
sorry cut that printf and end; label statement in the last
|
|
Go4Expert Member
|
|
| 8Nov2008,15:16 | #5 |
|
ooh i got that lcm part clear out, i just want now how to reduce the form p/q
|
|
Mentor
|
![]() |
| 8Nov2008,15:29 | #6 |
|
well, if p/q is 16/20, what's the lcm, and what's the final result?
|
|
Go4Expert Member
|
|
| 8Nov2008,15:33 | #7 |
|
if p/q is the result, it's not final we have to reduce it like 16/20 = 4/5(final result)
|
|
Mentor
|
![]() |
| 8Nov2008,15:34 | #8 |
|
lcm=least common multiple according to the Wiki, which is 2, but 8/10 isn't the simplest form.
|
|
Mentor
|
![]() |
| 8Nov2008,15:35 | #9 |
|
Yes, that's right. So how would you do that on paper?
|
|
Go4Expert Member
|
|
| 8Nov2008,15:51 | #10 |
|
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
|

