A. Print K-th Element
Problem Setup
- login to CS50 IDE
- write
cdin the terminal to go to the home directory - write
mkdir print-kth-elementto create a folder calledprint-kth-element - write
cd print-kth-elementto go to theprint-kth-elementfolder - write
code print-kth-element.cppto create a file calledprint-kth-element.cppand open it in the editor
Problem
Given an array of \(n\) elements and a number \(k\), your task is to print the \(k\)-th number of the array.
Note: The array is zero indexed.
Input
The first line of input contains two integers \(n\) and \(k\) where \(1 \leq n \leq 10^4\) and \(1 \leq k \leq n\) — number of elements in array and \(k\)th element to find.
The second line of input contains \(n\) integers \(a_1, a_2, \ldots, a_n\) where \(1 \leq a_i \leq 10^5\) — elements of array.
Output
Print the \(k\)th element of array.
Examples
Example 1:
Input:
6 2
1 2 3 4 5 6
Output:
2
Example 2:
Input:
3 1
5 22 1
Output:
5
Test Your Code
Make sure you are in the print-kth-element directory, then run the following command:
check50 iti-technical-team/week3/2026/3/print-kth-element
Submit Your Code
Make sure you are in the print-kth-element directory, then run the following command:
submit50 iti-technical-team/week3/2026/3/print-kth-element