0 like 0 dislike

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)
Available when: 2017-10-26 18:00 - Due to: Unlimited

edited by | 206 views

69 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{

** ** * * ** * n,n2;
* * ** **** ** *** *** i;
* ** * * * * * ** * min,gcd;

** * *** *** * * ** * * ***** ** * &n,&n2);

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

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

* ** ***** ** * * * * * i=1;i<=min;i++)
    {
* *** ***** * ** ** *** * ** * ***** * * * **** *
*** ** ** * * * *** * * **
* * * * ** * * * * *** * ***** **** ** ** ** ** **** * ****
* ** *** ** **** *
* **** ** * *** * * * ****

* * ** * * ** ** * * * * * ** ** * ** gcd);
return 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()
{
**** ** * n,j,i,gcd;
*** * **** * * ***** ** * * * * ** ** *
* * * ** ** * *** *** * ** ** * *** *
  {
** ******* *** * * * *** * * ** ** **** * * ** * * * ******
** **** **** * ** ** * ** * ** *** * ** * **
  }
* * *** ** * *** ** ** * ** *
* *** * * * ** * ***** 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>

int main()
{
 int a,b;
 int m;
*** ** *** * *** * * * * *** * * * *** *
** ** * * **** * *** * * ** * * ** *** * * * * ** *** **** * *
* ****** ** ** ** **** * *
    {
* * ******* ** ** * ** * * ** * *
** ** ** * ***** * * *** ** * *
* ** * ** * ** * ** * * *** * * * * * * *

*** * *** **** ** *** *
* *** * ** * ** * * * % b == 0)
*** ** ** * * * *** ** ** * **** ** * * **** ** ** * * **** * ***

* * * * * ** * * **** * * *** * * *** * ** * ** 0;
}
answered by (-32 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong 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 * **** * * * *

int main()
{
* * ** * * * ** * * ** * n1, n2, i, gcd;

* * ***** * * * ** *** * ** ** * *** *** &n1, &n2);

* *** * * *** * ** * *** i <= n1 * * **** i <= n2; ++i)
* *** **** * *** * **
* ** **** ** *** * *** * ** ****** *** * * ** * * ** ** ** * * n2%i==0)
** ** * * * ** *** *** * * ** *** *** *** **** * * * * * * * = i;
**** * * ** *** * ** *

** * ****** *** ** ** * * * * ** * gcd);
* * * * *** * **** ** 0;
}
answered by (-254 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 ****** *** *
#include * * * * *****

int main()
{
** ** * * * n1, n2, i, gcd;

* ****** * * ** ** ***** &n1, &n2);

* * * **** * ** ****** * i <= n1 * * * i <= n2; ++i)
* ** *** * ***** * *
* * * * ** *** * *** ** * * ** *** ** * * * * ** * n2%i==0)
* * ** ** * ** * * * **** * * * ** * ** * ** *** * * * *** *** = i;
**** * *** ** * * *** *

** * *** *** * * * ** * *** gcd);
* ** * *** * * * ** * ** 0;
}
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!
* * *** *** **
* ** *
int * *
{
int **
* * * ** ** *
* * *
{
* **
a=b;
b=r;
}

** *** ***** **
}
answered by (-214 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,smaller,i;

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

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

* * ** * ** ** * ** ** *** * * *** ****
**** * ** ** ** *** * ***** ** * * * * && b%i==0)
* ***** **** * ** ** * * ** *** *** ***** * **

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

* * ** ** * *** *** ** 0;
}
answered by (-16 points)
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 <stdio.h>
int main()
{
**** ** ** ** * * * a,b,n;
** ** * * * * ***** *** * * **** * ** ** * * *
* ** * * * * * **** *** (n=a-1;n>1;n--)
***** * * * *** * *
* * ******* ** * * * ***** * **** * ** * && b%n==0)
** * * *** *** * *** *** ***** * *** ** ** * * **
* ** * * ***** ** ** ** *
* ** ** * **** * * * * *** *** ***
** **** * **** * ** * **** * 0;
}
answered by (-279 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,n,a,b;
*** * * * ** ****** ** *** ** * * %2d",&x,&y);

    for (n=x-1;n<x;n--)
    {
* * * * ****** **** ****** ** **** * *** ** *
*** ** * * ** ** ** * * * * * ** ****** (a==0)
* ** ** * **** ** ** **** * ** ** ** *
* ** ** ** * * *** * ** * * ** * * * ** *** * *** * * ** ***** **
*** * *** * ****** **** * ** * * *** ** ** * * ** ** * * ** (b==0)
** *** * ****** ****** * * * * * *** *** * * ** * ** ********
* *** * * ** * ** * ** ** * ** **** ******* ***** * **** * ** * * * * * * * ** *
** * * * * * * *** * ** * * ** *** * ** ** *** **** *** ***** * * *** ***
* * * *** * ********* * ** *** * * *** *
    }
* * ** * * * * ***** * ** ***
* *** *** *** * ******* *** 0;

}
answered by (-249 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 main()
{

**** ** * ** * ** n,n2;
* * * ** ** ** *** * **** i;
*** *** **** *** ** *** * min,gcd;

*** **** * *** * * *** ** * *** * * * &n,&n2);

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

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

*** * * * ** *** **** * ** * i=1;i<=min;i++)
    {
** * ******** *** ** *** *** * ** * * *** * * *
* * * * * **** ** * ** * ** * ** ****
********** * * * * *** **** * ** ** * *** ** ** * * ***
* * ** * * * * **** * *** ****** * ****
    }

* * * *** ** * **** * * * ** ******* * gcd);

*** ** * * * ***** ** ** 0;
   }
answered by (-167 points)
0 0
prog.c: In function 'main':
prog.c:8:5: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
     scanf("%d%d", &n,&n2);
     ^~~~~
prog.c:8:5: warning: incompatible implicit declaration of built-in function 'scanf'
prog.c:8:5: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c:27:5: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
     printf("%d", gcd);
     ^~~~~~
prog.c:27:5: warning: incompatible implicit declaration of built-in function 'printf'
prog.c:27:5: note: include '<stdio.h>' or provide a declaration of 'printf'
Get it on Google Play Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.62.22
©2016-2019

Related questions

1 like 1 dislike
85 answers
[Exercise] Coding (C) - asked Oct 26, 2017 in Chapter 6: Loops by semicolon (5.2k points)
Available when: 2017-10-26 18:00 - Due to: Unlimited
| 183 views
0 like 0 dislike
10 answers
[Exam] asked Dec 9, 2017 in Midterm by thopd (11.3k points)
Available when: 2017-11-15 14:10 - Due to: Unlimited
| 64 views
1 like 1 dislike
36 answers
[Exam] asked Nov 15, 2017 in Midterm by thopd (11.3k points)
Available when: 2017-11-15 14:10 - Due to: Unlimited
| 61 views
9,252 questions
85,577 answers
63,644 comments
2,713 users