Sometimes freelancer programmers can learn simple stuff from kids. For example, if you forget fractions, we will refresh our knowledge in this small lesson.
What is a mixed number?
The mixed number of sums is an integer other than zero and a simple fraction, where the amount is shown without a plus sign “+.” In that case, if you have two cakes and three-quarters of the third cake, you can write as 2 + 3/4, which is equal to 2 3/4.
What is 5/2 as a Mixed Number?
5/2 fraction can be written as a mixed number like 2 1/2. It means that 5/2 consists of two whole objects and half of a third. In simple words, 5/2 consists of four halves from the whole object and one-half of a third.
So if you want to practice mixed numbers in programming, you can do this:
For natural numbers a and b, write a program that translates the false fraction a/b into a mixed number n c/ b, such that c/b <1
In the first line of the standard input, there is a natural number a, which represents the numerator of the false fraction. In the second line, the natural number b is different from zero, which means the denominator of the fraction (a≥b). The first and only line of the standard output contains a mixed record of a fraction, more precisely a natural number, a counter, and a denominator of a mixed number separated from each other by one space (blank character).
23
8
Exit
2 7 8
or this is code in Python:
dem = int(input('Type denominator'))
a = num // dem
b = num % dem
print 'The mixed number is {} and {}/{}'.format(a, b, dem)