2 like 0 dislike
17.3k 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 | 17.3k views

67 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>
int main(void)
{
    int a=0,b=0,c=0,b1,a1;
***** *** * * * ** * * ** ***** *** ** * **
* ** * ***** ** *** **
* ** ** * * * ** * * * *
* * * ** * *** ***
    if (a>b && a%b==0)
*** * **** ****** * * ****** * * * **
** *** * * *** * ** * * ** **** ***** * *** * * *****
* *** ** ***** * * * *
    {


* * * * *** * * * ** * ** ** * * *** (a%b!=0){
*** * **** * *** * * *** ** * ***** * *** **** ** * * ** **
*** *** ** ** * * ** ** ** * **** * *** * ** ** ** *** ** *
* * ***** * * ** ** ** *** * * * * * **** * * * *** *** * **
* * ** * ** ** * * * **** ** * * * *

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

* ** * * * * *** * *** **** * *** * *** * * *** * ***
    }
return 0;
}
answered by (-329 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>
main(void)
{
    int a=0,b=0,c=0,b1,a1;
** *** * * *** * * * * *** * * *** * ** *
*** * * ** ** ** * * * ****
* *** * **** ***** ** *
* * ** ** ** ** * * *
    if (a>b && a%b==0)
** * * ** * * ** * ** ** ****** ** ** **
** * **** * ** * * ** * ** * * * **** ***** * **** * * **
** * ***** ***** * *** *
    {


* * ** * *** * **** * ** * *** **** * (a%b!=0){
* ** ** * * *** **** **** *** * *** ** ** * * **** **** * ** *
* ** ***** ****** * * * **** * * * * **** **** * ** ******* *
***** *** ** ** * ** **** ** ** * ** ** ** *** ** * ** *** * * *
**** * * ***** * ** *** ** ** *** * ** * ***

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

* * * ** ***** * *** ***** ** *** **** ** ** * *** *** ** * ****
    }
return 0;
}
answered by (-329 points)
0 0
prog.c:2:1: warning: return type defaults to 'int' [-Wimplicit-int]
 main(void)
 ^~~~
0 like 0 dislike
Hidden content!
#include<stdio.h>
#define swap(a,b) { a^=b, b^=a, a^=b; }
int main(){
    int g1,g2;
** * ** * * * ** * *** * * * * * * / %d",&g1,&g2);
* ** *** *** * * * **** ** **
* *** ** * ** * ***** *** ** * ***** ** *** * ** * ** * * *
    }
* ******* * ***** *
****** * * * *** *** * ** ** ** ***** GCD;
* * * *** * *** ** ******** * ***** ** a=g1,b=g2;
** **** * ***** *** * * * * * * ***** * * ** * * swap(a,b);
** ** * * ** * * * * * ***** * ** * ** * **** *
* * ** ** * ** ** * * ** * * ** * **** *** *** ** *** * * * * * ** = a>b? b:a;
* **** ** * * *** * ** * * * * *** *** *
** * ** * * ** * * * **** * ** *** ** *
** * * ** *** ** * *** *** * * * * * ****** * ** * *** ** * ** ***** ***
* * * ** * * * ** * * * * ** ** * ***** * ** *
** * ** *** *** * ** *** *** * * * * * ** * * **** *** * ** ***
** ** * * *** * * *** ****** ** * ** *** **
* ** **** ** * **** * *** *** * *** * ** ** * * * *** * * *
    }


* ** *** ** * * *** 0;
}
answered by (-116 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()
{
    int n1,n2,num,denom,i=1;
* ** * ** * * * *** ** * **** *** *** ***** * * *
    while (num !=0 && denom !=0)
        {
        i++;
        num = n1/i;
        denom = n2/i;

***** *** ** *** ***** * ** **** * ** ***** ***** ** *** * ** * (n1%i ==0 && n2%i == 0)
** * * * * * ** ** ** ** ** * * ** ** * *** ** ** * ** * *
* * * * ** *** * * **** * *** *** *** * ** * **** **** ** * ** *** ** ** * || denom==1)
** * * *** ** * ** * * ****** * * *** * **** * * ** * ***** * * *** ** * * *
**** * ** * ***** ** * * ****** ** *** * * ** ** **** *** * * * * * * * * * * * * ******* *** * * * *** *** *
* ***** ***** * ****** ** * * ** * * * * * * * ****** * * ***** **** * *** ** *** * ** *
* * * * ** * *** ** ** * ** *** * *** * *** * * **** * *** *** ** * ** *** ** * * * *** * ***** * *** ** ** **** **
***** *** *** **** * * * ** * ** * ** **** ** *** ** * ** * * ** * ** **** ***** * **** * *
* * * * * * *** ** * ** **** ** * * * ** * ** ****** ****** *** ** ** * ** ** * ** ***** ****** ******* * ** ** ** ** *
* * **** ***** **** * *** ** * ** * * * * ** * * ** * ** ** ******* ** * * * * ** * * * * * *** ***
* **** * ** *** * * * ***** * ***** * * ** * * ** ****** **** ** * ****** * * *** *** * * ****** * ****** * * * * ** ***** *** **
* ** * ** ** ******* ** * * *** ** *** * * * ** * * * *** * * * ******* **** * *** * * * * **** ** **** ** ***** * **
***** **** * * *** ** * * ** * *** * **** * ** ** ** * * *** * * * ** ** * **
* ** * * ****** *** * **** ** * ** * ** ** ** * ** *** *****
** **** * * **** *** ** * *** *** * * **** * * ** *** *
**** * * ** * * **** ** * * ** * * ****** ** ** * * *
* * * ** * * * * *** ** * * ** ** * * ** *** * ***** **** ***** ** * * * ****** * ******** ** *
* * * * * * *** ** ** * *** ** * ** * * * * ***** *** * ******
        }
 return 0;
}
answered by (-323 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Wrong output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

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

int main()
{
    int a,b,c,d;
* *** * * * *** ** * ********* * * * * * ** ** * ** **
    if(a>b)
    {
***** * ***** * ***** * ** *** *** * ***** * *
*** * **** ** * * **** ** * * ** ****** **
* *** **** * * ** ** *** * * * *** ** ** * * * *** ** **** ** ** *** ** * **
*** * ** * * * ** ** **** * * * * *** * *** * *** ** * * * ** * * * * *
* * *** * * ****** ***** **** * *** *** * ** *** *** ** * * * *** ** * ** ** ** ** ** *** ** ** **
** * * *** ** ** * **** * ** * ** **** * * * * *** * *** ***
* * * * * * **** * * * **** ** *** * ***** * * * *** * ** **
*** **** ******* * * ** ** *** * * * * *
    }
    else
    {
* * * *** * ****** * * * * *** ** *** * *
**** ** * * * * * * *** ****** ** *** ** * ***
** *** ** * ****** ** *** * ** * * * * ******* * * * ***** *****
* ** ** * * ***** * ***** ** * * *** *** * **** **** * ** * * *
** * *** **** * * * *** * * * ***** ***** *** * *** * * ** * ** ** ***** * * ** *** * * ** ** * ** *
*** * **** **** ******* ** * * ****** *** * * ** *** * *** *** * ** ** * ** **
* ** ***** * * * ** *** ** ** ** ** * * * * *** ** *
**** **** ** * ** * **** * ** * * *
    }
    return 0;
}
answered by (-498 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Wrong output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
* * ** ******* * ** nom,denom,i,a;
* * * **** * * * ** ***** %d", &nom, &denom);
****** * * ******* ***** i<=denom; ++i)
    {
** * ** ** ** * * ** *** *** * **** * ** ** **** **
* * *** ** * ** **** * * ****** * ** * * *** ** ** **** && denom%i==0)
* ******* * *** **** *** **** *** *** * * *
* * *** * * *** * * * * * ** ****** ******* * *** * **** = nom/i;
* * * * ** ** * ** * * *** * * * * *** * ** * * * * * * * * * = denom/i;
*** * * * *** **** **** * * ** *** * ** ** * * *
** *** ** ** ** ** ** *** ** * * * * ** *** * * ** ** **** *** * * * *** * ****
* * * * **** ** * **** ** ** ** **** *** ** * * * ** *** ** * * *
*** *** *** ***** ** * * ** ** * ***** ** ** * * ** * * * ** * *** ** ** ** **** *
**** ***** * * * ***** ** **** * * ***
    }
* ** * ** *** ** * * 0;
}
answered by (-281 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
****** ** ** * * ** * ** * nom,denom,i,a;
*** ** * **** ** *** ******* %d", &nom, &denom);
**** ** ** * ***** ** * ** i<=denom; ++i)
    {
* **** ** * ** * * * * * ** ** ** *** **** *** * * *
* * * ** * * ** * ** ** *** * **** * * && denom%i==0)
****** ** * * * *** * * ** **** *** ** **
* *** * ****** ** * ** * * * * ** * **** **** ** * *** * = nom/i/3;
**** * * * ** * ** * **** ****** *** * * * *** ***** = denom/i/3;
**** * ** ***** * ** * ** * * ** ** *** * * ** * ** * ** * ****
****** * * * * * * *** * * ** * ** * *** * * * * *** ** *** **
*** ** ** * ** * * **** * ** ** * * * *** * ** * ****
** ** * * ** * ** ** * * **** * * ** ** * * ** * ** * * ** * * ** ******** * * * * * *
** * **** *** **** ** * ** **** **
    }
*** **** *** * * * * 0;
}
answered by (-281 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Correct output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
** *** * * * * * ** a,b,count,d,e,f;
* ******** ** ** * * ** x,y,z;
* ***** * * * ** *** ***** **** * * * ** ***
** * ** * ***** * *** ** * * ** * && count<=b;count++){
* ******* * * ****** *** * * ** * * * **** *
**** * *** ** ** ** ** ** * ***** * **
** * * * * * * ** *** * * * ** * * **** * * && e==0){
* * * * **** * ** ** ** * *** * ** * ** * * * **
* * **** * * * ** ** *** *** ********** * **** * *
    }
** * * ** * ** **
* * **** * ******* * *
**** * * *** * ******* **** % b == 0){
* ** *** ** ** * * * **** * * * * ** * ****** ** * a/b);
** ** *** * * ***
* ** * ** ** ** * *
**** *** *** * * *** ***** * * * ***** ** ** * * ** *
    }
* * ** ** * ******* **** 0;
}
answered by (54 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()

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

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

    if (num<denom)
    {
** ** ** **** * * * * ** **** ** * * (n;n<=num;n++)
** *** *** **** * * **** ** *
* * * * *** * *** ** *** * ** * * ** * * ***** * **
* * ***** * * ** ** **** ** ** * **** * ** * * * ** ******** ******* *
* ****** * **** ** * *** ** * * * * *** * * * ** * (flag==0 && n!=1 && bflag==0)
** *** * * ** * * * * * * * * * ******* ** ** ** * * * * ** * * * * *
* **** *** * * ** * * *** *** * * * ***
* * ** * * * ****** ** * * * *** * * ** = num/n;
** * * * * * ** * * * * *** * * ** = denom/n;
* ** *** * *** * * * * * ** ***** * * * **** ** * *** * **
    }
* * * * * * * *
    {
** ** * ****** * * *** ****** * ** *** (n;n<=denom;n++)
* ****** ** ** ***** * * *** * ** * * * **
* ** ** * * *** ** * *** * ** * ** * ** * * * *** * **** *
***** ** * **** * * ** * *** *** * * * * * * *** * *** * * **** * *** * (flag==0 && denom==n)
* * ** ** ** * ****** *** **** * *** **** * * ***** ****** * *** * ***** * * **
* ********* ** * ** * ** * * * * * *
* * ** ** * * ** * ****** * * ** ** * * /= n;
* * *** ** * * ***** *** * ** * * ** /= n;
* **** ***** ****** * ** **** ** *** *** * * * **** * * ** * * * ***
    }
* *** * *** ** * ** * * 0;


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

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
| 17.2k 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
| 16.9k 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
| 22.3k 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
| 16.9k views
12,783 questions
183,442 answers
172,219 comments
4,824 users