Write a function addFractions that takes as input four integers representing the numerators and denominators of two fractions, adds the fractions, and returns the numerator and denominator of the result. Note that this function should have a total of six parameters. Hint: a/b + c/d = (ad+bc)/bd.

Respuesta :

Answer:

The function is written in Python:

def addFractions(a,b,c,d):

    num = a*d + b*c

    denom = b * d

    return [num, denom]

a = int(input("Numerator 1: "))

b = int(input("Denominator 1: "))

c = int(input("Numerator 2: "))

d = int(input("Denominator 2: "))

print(addFractions(a,b,c,d))

Explanation:

The program is written in Python and I also include the main of the program

This defines the function

def addFractions(a,b,c,d):

This calculates the numerator

    num = a*d + b*c

This calulates the denominator

    denom = b * d

This returns the numerator and the denominator

    return [num, denom]

The main starts here

This prompts user for the numerator of the first fraction

a = int(input("Numerator 1: "))

This prompts user for the denominator of the first fraction

b = int(input("Denominator 1: "))

This prompts user for the numerator of the second fraction

c = int(input("Numerator 2: "))

This prompts user for the denominator of the second fraction

d = int(input("Denominator 2: "))

This pass arguments to the function

print(addFractions(a,b,c,d))