Wuhan University of Science and Technology acm:1007: Chinese Edition C language Programming tutorial (second edition) Exercise 5.7

Source: Internet
Author: User
Tags greatest common divisor

Problem Description

This day the teacher gave small Hao a very simple topic relaxed: Enter a score, let you find their simplest score.

Input

The first line includes a T, which represents the number of groups of test data.

The next line of T lines includes a fraction. (The numerator denominator is within the int range)

Output

For each test sample, the output line has its simplest fraction.

Sample Input
32/63/111/36
Sample Output
1/33/111/36

My Code:
1#include <stdio.h>2ProcessintAintb/*greatest common divisor, so that the numerator function*/3 {4     intC;5      while(b!=0)6     {7c=a%b;8A=b;9b=C;Ten     } One     returnA; A } -  - voidMain () the { -     intn,i,a,b,min; -scanf"%d",&n); -      for(i=0; i<n;i++) +     { -scanf"%d/%d",&a,&b); +min=process (A, b); Aprintf"%d/%d\n", a/min,b/min); at     } -}

Other code:

1#include <iostream>2 3 using namespacestd;4 intMGCD (intAintb)5 {6 7     intT;8     if(a<b)9     {Ten  Onet=a;a=b;b=T; A     } -      while(a%b) -     { thet=b; -b=a%b; -A=T; -     } +     returnb; - } +  A intMain () at { -     inta,b,t; -     Charch; -     intCount=0; -     intT; -Cin>>T; in      while(cin>>a>>ch>>b) -     { to++count; +t=MGCD (A, b); -A/=T; theb/=T; *cout<<a<<"/"<<b<<Endl; $         if(count==T)Panax Notoginseng         { -              Break; the         } +     } A  the     return 0; +}

Wuhan University of Science and Technology acm:1007: Chinese Edition C language Programming tutorial (second edition) exercise 5.7

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.