This is a C program to print the kth element in the array.
Problem Description
This C Program implements an array prints the kth element in the array where the position k is entered by the user as an input.
Problem Solution
1. Create an array and taking its size from the users, define all its elements.
2. Take an input from users, the position in the array where we want to access element.
3. The element would be in the index (entered_position -1) of the array, print it.
Program/Source Code
Here is source code of the C Program to print the kth element in the array. The program is successfully compiled and tested using Turbo C compiler in windows environment. The program output is also shown below.
/*
* C Program to Print the kth Element in the Array
*/
#include
int main()
{
int arr[100], len, i, j, temp, n;
printf(“Enter the size of array”);
scanf(“%d”, &len);
printf(“\n Enter the array elements”);
for (i = 0; i < len; i++) { scanf("%d", &arr[i]); } printf("\n Enter Which kth Number You want"); scanf("%d", &n); printf("\n The %d th kth number is: %d", n, arr[n - 1]); return 0; } Runtime Test Cases Enter the size of array4 Enter the array elements 12 13 17 20 Enter Which kth Number You want 4 The 4th kth number is: 20