0% found this document useful (0 votes)
319 views2 pages

PFC - Workshop 04B: 1. Fraction Simplifier

The document describes two functions to write: 1) A fraction simplifier function that takes in numerator and denominator, displays the fraction, and simplifies it. It should handle negative and zero values. 2) A roots function that calculates the real roots of a quadratic equation given coefficients a, b, c. It returns the number of real roots and the root values through parameters x1 and x2. It considers the discriminant to determine the number of real roots.

Uploaded by

vietanh hoang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
319 views2 pages

PFC - Workshop 04B: 1. Fraction Simplifier

The document describes two functions to write: 1) A fraction simplifier function that takes in numerator and denominator, displays the fraction, and simplifies it. It should handle negative and zero values. 2) A roots function that calculates the real roots of a quadratic equation given coefficients a, b, c. It returns the number of real roots and the root values through parameters x1 and x2. It considers the discriminant to determine the number of real roots.

Uploaded by

vietanh hoang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

PFC - Workshop 04B

1. Fraction Simplifier

In this question you should write 3 functions with prototypes as follows:

void input(int *num, int *den); // input numerator (num) and denominator of a fraction (den)
void display(int num, int den); // display the fraction
void simplify(int *num, int *den); // simplify the fraction

Include negative as well as zero values in your test cases.

The output from your program looks something like

2. roots Function

Design and code a C function named roots that calculates the roots of a quadratic equation.  Your
function receives three doubles that hold the coefficients of the quadratic equation and returns through
two other double parameters the real roots of the equation.  The function returns the number of real
roots as the return value of the function itself.  The header for your function looks something like

int roots(double a, double b, double c, double *x1, double *x2) 

Consider the quadratic equation:

f(x) = a * x2 + b * x + c
where a, b and c are constant coefficients.  This equation may have up to 2 real roots.  The roots are the
values of x for which

a * x2 + b * x + c = 0

The roots are given by the equations

x1 = ( - b + sqrt( D ) ) / ( 2 * a )
x2 = ( - b - sqrt( D ) ) / ( 2 * a )

where D is the discriminant

D = b2 - 4 * a * c

If D is positive-valued, there are 2 real roots.  If D is zero-valued, there is one real root.  If D is
negative-valued, there are no real roots.

If there is one real root, set x1 to its value and leave x2 unchanged.  If there are no real roots, leave x1
and x2 unchanged. 

The output from your program looks something like

You might also like