C program for printing the kth element in the given array after sorting

#include

int main()
{
int arr[10], 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]);
}
for (i = 0; i < len; i++)
{
for (j = 0; j arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j+1] = temp;
}
}
}
printf(“The new array is:”);
for (i = 0; i < len; i++)
{
printf("%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;
}

Advertisements

2 thoughts on “C program for printing the kth element in the given array after sorting

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s