FRACTION IN C LANGUAGE
Solved
Coucou1504
Posted messages
56
Registration date
Status
Member
Last intervention
-
Coucou1504 Posted messages 56 Registration date Status Member Last intervention -
Coucou1504 Posted messages 56 Registration date Status Member Last intervention -
Hello,
I need to write a program that gives the result in the form of a fraction for the product of fractions. I am able to get a result but not as a fraction. How can I obtain a result in fraction form??
Thank you in advance
I need to write a program that gives the result in the form of a fraction for the product of fractions. I am able to get a result but not as a fraction. How can I obtain a result in fraction form??
Thank you in advance
Configuration: Windows Vista Internet Explorer 7.0
6 answers
Purely display then?
23 / 11
for a "pretty" display, you need to retrieve the number of characters required to write each number (log 10 of the number) to determine the number of spaces to insert in front of the smaller of the two so that they are aligned and also to know the number of characters to draw the fraction bar.
M.
printf( "%d / %d\n", numerator, denominator );
23 / 11
for a "pretty" display, you need to retrieve the number of characters required to write each number (log 10 of the number) to determine the number of spaces to insert in front of the smaller of the two so that they are aligned and also to know the number of characters to draw the fraction bar.
3 ---- 27
M.
Hello,
There are no fractions in C. At best, there are floating-point numbers, but it's not great for retrieving the fraction. (Actually, it can be done decently, but anyway...) The ideal is to manage two integers yourself, for the numerator and the denominator.
(As long as this is also your input data format)
M.
There are no fractions in C. At best, there are floating-point numbers, but it's not great for retrieving the fraction. (Actually, it can be done decently, but anyway...) The ideal is to manage two integers yourself, for the numerator and the denominator.
(As long as this is also your input data format)
M.
Thank you for responding, but how can I simplify a fraction? My statement also asks me to simplify a fraction! There is currently only this "little" thing that bothers me!!!
Thank you in advance.
Thank you in advance.
Ah, well... just like in math...
18 / 6 = 3 / 1 because
18 = 2 * 3 * 3 and
6 = 2 * 3
In short, we break each down into a product of prime factors and eliminate the common factors equally.
1024 / 96
1024 = 2^10
96 = 2^5 * 3
so 1024 / 96 = 2^(10-5) * 3^(0-1) = 32 / 3
You need to create two arrays where the index represents the i-th prime number and the value represents its power in the decomposition of the number.
M.
Or brute force, as long as both are divisible by an integer, you divide them, when they are no longer divisible, you test with the next integer until that integer is less than the square root (/or half...) of the smaller of the two numbers.
18 / 6 = 3 / 1 because
18 = 2 * 3 * 3 and
6 = 2 * 3
In short, we break each down into a product of prime factors and eliminate the common factors equally.
1024 / 96
1024 = 2^10
96 = 2^5 * 3
so 1024 / 96 = 2^(10-5) * 3^(0-1) = 32 / 3
You need to create two arrays where the index represents the i-th prime number and the value represents its power in the decomposition of the number.
M.
Or brute force, as long as both are divisible by an integer, you divide them, when they are no longer divisible, you test with the next integer until that integer is less than the square root (/or half...) of the smaller of the two numbers.