標題:
2025/1/18冠毅
[打印本頁]
作者:
郭竑志
時間:
2025-1-18 13:36
標題:
2025/1/18冠毅
[課堂重點]
209 選擇敘述與迴圈 (五五乘法表)
210 選擇敘述與迴圈 (最大公因數與最小公倍數)
301 函式與陣列 (小星星)
302 函式與陣列 (分數調整)
304 函式與陣列 (倍數判斷)
305 函式與陣列 (運算判斷)
[今日作業]
303 函式與陣列 (質數判斷)
作者:
劉冠毅
時間:
2025-1-18 14:03
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a;
cin>>a;
for(int i=2;i<a;i++){
int j=2;
for(j;j<=i-1;j++){
if(i%j==0){
break;
}
}
if(i==j)
cout<<i<<" ";
}
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2025-1-18 14:15
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a;
cin>>a;
if(a==0){
for(int i=1;i<=5;i++){
for(int o=1;o<=5;o++){
cout<<i<<"*"<<o<<"="<<i*o<<"\t";
}
cout<<endl;
}
}else if(a==1){
for(int i=1;i<=5;i++){
for(int o=1;o<=5;o++){
cout<<o<<"*"<<i<<"="<<i*o<<"\t";
}
cout<<endl;
}
}else{
cout<<"error";
}
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2025-1-18 14:56
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a;
int b;
int tmp;
int lcf;
cin>>a>>b;
lcf=a*b;
while(b!=0){
tmp=b;
b=a%b;
a=tmp;
}
cout<<a<<endl;
cout<<lcf/a;
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2025-1-18 15:20
#include<bits/stdc++.h>
using namespace std;
int compute(int i,int o){
for(int h=1;h<=o;h++){
for(int k=1;k<=i;k++){
cout<<"*";
}
cout<<endl;
}
return i*o;
}
int main()
{
int a, b;
cin>>a>>b;
cout<<compute(a,b);
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2025-1-18 15:30
#include<bits/stdc++.h>
using namespace std;
int compute(int i){
if(i<0 or i>100){
cout<<"-1";
}else if(i>=60){
i=i+5;
}else{
i=i+10;
}
return i;
}
int main()
{
int a;
cin>>a;
cout<<compute(a);
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2025-1-25 13:54
#include<bits/stdc++.h>
using namespace std;
int compute(int o)
{
for(int p=2;p<o;p++){
if(o%p==0){
return 0;
}
}
return 1;
}
int main()
{
int u;
cin>>u;
if(compute(u)==0){
cout<<u<<"is not a prime number";
}else{
cout<<u<<"is a prime number";
}
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2