返回列表 發帖

[隨堂測驗] 求最小公倍數 (break敘述)

讓使用者任意輸入兩個正整數, 求它們的最小公倍數.
提示: 加入break敘述, 使符合條件時, 跳出迴圈.

提示:
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.     int x, y, bigger;
  7.     while(true)
  8.     {
  9.         system("cls");
  10.         cout<<"輸入第一個數: ";
  11.         cin>>x;
  12.         cout<<"輸入第二個數: ";
  13.         cin>>y;
  14.         bigger=x>y?x:y;
  15.         
  16.         //1 vs 5   1*5
  17.         cout<<x<<"與"<<y<<"的最小公倍數為: ";
  18.         for(int i=bigger; i<=x*y; i??)
  19.         {
  20.              if( ? % ? ==0 && ? % ?==0)
  21.              {
  22.                   cout<<i<<endl;
  23.                   break;         
  24.              }
  25.         }
  26.       
  27.         system("pause");
  28.     }
  29.     return 0;   
  30. }
複製代碼

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

返回列表