Given an array, find the kth element of the array.
For example:
If the input array is
1 2 3 4 5 6
Then
if k=3, then 3rd element is 3
if k=4, rth element is 4
Implementation:
For example:
If the input array is
1 2 3 4 5 6
Then
if k=3, then 3rd element is 3
if k=4, rth element is 4
Implementation:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
 int *a,n,i,pos;
 
 /* Get the number of elements of the array */
 scanf("%d",&n);
 
 /* allocate the memory for the array */
 a=(int*)malloc(sizeof(int)*n);
 
 /* Get the elements of the array */
 for(i=0;i<n;i++)
  scanf("%d",(a+i));
  
 /* position to print the element */ 
 scanf("%d",&pos); 
 
 /* The kth element will be at pos-1, if the array is 0-based indexing */
 printf("%d",*(a+pos-1));
 
 return 0;
}