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

67 Answers

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

int main()
{

*** **** ** * * * ** * i;
** * * **** ** ** j;
* *** * ** *** * newNum1;
* * **** ** * * * ** newNum2;
** * * ** ** * ***** * gcd;
*** * * *** * ** * ** rem;
*** * **** *** ** ** * num1, num2;

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

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

* *** * *** * ** *** ***** *** != 0)
* * * * ** * **
** * ******** * ** * **** * * * * * * * *** * * = j%i;
* ** * ** * *** * * * *** ** **** ****** = i;
****** **** * ** ** ***** ** * ** * * ** * ** = rem;
* * * ** ** *
* ** * ** ***** **** *

* * * * * * ** ***** * * ***** ** = num1/gcd;
* * *** * *** * ** ** = num2/gcd;

* * ** * * ** ** **** * == 1)
    {
** ** * * *** * * * * * * * * * ***** ** ***** ** * *** ** * * * *
    }

* *** * * * * * * **
    {
* *** **** ** ***** ** *** **** ****** ** * **** ***** ** * * ** ** * * ***
* ** * * * *** ** * ** * * **

** ** * ** * * ** * ** 0;
}
answered by (-140 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 <stdlib.h>
#include <stdio.h>

int main()
{
    int num,deno,i;
* ** ** * * * * * * ***** * * * * * * * *** ** * ** **

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

    else{
* * * * * **** **** ** **
    {
** * * * ** ** ** * * * * ** ** *
* *** * ***** * * *** * ** ** ** ** ** ** **** ** * ***** * ** *** ** * && deno%i==0)
****** ** * * * * ** * * * *** * * *** ***** * * ** ** *
* * * ** ** **** * * ** * * * **** * *** ** *** *** ** ** *
* * * * * * **** * * * * **** * ** * * ** ***** *** ** ** ** * * * ** * * * *****
** ** * * *** * * ** **** ***** * * * ** * * * ** * **
    }

* ** ***** * ** * ** *** *
    {
*** ** * *** * *** ** * *** *****
*** *** ** * * * * * * * * ** * * * * ** ** * ** ** ** * *** * ** && deno%i==0)
** ** *** **** *** * ****** *** ** ** * *** ***** **** * ** * *****
* * * * * * * ** * * ***** * ***** * *** *** * * * * ** * * * ** * * *
** ** **** *** * * *** * ** * * **** *** ** * * ** * * * ***** ** * **** ********** *
** * ** *** *** ** * ** * ******** ** **** **** ** ** ***** ** * * *
    }
*** ** *** * **** * * ** ** * * * * ** *

    }




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

}
answered by (-16 points)
edited by
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct 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 ** * * ** *
#include * * ** * **

int gcd(int n, int m)
{
* *** * * **** * * * ****** * gcd, remainder;

**** * * * * * (n != 0)
** ***** * ** * ** ** *
** * ** ** * * * ****** *** * ** * ** ** = m % n;
** * * **** * **** * * * * *** *** = n;
* ****** * ***** * ** * * ** ** * ** * * ******** = remainder;
* * * * * ***** **

* * * ** ** * * = m;

**** ** ***** * gcd;
}

int main (int argc, const char * argv[]) {

* * ** * ** * * number1, number2;
** ***** * * *** newNumber1, newNumber2;

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

**** * ** *** *** ** * * * * * = number1 / * *** number2);
* **** * *** **** * ** * ** * = number2 / * * number2);

* * * **** * ** * ** * * *** * *
*** * ** * * ** ** ** * ******* * **** ***
* **** * * *** ** *** ** **
** *** ** **** ** ** ** ** ** * * *
}
answered by (-108 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!
*** * *****
**** ****** ** *

int * * n, int m)
{
******* ** * int gcd, ** *

* * * ** * ** (n != 0)
* *** *** * * {
*** * * *** ** ** * * = m % n;
* * *** * ** ** *** * m = n;
**** ** * ** * ** n = * ***
* * * **** ** }

* * * * * gcd = m;

**** * **** gcd;
}

int main (int ** * char * *** * {

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

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

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

** * * if ** * * *** * *
** **** ** ** * ** ** * **** ** ** * * * * *
* **** * * ** else
** * *** ** ** ** * ******** * * * ** * ** * * *
}
answered by (-168 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()
{
 
** ***** * * ** * * * ** i;
** * ***** * ** * * *** * ** j;
** ** ** ** * * * * ** newNum1;
** ** * ** * ** * ** * newNum2;
**** ** * ** * * * gcd;
* ******** ** * * ** rem;
* * * *** * * * **** * num1, num2;
    
* ** * * * ******** * * * * *** * * * * * * * **
* *** * **** * * * * **
* ** ** * * ***
* ** * * *** * * * *
* ** ** ** ** ** *
*** * * *** * ** ** * != 0)
** * * * * * *** * ***
* * * * ** ***** * * * ****** * * *** ** = j%i;
* * * **** * * * * * ** ** *** ** * * = i;
***** * **** * ** *** * *** ** ** ** * ** = rem;
** * ** * *** ** * **
*** ** *** ** * ** **
    
** *** **** ** * ** * * ** = num1/gcd;
* *** ** * * * * * *** * = num2/gcd;
    
** * * ***** ** * * * == 1)
** ** * ** ****** **** *
*** ** ** * ****** *** * ** * ** * *** *** * **** ***** * *
** * *** **** *
    
** ********** ** * *** * ***
** * * ** ***
***** * *** * * ** ** * ** * ** *** **** * **** ** * * *** *** * ***
** *** ** * ** * ***
    
** ** *** * *** *** * * 0;
}
answered by (-284 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()
{
 
* * ** * * ** *** * ** i;
** ** * * * ** * * * j;
*** * * * * * * * * *** newNum1;
*** ** * * * * * ** ** newNum2;
* ** *** * * ** gcd;
* *** * ** * rem;
** *** *** * ** ** ****** num1, num2;
    
* *** * * ** * * * *** ** ***** * * *** ***
** * *** *** **** *
* * ** ** ****
* *** * * * * *** * ***
** ** ** ** * * * * ***
* * * * * * ** * *** != 0)
* * ** ** * *** * *
* * ** * * ** *** * ******* ** ***** = j%i;
* **** * ** *** * * * ********* * * ** * * ** = i;
* * ** ** ** ** **** * ****** * ********* = rem;
* *** * * ** ** *
**** *** ** * * ** * * * **
    
** **** ** * * ** *** * = num1/gcd;
*** ** ** * *** ** ** **** = num2/gcd;
    
* * * * ** * * ** * ** * == 1)
* ** * * * * *** ****
* * * **** ** ** * ** **** ** * ** * ** * * * *** ** **** * * *
** *** * * * * *
    
* * ** * * * ** * ** **
* **** * * ** * ** *
* * ** *** ** * ** ** * * *** * * ** ** **** ** *** * * * *** * *
*** * **** ***** *** *** *
    
* ** ** ** * *** * * ** 0;
}
answered by (-193 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 n,m,i,gcd;
* * ****** *** ** *** **** **** * * * ***** * * **
** ** *** ** * ** ***** * ** *** * ** *
    {
* ** * * ** * * ** *** * * * * * *** *** * *
*** ** * *** * ** * * *** ** * * * ** * * * ** *** ***
* **** * ******** * * ** *
* ****** ** * ****** ** * ******* *
* ** ** * ******* ** * ******** * *** **

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


return 0;
}
answered by (-32 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 gcd(int,int);
int main(){
* * * ** * **** ***** ** a,b,GCD;
** ***** * * **** * * ** * *** ** * * ** ** ** *
* * **** * *** ****** ***
**** ** * **** *** ** ** *
* ** * ** * ** * ** * * ** ** * * * * ** ** * *** *** * * * *
* ** ****** * *** * ***
*** * * *** ** ***** ** ** * * **** * * ** * * **** *
** * ** ** * *** 0;
}
* * * * * * ** * ** * gcd(int a, int b){
* ** * ** * * ***** * *** * ** * * ***** ***** ** (!b) return (a);
** * ** *** * * * * ****** * *** ** * ** * * * ***** gcd(b, a % b);
* *** * * * *** *******
answered by (-32 points)
edited by
0 0
prog.c: In function 'main':
prog.c:6:1: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
 printf("\xe8\xab\x8b\xe8\xbc\xb8\xe5\x85\xa51\xe5\x80\x8b\xe5\x88\x86\xe6\x95\xb8\xef\xbc\x8c\xe5\xa6\x82:4/8\n");
 ^~~~~~
prog.c:6:1: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:6:1: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:7:1: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
 scanf("%d/%d",&a,&b);
 ^~~~~
prog.c:7:1: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:7:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
0 0
prog.c: In function 'main':
prog.c:7:1: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
 scanf("%d/%d",&a,&b);
 ^~~~~
prog.c:7:1: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:7:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c:9:1: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
 printf("%d/%d",a/GCD,b/GCD);
 ^~~~~~
prog.c:9:1: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:9:1: note: include '<stdio.h>' or provide a declaration of 'printf'
0 0
prog.c: In function 'main':
prog.c:7:1: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
 scanf("%d/%d",&a,&b);
 ^~~~~
prog.c:7:1: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:7:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c:9:1: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
 printf("%d/%d",a/GCD,b/GCD);
 ^~~~~~
prog.c:9:1: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:9:1: note: include '<stdio.h>' or provide a declaration of 'printf'
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: 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 ** ** * ** **
#include * ** * ** * *

//gcf function - return gcd of two numbers
int gcd(int n, int m)
{
* ***** * **** *** * ** gcd, remainder;
*** * ** ** * *
*** * * * * * ** * * (n != 0)
******* * * ** ** ** **
** * ** *** ****** * * *** * ***** ****** = m % n;
* ****** * ** ***** * * *** ** ** * * ****** * ** = n;
** ** * * * * **** * ** * * ** * * ** * ** = remainder;
** * * *** *** ** **
* ** ** *** * * *****
* ** **** * *** * ** = m;
* * * ** **** *
* **** * * ** * * ** * *** * gcd;
}
int main (int argc, const char * argv[]) {
*** ***** *** * * * number1, number2;
** ** ** * * * * * * * newNumber1, newNumber2;
* ** * ** **** ** * **
** * ***** ** *** *
**** * ** ** ** * ** ** ** * ** *** *** ** * * ***
* * ** * *
******* * ** **** * ** **** * = number1 / gcd(number1, number2);
* * * * ** *** *** *** = number2 / ** * * number2);
* **** ** *** *** ** ****
*** ** **** * * ** * * *
** ** ** * *** ** * ( ** ***
** ** * * * *** * ** * *** * * ** ** * ** ** *** * newNumber1);
* ***** * ****** ** * **
****** * *** **** * *
* * * ** * * * * *** * ** **** *** newNumber1, newNumber2);
}
answered by (323 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,c,d,e,f;
**** ** ** **** ** ***** ** **** ** *** ***
*** ** * * *** * * ** * *
*** * **** *** * *
* ** ******* ** ** * **
    {
* * * **** *** *** * *** *** * * * **
* **** * ** * *** *** * * * * * *** ****** **
* * ** * * ***** ** * ** ********** ** ** *
    }
* **** *** ** * ** * *** **
    {
** * ** * * * * ** * * ******* * * * * * *
* **** ** ** **** * * ** * * * **** * *** *** ** * * *** * ** **
**** ** *** **** * ** * * ***** * * *** * ** *** ** * ***
* ** * * * *** ** * * * * * **** ***** * * * * **** ***** * **
    }
* * ** ******* ** ******
    {
* * * * ***** *** * ** * * ** ** ***** * * ** * *****
* * * ** * *** * ** * ** * ** * * ************* * ** * * * ****
* * * * * * *** * ** * ** * ** *****
* * ** **** * * * ****** * *** **** ** * * * * *** ** * * *** *
    }
** * * ***** ** ** 0;
}
answered by (-498 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.120.164
©2016-2025

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
| 14.7k 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
| 14.5k 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
| 18.6k 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
| 14.3k views
12,783 questions
183,442 answers
172,219 comments
4,824 users