answersLogoWhite

0

The following shows how this can be achieved:

typedef struct fraction {

int n; // numerator

int d; // denominator

};

struct fraction subtract (struct fraction a, struct fraction b) {

struct fraction r; // result

r.d = lcm (a.d, b.d); // lowest common multiple

r.n = (a.n * (r.d/a.d)) - (b.n * (r.d/b.d));

return r;

}

The lcm() function has the following definition:

int lcm (int a, int b)

{

int sign = 1;

if (a<0) a*=-1, sign *=(-1);

if (b<0) b*=-1, sign *=(-1);

return (a*b) / gcd (a,b) * sign;

}

The gcd() function (greatest common divisor) has the following definition:

int gcd (int a, int b)

{ int sign = 1;

if (a<0) a*=-1, sign *=(-1);

if (b<0) b*=-1, sign *=(-1);

while (a!=b)

a>b?a-=b:b-=a;

return a * sign;

}

User Avatar

Wiki User

9y ago

What else can I help you with?

Continue Learning about Engineering

How do you add and subtract 16 bit numbers using 8051 microprocessor?

The 8051 is a microcontroller, not a microprocessor. To add or subtract, use the ADD or SUBB opcodes.


What is an example of an algorithm?

A computer algorithm is any set of instructions that a computer could use to produce a result. An example would be "given a numeric input, multiply that value by 9, divide the result by 5, then add 32." This is how a Celsius temperature is converted into Fahrenheit.


Write a program to subtract integer y from integer x?

x -=y;


How do you write a program on bcd addtion?

The first thing to remember is that a BCD digit is only 4 bits (a nibble). Secondly BCD is a base 10 system so the largest number for each digit is 9 but a nibble can have a value of up to 15. Thirdly, after each addition the resulting value has to be normalized. Here is the rule. If the resulting value is grater than 9, subtract 10 and also carry 1. Programming this is your job.


What is difference between procedure oriented and Object Oriented?

In POP, importance is given to the sequence of things to be done i.e. algorithms and in OOP, importance is given to the data.In POP, larger programs are divided into functions and in OOP, larger programs are divided into objects.In POP, most functions share global data i.e data move freely around the system from function to function. In OOP mostly the data is private and only functions inside the object can access the data.POP follows a top down approach in problem solving while OOP follows a bottom up approach.In POP, adding of data and function is difficult and in OOP it is easy.In POP, there is no access specifier and in OOP there are public, private and protected specifier.In POP, operator cannot be overloaded and in OOP operator can be overloaded.In POP, Data moves openly around the system from function to function, In OOP objects communicate with each other through member functions.

Related Questions

How do you subtract mixed numbers and improper fraction?

First you would want to change the mixed number to an improper fraction. Then you can subtract


How to subtract a fraction from a whole number?

Change the whole number into an improper fraction with the same denominator as the fraction and then subtract accordingly


How do you subtract whole numbers with fractions?

Turn the proper fraction into an improper fraction.


How to subtract a mixed number from a whole number?

You convert the mixed numeral into an improper fraction. Now subtract the improper fraction from the whole number by putting the whole number over 1.


How do you add and subtract frations with a whole number with a fraction?

Express the mixed fraction as an improper fraction and then proceed as you would with ordinary fractions. If the answer is an improper fraction, then remember to convert to a mixed fraction.


How do you subtract an improper fraction from a whole number?

u just bfffl


How can you add and subtract mixed numbers?

Make it into an both numbers an improper fraction and then do the opperation.


What is eight ninths subtract four sevenths as a fraction?

8/9 - 4/7 = 4/2 which is a improper fraction.


How do you subtract fractions without mixed numbers?

First, turn the fraction into a improper fraction. Then find a common denominator between the two numbers. After this, subtract strait across, but leave the denominator the same.


How do you add and subtract fractions in math?

You need common denominators. Then add or subtract the numerators. If the answer is an improper fraction it is common practice to reduce it to a mixed number.


How do you subtract mixed number from mixed numbers with dissimilar fraction?

Make them into improper fractions, find the least common denominator, convert them, subtract, reduce if possible.


How do you subtract mixed fractions with different denominators?

You change the mixed fraction to an improper fraction . Then you find the denominators GCF. Then you subtract. Another reply: Converting to an improper fraction is not really necessary, but converting to a common denominator is. Example: 3 1/2 - 1 1/3 = 3 3/6 - 1 2/6 = 2 1/6. In other words, you can subtract the integer part and the fraction part separately.