精華區beta NTUBIME96-HW 關於我們 聯絡資訊
#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