Simplest fraction,

Source: Internet
Author: User

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; }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.