0

c++

Write a program that can be used to express a fraction in its lowest form. Functions In order to complete this task, you are expected to complete the implementation of the three functions described below.  void displayFraction(int a, int b) Takes two integer numbers and display them in a fraction format such as a/b. Use default values for the parameters of this function so that if the function is called without parameters 0/1 is displayed and when called with one parameter (say x), then x/1 is displayed. Note that this function should simply display what it is given even if it is invalid.  int gcd(int a, int b) Takes two positive integers and returns the greatest common divisor of the two numbers. The greatest common divisor of any two numbers a and b is the largest positive integer c that is a divisor of both a and b. The number c is a divisor of b if the remainder after dividing b by c is zero. When passing 0 or a negative value as any one of these parameters, the function should return -1.  bool reduceFraction(int &num, int &denom) Takes two integers representing the numerator and denominator of a fraction. Reduces the fraction to its lowest form. For example, the result of reducing 20 4 is 5 1 . When passing 0 or a negative value as any one of these parameters, the function should return false, otherwise it should return true. Main program Write a program called References.cpp that uses the above functions. The program should prompt the user for a numerator and denominator. When given valid input, it should display the GCD of the two input values and then display the given fraction, the fraction in its lowest form as well as the fraction in decimal format. The following is a sample test run (user input is shown in bold): Fraction Reduction ------------------------------- Enter the numerator: 4 Enter the denominator: 20 The GCD of 4 and 20 is 4 The lowest form of 4/20 is 1/5 = 0.2

8th Apr 2017, 7:47 PM
InsaneBeatmaker Sane
InsaneBeatmaker Sane - avatar
4 Answers
+ 12
Is this your homework? Ppl will more likely help you if you show them what you have done so far and tell them what exactly your problem is.
8th Apr 2017, 8:07 PM
Tashi N
Tashi N - avatar
+ 10
tl;dr - Pls do dis homwok 4 meh kthxbai
9th Apr 2017, 4:03 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
OH MY đŸ˜Č look at all these words, I'm not reading that 😂
8th Apr 2017, 8:12 PM
Ghauth Christians
Ghauth Christians - avatar
0
#include <iostream> using namespace std; int main() { int b,n; cin>>b; cin>>n; for(int i=b;i>1;i--) { if(b%i!=0 || n%i!=0) {} else { b=b/i; n=n/i; } } cout<<b<<"/"<<n<<endl; return 0; }
8th Apr 2017, 10:43 PM
Leonida17st
Leonida17st - avatar