標題:
05/09小考專區
[打印本頁]
作者:
李知易
時間:
7 天前 19:06
標題:
05/09小考專區
本帖最後由 李知易 於 2025-5-9 21:01 編輯
請於其中四題挑選三題作答
請於程式碼前標註題號
範例:
(一)
#include<*************>
using n*******e s*d;
int main()
{
cin >> a;
cout << a;
return 0;
}
複製代碼
(二)
#include<*************>
using n*******e s*d;
int main()
{
cin >> a;
cout << a;
return 0;
}
複製代碼
[attach]21029[/attach]
題目 1:判斷奇偶數
--------------------------------------
輸入一個數,判斷其為奇數或偶數。
輸入範例: 3
輸出範例: 3為奇數
--------------------------------------
題目 2:九九乘法表
----------------------------------
印出一九九乘法表(1x1 ~ 9x9)
如下:
1x1=1 1x2=2 ... 1x9=9
2x1=2 ...
----------------------------------
題目 3:計算 1 到 N 的總和
----------------------------------------------------
讓使用者輸入一個正整數 N,並輸出從 1 到 N 的總和。
輸入範例: 10
輸出範例: 總和為 55 (1+2+3+...+10= 55)
----------------------------------------------------
題目 4:最大值與最小值
-------------------------------------------
輸入五個整數,找出其中的最大值與最小值。
輸入範例: 1 3 5 2 4
輸出範例: 最大值為 5
最小值為 1
-------------------------------------------
四題挑三題做
挑戰提:
題目 5:字串反轉
-------------------------------------------
輸入一個字串,輸出其長度並將其反轉。
輸入範例: applebanana
輸出範例: 11
ananabelppa
-------------------------------------------
解答:
(一)
#include<bits/stdc++.h>
using namespace std;
int main()
{
re:
int n;
cin >> n;
if(n % 2 == 0)
cout << n << "為偶數" << endl;
else
cout << n << "為奇數" << endl;
goto re;
return 0;
}
複製代碼
(二)
參考之前題目九九乘法表
(三)
#include<bits/stdc++.h>
using namespace std;
int main()
{
re:
int n, sum = 0;
cin >> n;
for(int i = 1; i <= n; i++)
sum += i;
cout << sum << endl;
goto re;
return 0;
}
複製代碼
(四)
#include<bits/stdc++.h>
using namespace std;
int main()
{
re:
int a, b, c, d, e, f, g, h, i;
cout << "請輸入五個數:";
cin >> a >> b >> c >> d >> e;
f = a > b ? a : b;
g = f > c ? f : c;
h = g > d ? g : d;
i = h > e ? h : e;
cout << "最大為" << i << endl;
f = a < b ? a : b;
g = f < c ? f : c;
h = g < d ? g : d;
i = h < e ? h : e;
cout << "最小為" << i << endl;
goto re;
return 0;
}
複製代碼
(五)挑戰題
#include<bits/stdc++.h>
using namespace std;
int main()
{
re:
string str;
cin >> str;
int len = str.length();//int len = str.size();
cout << len << endl;
for(int i = len - 1; i >= 0; i--)
cout << str[i];
cout << endl;
goto re;
return 0;
}
複製代碼
進階解法:
#include<bits/stdc++.h>
using namespace std;
int main()
{
re:
string str;
cin >> str;
int len = str.length();//int len = str.size();
cout << len << endl;
reverse(str.begin(), str.end());
cout << str << endl;
goto re;
return 0;
}
複製代碼
作者:
張詠博
時間:
7 天前 19:24
此帖僅作者可見
作者:
張詠博
時間:
7 天前 19:26
此帖僅作者可見
作者:
陳頎諠
時間:
7 天前 19:26
此帖僅作者可見
作者:
陳頎諠
時間:
7 天前 19:29
此帖僅作者可見
作者:
鄭子宸
時間:
7 天前 19:30
此帖僅作者可見
作者:
鄭子宸
時間:
7 天前 19:33
此帖僅作者可見
作者:
張詠博
時間:
7 天前 19:33
此帖僅作者可見
作者:
洪睿輿
時間:
7 天前 19:34
此帖僅作者可見
作者:
朱立人
時間:
7 天前 19:35
此帖僅作者可見
作者:
陳頎諠
時間:
7 天前 19:40
此帖僅作者可見
作者:
鄭子宸
時間:
7 天前 19:42
此帖僅作者可見
作者:
楊昀瑾
時間:
7 天前 19:47
此帖僅作者可見
作者:
朱立人
時間:
7 天前 20:14
此帖僅作者可見
作者:
黃品錡
時間:
7 天前 21:05
此帖僅作者可見
作者:
黃品錡
時間:
7 天前 21:06
此帖僅作者可見
作者:
江立辰
時間:
6 天前 07:34
此帖僅作者可見
作者:
黃品錡
時間:
3 天前 19:44
此帖僅作者可見
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2