返回列表 發帖

301 函式與陣列 (小星星)

1. 題目說明:
請依下列題意進行作答,使輸出值符合題意要求。

2. 設計說明:
請撰寫一程式,包含名為compute()的函式,接收主程式傳遞的一個陣列,陣列中有兩個正整數,陣列索引值0代表一列要輸出的星星數;索引值1代表共輸出幾列,compute()輸出星星印出的結果並計算總共有幾顆星星回傳至主程式輸出。

提示:若使用 Java 語言答題,請以「JP」開頭命名包含 main 靜態方法的 class,評測系統才能正確評分。

3. 輸入輸出:
輸入說明
兩個正整數

輸出說明
根據輸入值決定輸出多少星星與星星的總數

範例輸入
10
3

範例輸出
**********
**********
**********
30


本帖隱藏的內容需要回復才可以瀏覽
python
  1. def compute(W, H):
  2.     for i in range(H):
  3.         for j in range(W):
  4.             print('*', end = '')
  5.         print()
  6.     print(W * H)

  7. W = int(input())
  8. H = int(input())
  9. compute(W, H)
複製代碼
May

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int q[2];
  4. int compute(int q[2])
  5. {
  6.     for(int i=1;i<=q[1];i++)
  7.     {
  8.         for(int j=1;j<=q[0];j++)
  9.             cout<<"*";
  10.         cout<<endl;
  11.     }
  12.     return q[0]*q[1];
  13. }
  14. int main()
  15. {
  16.     cin>>q[0]>>q[1];
  17.     cout<<compute(q);
  18.     return 0;
  19. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int q[2];
  4. int compute(int q[2])
  5. {
  6.     for(int i=1;i<=q[1];i++)
  7.     {
  8.         for(int j=1;j<=q[0];j++)
  9.             cout<<"*";
  10.         cout<<endl;
  11.     }
  12.     return q[0]*q[1];
  13. }
  14. int main()
  15. {
  16.     cin>>q[0]>>q[1];
  17.     cout<<compute(q);
  18.     return 0;
  19. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int q[2];
  4. int compute(int q[2])
  5. {
  6.     for(int i=1;i<=q[1];i++)
  7.     {
  8.         for(int j=1;j<=q[0];j++)
  9.             cout<<"*";
  10.             cout<<endl;
  11.     }
  12.     return q[0]*q[1];
  13. }
  14. int main()
  15. {
  16.     cin>>q[0]>>q[1];
  17.     cout<<compute(q)<<endl;
  18.     return 0;
  19. }
複製代碼

TOP

本帖最後由 朱奕祈 於 2024-7-6 14:15 編輯
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int q[2];
  4. int compute(int q[2])
  5. {
  6.     for(int i=1;i<=q[1];i++)
  7.     {
  8.         for(int j=1;j<=q[0];j++)
  9.             {
  10.                   cout<<"*";
  11.             }
  12.             cout<<endl;
  13.     }
  14.     return q[0]*q[1];
  15. }
  16. int main()
  17. {
  18.     cin>>q[0]>>q[1];
  19.     cout<<compute(q)<<endl;
  20.     return 0;
  21. }
複製代碼
(☆▽☆)<<可以按喔

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int q[2];
  4. int compute(int q[2])
  5. {
  6.     for(int i=1;i<=q[1];i++)
  7.     {
  8.         for(int j=1;j<=q[0];j++)
  9.             cout<<"*";
  10.         cout<<endl;
  11.     }
  12.     return q[0]*q[1];
  13. }
  14. int main()
  15. {
  16.     cin>>q[0]>>q[1];
  17.     cout<<compute(q)<<endl;
  18.     return 0;
  19. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int q[2];
  4. int compute(int q[2])
  5. {
  6.     for(int i=1;i<=q[1];i++)
  7.     {
  8.         for(int j=1;j<=q[0];j++)
  9.             cout<<"*";
  10.         cout<<endl;
  11.     }
  12.     return q[0]*q[1];
  13. }
  14. int main()
  15. {
  16.     cin>>q[0]>>q[1];
  17.     cout<<compute(q)<<endl;
  18.     return 0;
  19. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int q[2];
  4. int compute(int q[2])
  5. {
  6.     for(int i=1;i<=q[1];i++)
  7.     {
  8.             for(int j=1;j<=q[0];j++)
  9.             {
  10.                 cout<<"*";
  11.             }
  12.            cout<<endl;
  13.     }
  14. return q[0]*q[1];
  15. }
  16. int main()
  17. {
  18. cin>>q[0]>>q[1];
  19. cout<<compute(q);
  20.     return 0;
  21. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a(int n[]){
  4.     for(int i=1;i<=n[1];i++){
  5.         for(int j=1;j<=n[0];j++)
  6.             cout<<"*";
  7.         cout<<endl;
  8.     }
  9.     return n[0]*n[1];
  10. }
  11. int main()
  12. {
  13.     int n[2];
  14.     cin>>n[0]>>n[1];
  15.     cout<<a(n);
  16.     return 0;
  17. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int q[2];
  4. int computer(int q[2])
  5. {
  6.     for(int i=1;i<=q[1];i++)
  7.     {
  8.         for(int j=1;j<=q[0];j++)
  9.             cout<<"*";
  10.             cout<<endl;
  11.     }
  12.     return q[0]*q[1];
  13. }
  14. int main()
  15. {
  16.     cin>>q[0]>>q[1];
  17.     cout<<computer(q);
  18.     return 0;
  19. }
複製代碼

TOP

返回列表