I was writing a program in C to check how many elements in a given array are smaller than or equal to a particular element of same array.
t
= no of test cases
n
= size of array
k
= index of that element array with with whom all the elements have to be compare
j
= number of elements less than or equal to element k
of array
for (i = 1; i <= t; i++)
{
scanf("%d", &n);
scanf("%d", &k);
for (i = 1; i <= n; i++)
{
scanf("%d", &arr[i]);
}
for (l = 1; l <= n; l++)
{
if (arr[l] <= arr[k])
{
j++;
}
}
printf("%d\n", j);
fflush(stdin);
}
But the problem is that my program is running only for one case. After that it terminates. Why this is happening? Why this is not running for 2, 3, 4 ... test cases?