0 like 0 dislike
6.4k views

Write a program that asks the user to enter two integers, then calculates and displays their greatest common divisor (GCD).

寫一個輸入兩個整數 輸出它們的最大公因數程式

Hint: Use Euclidean Algorithm

使用歐幾里得演算法

Example input: 

12 28

Example output:

4

 

[Exercise] Coding (C) - asked in Chapter 6: Loops by (5.2k points)
ID: 28913 - Available when: 2017-10-26 18:00 - Due to: Unlimited

edited by | 6.4k views

69 Answers

0 like 0 dislike
Hidden content!
*** * * **** **
int main (void)
{
int a,b,c;
** **** * * * * **
* *** * **** * ** * *
while ( a % b != 0){
****** ***** ** ** *** *
* * **** ** **** **** * ***
** * ** * * * * *
}
**** ***
** * 0;
}
answered by (5.2k points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#define swap(a,b) { a^=b, b^=a, a^=b; }
int main(){
* *** **** **** a,b;
** ******* **** GCD;
* * * ** **** * * *** ****** * %d",&a,&b);
** *** **** * * *** * * ***** swap(a,b);
** * *** *** ** * * *
* ** *** ***** * * ** * ** ***** **** * *** * ** ******** ** b:a);
* * ** * * * ** * * *** **** * * * 0;
    }
* *** * * * * ** * * ** ** * *
* * * * * **** ** * **** ** ** **** **** ** *
*** * * *** *** *** ** * * * ** * * * * ** **
** ** * ** * *** * *** **** * *** ** **
** **** * * * **** *
* *** ***** * *** ** ** * *** ** *
** ** * ******* ****** * ** 0;
}
answered by (-116 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main (void)
{
**** * * ** ** **** a,b,i;
* * *** ** * * *** * ** ** **** *** ** * * ***
   if (b>=a)
   {
** ** ** ** * ** * *** ** **** ****** *
** *** **** **** * ****** * * ** ******* ** * /*|| (a%i==0 && b%i==0)*/ )
*** * ** **** * ** *
* *** * ** * ** * ** * ** ** *** **** *** ** * (a%i==0 && b%i==0)
* * *** ** * ** * ** * * * * * **
**** * *** * ** * * * *** * ** ** * * * * *** * * * *** *** * ********** **** *** *
** ***** * *** * * * *** * * * ** ** * ** ***** * ** * * ** *** *** *
* * * *** ** ***** ****** ** * ** * ***** ****** * **
* *** * * ****** * ** **** * **** *** * *** ** *
* * ******* * *
   }
   else
***** * * * *
* * **** ** * ** * ** ** * * * *** ** ** *** * ** *** /*|| (a%i==0 && b%i==0)*/)
* * * * * ** * * ***
*** *** * ** * * * * **** ***** * * ** * * (a%i==0 && b%i==0)
* *** * ** * * * ** * * * ** ** ********* * * *
* ** * ** *** ** *** ** ** * * ** * * * * **** *** *** ** ** * * *** **
* * * ** ** * * **** * * * * ** * ** **** ** ** * ** *
* * *** * *** ** * * ** **** *** ** * * * * *
** * * * * * * ** * * ***** * * * * * *
* * * ** * * * * ***
   }

* * * ***** ** ** * * * * ** * ***** printf("the GDC doesn't exist");
* * * *** * ** ***** 0;
}
answered by (-168 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#define swap(a,b) { a^=b, b^=a, a^=b; }
int main(){
* * * * ** a,b;
** *** *** *** * * * ** GCD;
* * *** * ** ** * *** ***** * *** %d",&a,&b);
**** *** * *** * *** *** * * swap(a,b);
** * *** ** * * * * ** * ** ****
* * ** ** ******** * * ** *** **** * ***
** * * * *** ******* ** * * * ** * * * ** * *
* ** * * **** * ** * * * * * * ***** ***
** ** * ** * * *
**** * ** * ** ***** * * ** * * ** * * *
* *** * **** * *** 0;
}
answered by (-116 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main (void)
{
** * *** * * * * a,b,c;
* *** ** * ** **** * ** ("%d %d",&a,&b);
** * * ****** *** ** * (a%b!=0){
******* *** **** * **** * * ***** * ** * **
* ** ** * * * ** * ** ** ** * * *** ****
* ** **** * ** ** * ** * *** * **
* *** **** * ******
* ** ** * ** * * * * * * ** ** * * *****
** ** * **** ** ****** * **** 0;
}
answered by (-204 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main()
{
* * * * ****** ** ** a = 0;

**** ** *** * ** * ** * b = 0;

* * * *** * temp = 0;

*** * * * * * ** * * ***** ****** ** * * * &a, &b);

** * ***** ** * * *** a > b && a % b != 0)
**** **** * **** ** *
* ** ***** * * * *** ** * * * * = a % b;

* ** * * *** *** * * **** * ** * * **** * * ****** = b;

* * *** * * * ** **** ** * ********* = temp;
***** * *** * *

* * ** * *** * * ** * * a > b )
* * ** ** * * * ** * * **
** * * ** **** * * * ** ** ** *** * * * * * *** * * * ** b);
**** ** *** *** * **** **

* ** * * * ***** ** ** a < b && b % a != 0)
*** *** * * ** **
** * * * * * * * *** *** *** * *** * * ** * = b % a;

** ** ***** * ** ** ** * * * * *** ** = a;

*** * * * *** * ** * * ** **** * * *** ** * = temp;
****** *** ** ***

*** * **** *** ** ****** **** * a < b )
*** *** ** * * ****
** *** * * * * ** * * *** * ** **** *** ** * a);
* *** * * * ** *** *
}
answered by (-285 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main(){
** * * * * * * * * i;
** * * *** * ** sum=0,counter=0;
** ** ** ** ** * * *** * * ** *** * * ***** * *
* **** * * * * * * {
** ** **** * * ** * * **** *** ** * * ** ** * *
* * * * * ** *** * *** * **** ** *** * i%10;
* * * * ** ** * ** * * * * * * * ****** ** ** ****
**** * * *** * * ******** **** * **

* ********* **** * *** * * * *** ***** %d",counter,sum);
** * * * * * ** * * ***** ** 0;
}
answered by (-116 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main()
{
* * * * * *** * * * a,b,i,max;
** ** ** * * * ** * ** * * * ** %d",&a,&b);
* *** * * * ** *** * * * *** ** **** * * * ***** * *
* *** * * * ** ***** *** *
* ** * * ** * *** * * * * * * * * ***** * ** *** * ** * *
* * * * * *** ** ** ** ** ** ** ** * * *** * *
* * *** ** ** **
* ******** * ***** * **** * * ******** *
* *** * *** ** ** * ***** 0;
}
answered by (-108 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,y,i;
* *** ** * ** ** ** ** ** **** %d",&x,&y);
* ** * * *** * * * ** **
**** *** * *** ** *** * **** ** * ** **** * * *
* ** * **** **** *** * * * ** * * ** ***** * ** (;;y=i%y){
** * ****** * *** *** * ** *** * **** * ***** *
* * *** ** *** * ** * ** ** **** * * ** *** * * ** * *
** * * ** * ****** **** **
* * * * * ** *** ** ***** ** *** * * * ****
* ** ***** **** ** ** *** *** *** ** * ** ** ** (;;x=i%x){
** ** * ** * ***** **** * * * ** * * * * ****** ***
* * * * * * ****** * *** *** * *** *** ** **** * * * ** *** * ** *
* * *** * * *** ** **** *** **** 0;
}
answered by (-498 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main()
{
* *** * ** * ** * ** a = 0;

*** * * * * **** * * b = 0;

** * ** ****** * * * * *** temp = 0;

***** ***** * * * ** ** ** ** ** * &a, &b);

*** * ** * * * * * *** * a > b && a % b != 0)
* * ** ** *** * * * *
** * * * *** ** **** * * **** * ** ** * ** * = a % b;

* ** *** * ** * ** ** * ********** * = b;

** * ** *** ** **** * ** ** * ** * ** * = temp;
** **** *** ** *** ***

**** * * * * * a > b )
* * * ** * * ** * * * *
* ** ** *** * * ** * *** ** ** ** * * * * * ** ** * ******* ** b);
* * * ** * **** * ******

** * * *** * ***** * a < b && b % a != 0)
* * ** * * ** * ***
****** ** ** * ** ** ** * ***** *** * * * *** = b % a;

** * **** * * * *** * * * * ** *** * = a;

* * * ** *** * * *** * ** ** *** ** **** * = temp;
* * ****** **** *

* * * ** ** * * ****** a < b )
****** **** * * **
* ** *** ** * ** * * *** ******* * *** * **** * ** * ** a);
** * *** * * * ** ** * *
}
answered by (-285 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.131.143
©2016-2025

Related questions

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
| 8.1k views
0 like 0 dislike
10 answers
[Exam] asked Dec 9, 2017 in Midterm by thopd (12.1k points)
ID: 36752 - Available when: 2017-11-15 14:10 - Due to: Unlimited
| 1.4k views
1 like 1 dislike
36 answers
[Exam] asked Nov 15, 2017 in Midterm by thopd (12.1k points)
ID: 32707 - Available when: 2017-11-15 14:10 - Due to: Unlimited
| 3.5k views
12,783 questions
183,443 answers
172,219 comments
4,824 users