6 thích 0 k thích
880 đã xem

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

Hint: The classic algorithm for computing the GCD, known as Euclid's algorithm, goes as follow: let m and n be variables containing the two numbers. If n is 0, then stop: m contains the GCD. Otherwise, compute the remainder when m is divided by n. Copy n into m and copy the remainder into n. Then repeat the process, starting with testing whether n is 0.

Example input: 

12 28

Example output:

4

 

[Normal] Coding (C) - đã hỏi trong Introduction to Computer Programming I (C) bởi (12.1k điểm)
ID: 27175 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn

chọn từ khóa lại bởi | 880 đã xem

2 Trả lời

0 thích 0 k thích
Hidden content!
#include **** ** *** *
int main()
{
** *** **** * * * n1, n2, i, gcd;
**** * * ** * * ** **** * * *** %d", &n1, ***** * *
** *** * ** * * *
** * * ** ** * ***** ***** i <= n1 * * i <= n2; ++i)
*** * **** *** * **** *
* * * ** **** * *** * * * * * * * * * Checks if i is factor of both integers
* *** ** * * ** * ****** * ** ** * ** * *** *** ** * n2%i==0)
* **** * ***** * * **** ** ** ** *** ** *** = i;
* **** **** *** * *
*** * ** ** * *
** **** ** ** * * * * *********** * gcd);
**** * ** * * ***** *** 0;
}
trả lời bởi (-233 đ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 ***** ** *
int main()
{
** * * * *** * *** *** n1, n2, i, gcd = 0;
* * * * * * * ***
** *** * **** * *** * * ** * * *** * * ** * %d", &n1, &n2);
* ** * *** **** * **
*** * * ** ** * * ****** * i <= n1 && i <= n2; ++i)
*** ** * * ****** ****
** ** ** * * ** **** * ******* * ** * * * && n2%i==0)
* ** *** * * * * *** *** * *** * * ** * *** *** * ** ** = i;
** **** ** *** ** * ***
* * **** * * ** * **** * * *
** *** ****** ******* *** * * ** * * *
** ** * *** * *** ***** *
***** * *** * *** ** ** 0;
}
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
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.179.49
©2016-2025

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

6 thích 1 không thích
1 trả lời
[Normal] Coding (C) - đã hỏi ngày 10 tháng 10 năm 2017 trong Introduction to Computer Programming I (C) bởi admin (9.9k điểm)
ID: 25954 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 1.2k đã xem
5 thích 0 k thích
3 trả lời
[Normal] Coding (C) - đã hỏi ngày 10 tháng 10 năm 2017 trong Introduction to Computer Programming I (C) bởi admin (9.9k điểm)
ID: 25955 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 904 đã xem
12,783 câu hỏi
183,442 trả lời
172,219 bình luận
4,824 thành viên