返回列表 發帖

[作業] 數青蛙 (一)

本帖最後由 許婷芳 於 2019-8-30 11:02 編輯

利用 for 迴圈,完成如下之執行畫面:

附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         int s;
  7.         re:
  8.         cout<<"請問要輸入幾隻青蛙:";
  9.         cin>>s;
  10.         for(int i=1;i<=s;i++)
  11.         {
  12.                 cout<<i<<"隻青蛙"<<i<<"張嘴,"<<i*2<<"顆眼睛"<<i*4<<"條腿!"<<"\t";
  13.                 cout<<endl;
  14.         }
  15.         goto re;
  16.         system("pause");
  17.         return 0;
  18. }
  19. //
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.         re:
  7.         int j;
  8.         cout<<"請問要數到第幾隻蟑螂? 母湯太大喔~"<<endl;
  9.         cin>>j;
  10.         for(int i = 1; i <= j; i++ )
  11.         {
  12.                 cout<<i<<"隻蟑螂"<<i<<"個嘴"<<i*2<<"顆眼睛"<<i*6<<"隻腳"<<endl;
  13.         }
  14.         goto re;
  15.         system("pause");
  16.         return 0;
  17. }
複製代碼

TOP

本帖最後由 謝以愛 於 2019-9-6 18:14 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main()
  5. {               
  6.         re:
  7.         int f;
  8.         cout<<"請問要數到第幾隻青蛙?"<<endl;
  9.         cin>>f;
  10.         for(int i = 1; i <= f; i++ )
  11.         {
  12.                 cout<<i<<"隻青蛙"<<i<<"張嘴"<<i*2<<"個眼睛"<<i*4<<"條腿"<<endl;
  13.         }
  14.         goto re;
  15.         system("pause");
  16.         return 0;
  17. }
複製代碼

TOP

TOP

本帖最後由 許婷芳 於 2019-9-6 19:04 編輯
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int s;
  7.     cout<<"請問要數到第幾隻青蛙?  ";
  8.     cin>>s;
  9.     cout<<endl;
  10.    
  11.     for(int i = 1; i <= s; i++ ){
  12.         cout << i << "隻青蛙" << i << "張嘴, " << i*2<< "個眼睛" << i*4 << "條腿!" <<endl;
  13.     }
  14.     system("pause");
  15.     return 0;

  16. }
複製代碼

TOP

本帖最後由 許婷芳 於 2019-9-6 21:07 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         
  7.          int s;
  8.          cout<<"請問要數到第幾個青蛙?";
  9.          cin>>s;
  10.          cout<<endl;
  11.          for(int y = 1; y <= s; y++)
  12.         {               
  13.                 cout<<y<<"隻青蛙"<<y<<"張嘴,"<<y*2<<"個眼睛"<<y*4<<"條腿!"<<endl;
  14.         }
  15.         system("pause");
  16.        return 0;   
  17. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int s;
  7.     cout<<"請問要數到第幾隻青蛙?  ";
  8.     cin>>s;
  9.     cout<<endl;
  10.    
  11.     for(int i = 1; i <= s; i++ ){
  12.         cout << i << "隻青蛙" << i << "張嘴, " << i*2<< "個眼睛" << i*4 << "條腿!" <<endl;
  13.     }
  14.     system("pause");
  15.     return 0;

  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.                 unsigned  long  long  s=0,o;
  7.                 re:
  8.                 cout<<"請問要數第幾頭牛";
  9.                        
  10.                
  11.                 cin>>o;
  12.         for(s=1;s<=o;s++)
  13.         {
  14.        
  15.                 cout<<s<<"頭牛"<<s<<"張嘴,"<<s*2<<"顆眼睛"<<s*4<<"隻腳!!!!!!!!!!!!!!!!!! ! !"<<"\t";
  16.                 cout<<endl;        
  17.     }
  18. goto re;

  19.     system("pause");

  20.     return 0;
  21.     }
複製代碼

TOP

本帖最後由 林祐霆 於 2019-8-31 11:40 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         unsigned long long s=0,o;
  7.         re:
  8.         cout<<"請問要數到第幾隻噁心的蜘蛛?請不要打太大的數字或輸入負數喔!(不然會跑很久)";
  9.         cin>>o;
  10.     for(s=1;s<=o;s++)
  11.     {
  12.         cout<<s<<"隻蜘蛛"<<s<<"張嘴,"<<s*2<<"顆眼睛"<<s*8<<"條腿!"<<"\t";
  13.         cout<<endl;
  14.     }
  15.     goto re;
  16.     system("pause");
  17.     return 0;   
  18. }
複製代碼
林祐霆

TOP

返回列表