2 thích 0 k thích
4.9k đã xem

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) - đã hỏi trong Chapter 6: Loops bởi (5.2k điểm)
ID: 31048 - Xem được từ: 2017-11-09 18:00 - Hiệu lực đến: Không giới hạn

đã sửa bởi | 4.9k đã xem

67 Trả lời

0 thích 0 k thích
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;
}
trả lời bởi (-140 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 thích 0 k thích
Hidden content!
#include <stdlib.h>
#include <stdio.h>

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

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

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

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

    }




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

}
trả lời bởi (-16 điểm)
đã sửa bởi
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 thích 0 k thích
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);

** *** * *** ** * ** **** * * *** *** * ****
** ** * * * * **** ** ** ** * **** *** * *
******** * *** *** **** ****
* * * * ** * ** ** ** * ** ** * ** *
}
trả lời bởi (-108 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 thích 0 k thích
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
* ** *** ** *** ** ** * ** * ** ** * * **** *
}
trả lời bởi (-168 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 thích 0 k thích
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;
}
trả lời bởi (-284 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 thích 0 k thích
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;
}
trả lời bởi (-193 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 thích 0 k thích
Hidden content!
#include<stdio.h>
int main()
{
    int n,m,i,gcd;
** * ** * ** *** * * * * * * *** * ** * *** ** ***** *
** * ** * *** * ** * * ** ** * * ** * * *
    {
*** ** ** *** ** * * * * * ***** ** ** * * **
* **** ** * * * * ** * *** * * * ** ***** **
******* * * * ** ** * *****
* * * * ** ***** * *** * * * * * *****
* ** ** * *** * * ** * * * * *

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


return 0;
}
trả lời bởi (-32 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 thích 0 k thích
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);
* * * * *** * ** *
trả lời bởi (-32 điểm)
đã sửa bởi
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 thích 0 k thích
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);
}
trả lời bởi (323 điểm)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 thích 0 k thích
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main()
{
*** * *** a,b,c,d,e,f;
** *** * *** ** * *** * * **** * * * * ***** * ***** *
* *** * * ****** **
*** * ** * *** * *
** *** ** * * ** * ** **
    {
* * ** * ** ** * *** * **** * * ** * * * **
** * * * * ** * ***** * * *** * * * * *** ***
* ** * * ** ** * * ** * * ** * ** *** ** * * * * *
    }
** *** **** * ** ** *** **
    {
* * * * ** * * ** * * ** * ** * * * ***** *** *
* ** * * ***** * * ** * * * * * ******** * * * * * ** * ** **
* * **** * * * *** * ** ** * * * * **
* * * **** ** ******** * * * * * ** * * ** * * *** *** * ** **
    }
* * ** * ** * * * *
    {
* * *** ***** **** *** ** * * * **** * * * *** **
*** * * * ***** * ** * * ** ** ***** *** ***** * * ** * *
* ** * * *** * *** ** * * * * **
** ** * * * * *** *** * ** * * ** *** ******* ** * ** ** * ** *
    }
* * * ** * *** * * * ** * 0;
}
trả lời bởi (-498 điểm)
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.70.178.161
©2016-2024

Những câu hỏi liên quan

0 thích 0 k thích
71 trả lời
[Exercise] Coding (C) - đã hỏi ngày 9 tháng 11 năm 2017 trong Chapter 6: Loops bởi semicolon (5.2k điểm)
ID: 31047 - Xem được từ: 2017-11-09 18:00 - Hiệu lực đến: Không giới hạn
| 5.5k đã xem
0 thích 0 k thích
72 trả lời
[Exercise] Coding (C) - đã hỏi ngày 2 tháng 11 năm 2017 trong Chapter 6: Loops bởi semicolon (5.2k điểm)
ID: 29831 - Xem được từ: 2017-11-02 18:00 - Hiệu lực đến: Không giới hạn
| 5.2k đã xem
1 thích 1 không thích
85 trả lời
[Exercise] Coding (C) - đã hỏi ngày 26 tháng 10 năm 2017 trong Chapter 6: Loops bởi semicolon (5.2k điểm)
ID: 28914 - Xem được từ: 2017-10-26 18:00 - Hiệu lực đến: Không giới hạn
| 6.4k đã xem
0 thích 0 k thích
69 trả lời
[Exercise] Coding (C) - đã hỏi ngày 26 tháng 10 năm 2017 trong Chapter 6: Loops bởi semicolon (5.2k điểm)
ID: 28913 - Xem được từ: 2017-10-26 18:00 - Hiệu lực đến: Không giới hạn
| 4.9k đã xem
12,783 câu hỏi
183,443 trả lời
172,219 bình luận
4,824 thành viên