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
It indicates 12 out of 34. Both the numerator and denominator are positive integers (excluding 0, if the definition of positive integers is unclear ).
Tip: Add "/" to the scanf format string to let scanf handle this slash.
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 example5/6
It indicates 5 out of 6.
Input example:
60/120
Output example:
1/2
Note: This question requires an appointment. In fact, it is to calculate the maximum denominator of a numerator, and then divide the denominator by the maximum denominator. The moving phase division is used to calculate the maximum common divisor.
#include "stdio.h"int main(){ int fz,fm,t; scanf("%d/%d",&fz,&fm); int origa=fz; int origb=fm; while(fm!=0) { t=fz%fm; fz=fm; fm=t; } printf("%d/%d",origa/fz,origb/fz); return 0;}
05-1. Minimum fraction (15)