返回列表 發帖
  1.     #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x,y,n;
  7.     cout << "請輸入第一個數: ";
  8.     cin >> x;
  9.     cout << "請輸入第二個數: ";
  10.     cin >> y;
  11.     cout << x << "與" << y << "的最公因數是: ";
  12.     int i=1;
  13.     while(i<=x)
  14.     {
  15.         if(x%i==0 && y%i==0)
  16.         {
  17.             n=i;
  18.         }
  19.         i++;      
  20.     }
  21.     cout << n << endl;
  22.     system("pause");
  23.     return 0;
  24. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main ()
  5. {
  6.     re:
  7.     int s;
  8.     cout<<"請輸入你的年齡: ";
  9.     cin>>s;
  10.     if(s>=200 || s<0)
  11.     {
  12.         cout<<"別鬧了"<<endl;
  13.     }
  14.     else if(s>=65)
  15.     {
  16.         cout<<"購買敬老票(70元)"<<endl;
  17.     }
  18.     else if(s>=13)
  19.     {
  20.         cout<<"購買一般票(100元)"<<endl;
  21.     }
  22.     else if(s>=4)
  23.     {
  24.         cout<<"購買兒童票(50元)"<<endl;
  25.     }
  26.     else
  27.     {
  28.         cout<<"幼兒票(免費入場)"<<endl;
  29.     }
  30.     goto re;
  31.     system ("pause");
  32.     return 0;
  33. }
複製代碼

TOP

返回列表