English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Lets say, i used 2 fractions in a program and added them together, How to output simplified fractions (i.e. 2/4 = 1/2)??

2007-11-21 02:41:49 · 5 answers · asked by David Junior 3 in Computers & Internet Programming & Design

5 answers

i % 20 means take i, divide it by twenty evenly, then return the remainder. It has nothing to do with your additional details.

9 % 4 is 1 because 9 / 4 = 2 Remainder 1
11 % 4 is 3 because 11/4 = 2 Remainder 3
30 % 20 is 10 because 30/20 = 1 Remainder 10

x % y is EXACTLY equivalent to
x - (int(x) / int(y)) ***that is to say:
x - x/y WITH INTEGER DIVISION

Now, if you wanted to get a simplified fraction, you have to do all the steps you would in real life.

find the common denominator (and corresponding numerator) then add together, then simplify.

2007-11-21 02:46:22 · answer #1 · answered by lansingstudent09101 6 · 3 0

In other languages, the '%' is called the modulus operator, and is used for returning the integer portion of a remainder of division. For example, 20 % 5 = 0, because 5 divides evenly into 20. 13 % 5 = 3, because 3 is the integer portion of the remainder when dividing 13 by 5. It is often useful when trying to figure out if a number is odd or even (any number where that number % 2 = 0 is even), and also for more advanced operations like encryption algorithms, etc.

2007-11-21 02:51:03 · answer #2 · answered by Anonymous · 1 0

i%20 means variable 'i' modulus '20'... for example, the number in the variable 'i' is '30', so it will be 30 modulus 20, the output will be 5.. it works like this, 30 divided by 20 is 1.5 right.. in c++, if you divide 30 by 20, it will output only 1.. if you use modulus, the remainder 5 will be outputed.. got it??

in simplifying do a loop.. i think there is no one way simplfying method to do it.. you will have to fabricate a solution..

btw, the variable i can be any integer..

2007-11-21 02:49:49 · answer #3 · answered by Anonymous · 0 0

It's called modulo, the remainer of dividing one number by another.

2007-11-21 02:51:53 · answer #4 · answered by ray_diator 7 · 0 0

The % stands for the remainder.

2007-11-21 02:50:32 · answer #5 · answered by Mike R 1 · 0 1

fedest.com, questions and answers