Board logo

標題: 2024/12/27 課堂重點(若恩) [打印本頁]

作者: 郭竑志    時間: 2024-12-27 20:07     標題: 2024/12/27 課堂重點(若恩)

本帖最後由 郭竑志 於 2024-12-27 21:31 編輯

[作業檢查]
208 選擇敘述與迴圈 (找質數)
209 選擇敘述與迴圈 (五五乘法表)
[課堂重點]
210 選擇敘述與迴圈 (最大公因數與最小公倍數)
301 函式與陣列(小星星)
302 函式與陣列(分數調整)
[/url]
[今日作業]
303 函式與陣列(質數判斷)
304 函式與陣列 (倍數判斷)
作者: 何若恩    時間: 2024-12-27 20:46

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

  3. int main(int argc, char** argv) {
  4.     int a, b, c=0, cnt=0, gcd;
  5.     cin>>a;
  6.     cin>>b;
  7.     if(a>b){
  8.         c=b;
  9.     }else{
  10.         c=a;
  11.     }
  12.     for(int i=1;i<=c;i++){
  13.         if(a%i==0 and b%i==0){
  14.             gcd=i;
  15.             cnt+=1;
  16.         }
  17.     }
  18.     cout<<gcd<<endl;
  19.     cout<<(a*b)/gcd;
  20.     return 0;
  21. }
複製代碼

作者: 何若恩    時間: 2024-12-27 21:13

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int compute(int a[2]){
  4.     return a[0]*a[1];
  5. }

  6. int main(int argc, char** argv) {
  7.     int a[2];   
  8.     cin>>a[0]>>a[1];
  9.     for(int x=1;x<=a[1];x++){
  10.         for(int y=1;y<=a[0];y++){
  11.             cout<<"*";
  12.         }
  13.         cout<<endl;
  14.     }
  15.     cout<<compute(a);
  16.     return 0;
  17. }
複製代碼

作者: 何若恩    時間: 2025-1-3 18:55

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int compute(int n) {
  4.     for (int i=2;i<n;i++) {
  5.         if (n%i==0) {
  6.             return 0;
  7.         }
  8.     }
  9.     return 1;
  10. }

  11. int main() {
  12.     int num;
  13.     cin>>num;
  14.     int result=compute(num);
  15.     if(result==1){
  16.         cout<<num<<" is a prime number"<<endl;
  17.     }else{
  18.         cout<<num<<" is not a prime number"<<endl;
  19.     }

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

作者: 何若恩    時間: 2025-1-3 19:12

  1. #include <iostream>
  2. using namespace std;
  3. int compute(int a[]) {
  4.     int count=0;
  5.     for(int i=0;i<6;i++) {
  6.         if(a[i]%3==0) {
  7.             count++;
  8.         }
  9.     }
  10.     return count;
  11. }

  12. int main() {
  13.     int a[6];
  14.     for(int i=0;i<6;i++) {
  15.         cin>>a[i];
  16.     }
  17.     int result=compute(a);
  18.     cout<<result<<endl;
  19.     return 0;
  20. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2