Simplest fraction,
Simplest fraction (10 points)
Subject content:
Scores can be expressed as "Numerator/Denominator. Write a program that requires the user to enter a score and divide the score into the simplest fraction. The simplest fraction means that the numerator and denominator do not have any components that can be divided. For example, 6/12 can be divided into about 1/2. When the numerator is greater than the denominator, it does not need to be expressed as an integer or a score, that is, 11/8 or 11/8. When the denominator is equal, it is still expressed as a score of 1/1.
Input Format:
Enter a score in a row. The numerator and denominator are separated by a slash (/). For example, 12/34 indicates 12 parts of 34. Both the numerator and denominator are positive integers (excluding 0 ).
Tip: Add "/" to the scnaf format string.
Output Format:
Output the simplest fraction corresponding to the score in a row. The format is the same as that of the Input. That is, the score is expressed in the form of "Numerator/Denominator. For example, 5/6 indicates 5 out of 6
Input example:
60/120
Output example:
1/2
#include <stdio.h>
int
cacu(
int
a,
int
b){
// This function is used to input the numerator a and denominator B, and returns the maximum approximate number.
int
temp;
while
(b!=0)
{
temp=a%b;
a=b;
b=temp;
}
return
a;
}
int
main()
{
int
a, b;
scanf
(
"%d/%d"
, &a, &b);
int
c = cacu(a,b);
a /= c;
b /= c;
printf
(
"%d/%d\n"
, a, b);
return
0;
}