2 like 0 dislike
5k views

Write a program that asks the user to enter a fraction, then reduces the fraction to lowest terms.

寫一個程式 輸入一個分數,約分為最簡分數後輸出

Example input:

6/12

Example output:

1/2

Example input 2:

12/6

Example output:

2
[Exercise] Coding (C) - asked in Chapter 6: Loops by (5.2k points)
ID: 31048 - Available when: 2017-11-09 18:00 - Due to: Unlimited

edited by | 5k views

67 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>

int main()

{
* ** * ** ***** ** num,denom,n=1,flag,bflag,cflag,dflag;

* ** ** * * *** * *** * ** ** * * * * *

** * *** ** * ** ** (n;n<=num;n++)
** ** *** * * *
*** *** * * * * * * * * ** ** * *** * **  //12%2
**** ** * *** ** * * * * * *** *** * *** * ** ** *
* ** * * *** * *** * * * **** *** *** * * //bflag=6 num=6 n=2
** **** * * **** ** ** * ** * * * * **** (flag==0 && n!=1)
* * * * * * **** * ****** * ** ** * * *
** ** * ** * ******* *** * * *** ** ***** * *** * * * * ***** * * ** //18&2
* * ** * * * ** * ** ** * ** ***** * * * *** * * * * * * * * ** ***** *
* * *** * * * * *** * * * ******** ** * * * * * * ** * *** * * * ** * **  //denom=9 18/2 dflag=9
* * * * * *** *** * ** * * ************ * **
    }
* *** ** * * * ** ** (denom!=1)
* ** *** * * * * * * ** ** ** **
***** * * * ***** *
* * *** ***** **** **** *** * * ***** * **
* *** * * *** * * * *** 0;


}
answered by (-249 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
    int a,b,c,d,e;
* *** *** ** *** ****** * *** * * * *** ***** ** * *******
    d=a;
    e=b;
    if(d>e)
    {
** * * ** ***** * * *** * * * *** ** * * *** * * ** ***
* ** ** ****** * **** * ******* * * * *
** * * *** *** ** ** **** ***** *** * ****** ** * ******* * ****** ** * **
** * * * * ** * * **** **** * *** ** * * * * *** * *
**** **** * * * * * * * ******* * *** * **** *** * ** * ** * **
        }

** **** *** *** * * * * ** * * **** **** **
        {
** * * * **** ** * * ** ****** * * *** **** * ** *** * * * * ** * ** * ** * ***** ** ** * **
** ** **** * *** * ** * ** * * ** **** * * *
* * ***** *** * * * * * * ** * if(e!=1)
* ** ***** ** *** * * ** * * ** * * * ****** *
* * ** * * * *** * ** * *** * ** ** ******* ** ** * ***** *** * *** * ** *
** * ** * ** * ** ****** * * ** * ***
* ** * ** *** * * * ** ** ****** * ** * if(e==1)
** ** * * ***** ***** *** ****** *** ***** * * * **
** ** * * *** *** *** ** * * * * ** * ** * * *** * * * * ** * **** **
* * ** * ** ***** * *** ** ** * *** ** ** * * *
    }
    if(d<e)
    {
*** * *** ** * *** ** ** ***** *** ****** ** **** **
* * ** ***** ***** ** ** ** *** *** **
** **** * **** ****** ** ** * *** * ** * * ** * * * * * **** ** *****
* * ** *** * * ** ** * * *** *** * * * ** ***** * ******
* ** * * * * ** * * ** *** * ***** * ** ** ** **** * * ***** ** *
**** * * **** * ** * * * *** **** * **** *
* *** ******* * * * ** * *** * * ***** * *******
* * * ****** * **** * ** * **** **** ** ** *
* ** *** * * ** * * * ***** * * ***** ***** * *** * * *** ** * * ** ** * *** * * * * * * ** *
*** * *** ** ** ** ** ******** * * * **
* ** ** * * * * ** ** ** * * * * ** * * if(d==1)
** * * * * *********** ** *
* ** * *** ** *** * ** * ** *** * ** * * ** *** ******** * * ** ** * * ** **** * ****
**** * * * ** * * * * * **** * * *******
    }
    return 0;
}
answered by (-255 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>

int main() {
* * * * *** *** * * * x, y, tmp, a, b;
** ** * *** ******* ** * * *** ******** &x, &y);
* * * * * * * ** * **
* ** *** *** ** ** *
* * ** * * ** ***** ** ** * * {
* **** ** ** *** ***** * * *** **** ***** ***
* ** *** * * **** * ** *** **** ** * ****** **
** * ** **** * ** * ** *** * * * ** *** ** ****
* *** * ** *******
** * ** * **** * ** * ** * **** {
* * ** *** ** * *** * * ** * * **** *** * * ** ** * (x/b)/(y/b));
    }
** ** * *** * * * ** * ** {
*** * * ** * * *** * * *** ** * ** ** *** * * * * * x/b, y/b);
    }
}
answered
edited by
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
Case 3: Correct output
Case 4: Wrong output
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(void)
{
** * *** ****** * * * ** * frac1;
* ***** * * **** frac2;
** *** * * ** ** ** ** * gcd;

* ** ** **** ** * a;
* * ** * *** * * * *** ** b;
* *** **** * * * c;

* * ****** * * *** * * **** ** ** ** &frac1, &frac2);
* * * * ** ***** ** * = frac1;
    b = frac2;

** ** ** ** * * ** ** * *** 0)
* ** * **** * *** ** * ****
** ***** * ************ * * * ** ** ** * = a % b;
* **** * *** ** * ** *** * * * * ****** * * *** = b;
* ** **** ** **** ** ** * * ** * = c;
* * * * * ***** *** * * **

* *** * ** * *** *** * * * /= a;
*** *** * ** ********* /= a;
**** * * * *** * ** *** * ** * * *** *
*** * * *** ***** * * ** ** ** ** ** **** * * ** **
** * ** * ****** * ** *
** ** *** * * ** **** **
** * * ** * **** * ** * *** ** ***** * frac1, frac2);


* * ** * ** * * * ** * 0;

}
answered by (-167 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include ** * ***

int main (void)



{


** * * * * * ** ***** * * * *


* ** ** * ****** ****** **** *** ** ** * ** *** *


** * * *** ** ******* (a=1; a <=num * ** * a <= denom; ++a)
* *** *** * **** * * *

* * * *** ** * ** * ** * * ***** * * * **** ** (num%a ==0 && denom%a==0)
* * * ** * * *** ******* ** * * * * * ** * *
***** * ** ** ** * ** * * * *

* * * *** * * * ** * * * = num/GCD ;

* * ** * * * * * * * ** denom/GCD;
* * * *** * *** ** * (num%denom==0 ){

** * * *** * * ** ****** * ******* *
}
* * * * ** *** ** * *
* *** * *** ** ** * **** * ** ** ***** * **** ********** ** *
}



* ***** ** * 0;
}
answered by (-107 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(void)
{
*** ** ** * * * **** * frac1;
*** ** **** * ***** * ** * frac2;
** * ********* ** gcd;

*** *** * ** * * ** * a;
** * **** ** * * ** b;
* ** * * * * * ** ** * c;

* * *** ** ***** ***** * * *** * ** &frac1, &frac2);
** **** ** ** ** *** * = frac1;
    b = frac2;

* * * ** * * ** * * 0)
* * * * ** ** ***********
** *** * * * *** * * ********* *** * **** * ** * = a % b;
** ** * ** *** * *** * ** *** * * * * = b;
*** ** * ** * * *** * * ** * * * = c;
** ** ** ** ** *

* ** * ** **** ****** * /= a;
*** ** * * *** * ***** /= a;
* * ** ******* ** **** ** * * *
*** ** * *** ** * ** *** ** **** ** * **
* *** * * *****
* * *** ** * ****** *
* * ** * *** **** * * *** *** *** * * frac1, frac2);


* *** ** ** * * * ** *** * 0;

}
answered by (-167 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main()
{
* * * ** * * * * *** a,b,i;
* * ** ** ** *** ** * ***** * ****** *** **
* * ** * ** * ** * * * * % b == 0)
* * * ****** ** ** * * * * * ** * ** * * * *** ** * ** * ***
* *** * * ** *****
*** * * * ** * *** = 1;i <= a;i++)
* ***** * * * *
** * * ** * * * * * ** ****** **** *** * * % i ==0&&b % i ==0)
* *** * ** ** ** * ** ** * ** *** **
*** * ** * * ** ** * *** *** * * * * * * **** * * ** = a/i,b = b/i;
** * **** *** * ** *** **** ****** * ** * ** ****
    }
** ** ******* ** **** * * * *** ** * *** * ** *** *** ** *** ** * *
** ** * **** * **** * * ** * ** * ****

*** *** ** *** *** ******* * 0;
}
answered by (-255 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main()

{
* * ** * * *** ** * a,b,i;
* * ** * * **** **** ** **** * * **** * ** *

* ** ** **** *** ***
* * ** ** * ** * ******* ***** *** *** *** * **** ** ** *
** ** ** * **** * **
***** * * * ** *** * * * * ****
    {
*** * * *** ** * *** * ** ****** ** * * * * && b%i==0)
* ** *** ***** *** ** **** ** * ** **** ** *
*** ** ** ** ** ********* *** * * ** * * ** * * ** **** **** * *
* ** * *** ** * * ** * ** ** *** * ** * *
* * * *** ** ** ******** ***
* ** ***** ** * * ** ** * ** * * * ** * * * * **** * *
    }
** **** ** * * ** ** ** 0;
}
answered by (-127 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include ** *** * ***

int main (void)



{


*** ** * ** * ** ****** ** * * * ** ******


* ** * ** *** * * *** *** ***** ** *****


** ** * * **** *** * (a=1; a <=num * *** **** a <= denom; ++a)
**** ** * **** * *

* ** * ***** ** ** * * * * *** * * (num%a ==0 * ***** denom%a==0)
* * * ** * ***** **** * ** *** * * * ***
** * ***** **** ** *** *

*** **** * * * ***** * * = num/GCD ;

***** * * * * ******* * * denom/GCD;

* ** ** *** ** **** * ** * ** **** ***** * ** *** ****




* ** ** * ** 0;
}
answered by (-107 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
Case 3: Correct output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
* ** * * * ** *
** n, int m)
{
* * * int *** * *
* * ** **** * ** ** * ** * (n != 0)
** ** * * {
* ** ** *** * **** = m % n;
* * * * ** ** * ** m = n;
* **** * *** ** * n = * *
* * * ** * }

* ** * gcd = m;

** * ** * * ***** gcd;
}
* * ** (int * ** char * * * {

* * *** * *** int * * **
* * * ** * ** int * * * **


* ****
* ** ** ** *** ** ** * ** ***** * ** ** * ** *


* ** ** * ** ** = **** / * * ** *****
* ** ** ** * = * * / * **** * ** **


** * *** * * * * **** **** * ** ** *
}
answered by (-140 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
Case 3: Correct output
Case 4: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.254.18
©2016-2024

Related questions

0 like 0 dislike
71 answers
[Exercise] Coding (C) - asked Nov 9, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 31047 - Available when: 2017-11-09 18:00 - Due to: Unlimited
| 5.5k views
0 like 0 dislike
72 answers
[Exercise] Coding (C) - asked Nov 2, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 29831 - Available when: 2017-11-02 18:00 - Due to: Unlimited
| 5.2k views
1 like 1 dislike
85 answers
[Exercise] Coding (C) - asked Oct 26, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 28914 - Available when: 2017-10-26 18:00 - Due to: Unlimited
| 6.4k views
0 like 0 dislike
69 answers
[Exercise] Coding (C) - asked Oct 26, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 28913 - Available when: 2017-10-26 18:00 - Due to: Unlimited
| 5k views
12,783 questions
183,443 answers
172,219 comments
4,824 users