1 喜歡 1 不喜歡
4.3k 瀏覽

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

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

Hint: Use Euclidean Algorithm

使用歐幾里得演算法

LCM:

In arithmetic and number theory, the least common multiplelowest common multiple, or smallest common multiple of two integers a and b, usually denoted by LCM(ab), is the smallest positive integer that is divisible by both a and b.

What is the LCM of 4 and 6?

Multiples of 4 are:

4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, ...

and the multiples of 6 are:

6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, ...

Common multiples of 4 and 6 are simply the numbers that are in both lists:

12, 24, 36, 48, 60, 72, ....

So, from this list of the first few common multiples of the numbers 4 and 6, their least common multiple is 12.

 

Example input: 

12 28

Example output (first number is GCD, second number is LCM):

4 84

 

[考試] 最新提問 分類:Midterm | 用戶: (12.1k 分)
ID: 32707 - 從幾時開始: 2017-11-15 14:10 - 到幾時結束: 無限制

修改於 用戶: | 4.3k 瀏覽

36 個回答

0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>
#include * **** ** *

int main()
{
* * * * * * * * * * * a,b,i,gcd,lcm;
** * * ** * ** * ** * ** *** * * ******* ** ** * * *
** * * * * * ** ** *
** *** **** * * *
* ** * *** ** ** * ** * * **   * *** * * *
**** **** ******** ** ** * *   gcd=i;
**** *** ** *
** * ***** ** * ** * ** ** * *
** ***** * *****
** * * *** *** ***** *** * * * %d",gcd,lcm);
**** * * ** *** 0;
}
最新回答 用戶: (-258 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
int main (void)
{
* *** * * * * * * a,b,c,d;
* ** ** * *** *** * * * * * ** %d",&a,&b);
* * ** *** *** * ** ***
** * *** *** * ** * **
* **** * * ** * * * ** * * * && b>0){
* ***** *** ** * * * * * *
* * * *** * * * *** * * * * * **** * *
* ** * ** * *** ** *
** ** * * ** ** * *
** * * ***** *** * * * * * *** * * * = b%a;
* *** * * *** * * * *
** * *** *** * *
* ** * * * **** * ** a == 0 ) {
* * ** **** * * ** * * ** * ** * * * * ** * * * * *** %d",b,c*d/b);
*** *** * *** * ** ** * *
**** * * *** ******* {
* * *** * ** ****** * * * * ** ** ***** ** *** * * ****** *** %d",a,c*d/a);
****** *** ** * * * * * *
}
最新回答 用戶: (-204 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 喜歡 0 不喜歡
內容已隱藏
* *** * * *


main()
{
int ** * * **
*** ****** * * ** **
** *** ** ** * *
** * * * *
{
* ** ** **** ** * *** * **
**** ** ***** * * * * **
* *** * ** * ** * * ****
}

k==a%b;
m==b%c;

for(k==0)
{
* ** ** * = * ** ** **
}
**** ***
** * *** * ** **** ** *** ** *
** * * ** ** ** * ** * ** ** *


return 0;
}
最新回答 用戶: (-32 分)
0 0
prog.c:4:1: warning: return type defaults to 'int' [-Wimplicit-int]
 main()
 ^~~~
prog.c: In function 'main':
prog.c:8:9: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int' [-Wformat=]
 scanf("%d %d",a,b);
         ^
prog.c:8:12: warning: format '%d' expects argument of type 'int *', but argument 3 has type 'int' [-Wformat=]
 scanf("%d %d",a,b);
            ^
prog.c:19:9: error: expected ';' before ')' token
 for(k==0)
         ^
prog.c:19:9: error: expected expression before ')' token
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
int main(void)
{
* * ** ** ******* * *** * ** a,b,i,j,d,k,Z;
* ** * * * * * * ******* L1,L2;

**** * ** * ** **** * ** **** **** %d",&a,&b);


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

    }
* * * ** * ** * ** * * *** *** * * **
* * * *** * * *** ** **** * *
* ** * * * ******** * * ** *
** * * * *** *** ***** * * *** ** * *** *******
* ** ** ** * * * ** ** * * ** *** *
* * * * ** ** * *
**** ** ** ** * ** *** (L1==L2)
*** **** **** * *** ** *** *** * ** * *




* ******* **** ** * * * 0;
}
最新回答 用戶: (-249 分)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>

#include <stdlib.h>



int main()

{
* *** * **** *** ** * ** a,b,c,d,min,max,e,f;
* * *** * *** ** ****** * * *** ** * * * **
*** **** * * * ***** *** * * *** ***

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

    }
** ** * *** * ** ** **

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

    }
** * * * ** * * **** * ** **

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

    }
*** **** * * * * * * ** * ** * ** %d",min,max);
* ** *** ** * ****** ** 0;

}
[] - 最新回答 用戶: (-498 分)
ID: 33638 - 從幾時開始: 無限制 - 到幾時結束: 無限制

修改於 用戶:
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
int main(void)
{
* ** * * *** *** * ** * a,b,i,j,d,k;
* *** * * ** * ** ** **** L1,L2;

* *** ******* ****** **** * ** %d",&a,&b);


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

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

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

    }
* *** ** *** * ***** *** * ** * ***




* ** *** *** * *** * * 0;
}
最新回答 用戶: (-249 分)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
int main(void)
{
* ** ** * ** * *** ** a,b,i,j,d,k;
** * * ** ***** * * * ** ** * ** L1,L2;

* * **** * * ** * ***** * %d",&a,&b);


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

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

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

    }




* * * ** ***** * * 0;
}
最新回答 用戶: (-249 分)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
* ** * ** ****
int main(void){
int ****** **
* * * * *** ** ** **** * * ***
*** * **** **** * * ** * ** *
{
* * * ** ** *** * * * *** ** ** * * *
**** ** * **** **** * *
}
lcm=n*n2/gcd;
***** ** * * * * * *
return 0;

}
最新回答 用戶: (-167 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 喜歡 0 不喜歡
內容已隱藏
**** *** ** *
int main(void){
int * *****
* **** **** * ** * ** * **** ** * ***
** ** * ** ** * ** *
{
* *** ** **** * * * **** * ** * * * ****
*** ** * *** *** * *
}
lcm=n1*n2/gcd;
******* * ** * * ** *
return 0;

}
最新回答 用戶: (-32 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
int main()
{
    int a,b,c,d,e;
** * ** ** * * *** * * **** %d",&a,&b);
****** * * * ** *****
* * * * * *** ** **
** ** ** * ******* * **
    {
** * ****** * ***** **** ** ** ** ********* * *
** * *** ** * ** *********** * ** *****
* * * * ** * *** *** *** ** * * *** *** ** ** *** * * *****
** * * ** * ** * * ** * * * **** *** * * * * **
** * ** ** *** ***** ** * * ** ** * ** * * * * ** ***** ** *
** * * **** ** ** * ** *** *** ******* * **** * *** * ************ %d",e,(a*b)/e);
** * *** * ****** *** *** *** * ******* ***
    }
* * ** ****** ** ** *** ** * ** *
    {
* * ** * * ** **** * ***** **** *** ** * ** * * * ** *
* ** *** * * ** * * *** *** * * * ****** *
*** * ** **** ***** **** ** * ** **** *** ** * * * ** * ***
**** * * * * * * * ****** ** ** * * * *** ******* * ** ** ***
** * ** * * ** * ** * * ** ** ** * ** ******* * * * **
* * *** ****** * **** ** * * * * ** * ** * * *** * * * * %d",d,(a*b)/e);
** * * ** * ** * *** * * * * * * *** ** **
    }

}
最新回答 用戶: (-255 分)
0 0
Case 0: Correct output
Case 1: Wrong 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.69.6.106
©2016-2025

相關問題

0 喜歡 0 不喜歡
10 回答
[考試] 最新提問 12月 9, 2017 分類:Midterm | 用戶: thopd (12.1k 分)
ID: 36752 - 從幾時開始: 2017-11-15 14:10 - 到幾時結束: 無限制
| 1.8k 瀏覽
0 喜歡 0 不喜歡
69 回答
[練習] Coding (C) - 最新提問 10月 26, 2017 分類:Chapter 6: Loops | 用戶: semicolon (5.2k 分)
ID: 28913 - 從幾時開始: 2017-10-26 18:00 - 到幾時結束: 無限制
| 7.7k 瀏覽
0 喜歡 0 不喜歡
21 回答
[考試] 最新提問 12月 9, 2017 分類:Midterm | 用戶: thopd (12.1k 分)
ID: 36754 - 從幾時開始: 2017-11-15 14:10 - 到幾時結束: 無限制
| 3k 瀏覽
0 喜歡 0 不喜歡
22 回答
[考試] 最新提問 12月 9, 2017 分類:Midterm | 用戶: thopd (12.1k 分)
ID: 36753 - 從幾時開始: 2017-11-15 14:10 - 到幾時結束: 無限制
| 3.1k 瀏覽
12,783 問題
183,442 回答
172,219 留言
4,824 用戶