Retrieve Element from Array


Submit solution

Points: 45 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type

題目說明

請設計一個程式,讓使用者先輸入陣列大小,接著輸入對應數量的整數作為陣列內容。
最後,請使用者輸入一個索引值,並輸出該索引對應的數字。

若索引值超出範圍,則輸出 "Index is out of range!"。

輸入

第一行:輸入一個正整數 n,表示陣列大小 (1 ≤ n ≤ 100)。
第二行:輸入 n 個整數,作為陣列的內容。
第三行:輸入一個索引值 (0 ~ n-1),指定要輸出的陣列元素。

輸出

若索引值在範圍內,則輸出對應數字。
若索引值超出範圍,則輸出 Index is out of range!

範例輸入 #1

5
10 20 30 40 50
2

範例輸出 #1

30

範例輸入 #2

4
3 6 9 12
-1

範例輸出 #2

Index is out of range!

Comments

There are no comments at the moment.