標題:
2025/1/25冠毅
[打印本頁]
作者:
郭竑志
時間:
2025-1-25 13:59
標題:
2025/1/25冠毅
本帖最後由 郭竑志 於 2025-1-25 15:35 編輯
[課堂重點]
304 函式與陣列 (倍數判斷)
305 函式與陣列 (運算判斷)
306 函式與陣列 (階乘)
307 函式與陣列 (陣列最大值)
308 函式與陣列 (費氏數列)
[今日作業]
307 函式與陣列 (陣列最大值)
308 函式與陣列 (費氏數列)
函式與陣列 (最小的分數值)
作者:
劉冠毅
時間:
2025-1-25 14:27
#include<bits/stdc++.h>
using namespace std;
int compute(int o[6])
{
int l=0;
for(int i=0;i<=5;i++){
if(o[i]%3==0){
l=l+1;
}
}
return l;
}
int main()
{
int str[6];
for(int e=0;e<=5;e++){
cin>>str[e];
}
cout<<compute(str);
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2025-1-25 14:46
#include<bits/stdc++.h>
using namespace std;
int compute(int o[3])
{
if(o[1]==1){
return o[0]+o[2];
}else if(o[1]==2){
return o[0]*o[2];
}
}
int main()
{
int str[3];
for(int i=0;i<=2;i++){
cin>>str[i];
}
cout<<compute(str);
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2025-1-25 15:37
#include<bits/stdc++.h>
using namespace std;
int f(int n)
{
if(n==0){
return 1;
}else {
return n*f(n-1);
}
}
int main()
{
int str;
cin>>str;
cout<<"n!="<<f(str);
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2025-2-8 00:06
本帖最後由 劉冠毅 於 2025-2-8 14:55 編輯
#include<bits/stdc++.h>
using namespace std;
int compute(int o[5])
{
int a,b,c,d;
a=max(o[0],o[1]);
b=max(a,o[2]);
c=max(b,o[3]);
d=max(c,o[4]);
return d;
}
int main()
{
int u[5];
for(int i=0;i<=4;i++){
cin>>u[i];
}
cout<<compute(u);
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2025-2-8 01:28
本帖最後由 劉冠毅 於 2025-2-8 14:50 編輯
#include<bits/stdc++.h>
using namespace std;
int f(int u)
{
if(u==0)
return 0;
else if(u==1)
return 1;
return f(u-1)+f(u-2);
}
int main()
{
int i;
cin>>i;
for(int u=i;u>=0;u--){
cout<<f(u)<<endl;
}
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2025-2-8 01:44
本帖最後由 劉冠毅 於 2025-2-8 14:11 編輯
#include<bits/stdc++.h>
using namespace std;
float compute(float u[6])
{
float a,b,c;
a=u[0]/u[3];
b=u[1]/u[4];
c=u[2]/u[5];
if(a<b and a<c){
return a ;
}else if(b<a and b<c){
return b;
}else if(c<a and c<b){
return c ;
}
}
int main()
{
float i[6];
for(int t=0;t<=5;t++){
cin>>i[t];
}
printf("%.3f",compute(i));
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2