[解答] 計程上機考Q6

看板NTUBIME96-HW作者 (我 累 了)時間22年前 (2003/12/08 00:36), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
#include <stdafx.h> #include <iostream> using std::cout; using std::cin; using std::endl; void funGcdLcm( int, int ); int main() { int a, b; int flag = 1; while( flag != 0 ) { cout << "First number : "; cin >> a; cout << "Second number : "; cin >> b; funGcdLcm( a, b ); do { cin.get(); cout << "Finish this program? (Y/N) "; switch( cin.get() ) { case 'Y': case 'y': flag = 0; break; case 'N': case 'n': cout << endl; flag = 1; break; default: flag = 2; break; } }while( flag == 2 ); } return 0; } void funGcdLcm( int a, int b ) { int i, j, r; i = a; j = b; while( j != 0 ) { r = i % j; i = j; j = r; } cout << "The GCD ( " << a << " , " << b << " ) = " << i << endl; cout << "The LCM [ " << a << " , " << b << " ] = " << a * b / i << endl; } -- 助教們有看作業板的話就順便幫忙看看有沒有錯吧^^ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.174.157.31
文章代碼(AID): #_qrRtbD (NTUBIME96-HW)