A function that finds the kth smallest integer in array A (unsorted), of size n
The compiler is your friend

Activate all warnings and you'll get pretty good hints :

selection.c: In function ‘kth_smallest_number’:
selection.c:17:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^


Test your code

Here's what I have written to test your code :

int A[] = {4,4,56,78,54,6512,21,8,7,2,321,87,78,54,2,21,5,4,321,456,5,4,35,5,4,1,67,8,1,54,4,654,7,6,54,321,7,32,4,21,54,7};
int n = sizeof(A)/sizeof(A[0]);
for (int k=0; k&lt;n; k++)
{
    printf("%d %d\n",k,kth_smallest_number(A,n,k));
}


I'd expect the returned value to be sorted and it's clearly not the case here. Thus, I expect something to be wrong.

Playing with other inputs : int A[] = {10,9,8,7,6,5,4,3,2,1,0}; , int A[] = {10,9,8,7,6,5,5,4,3,2,1,0};, it seems like your solution does not handle properly duplicated value.

A matter of style

The indentation looks weird on your question.

You should try to declare your local variable in the smallest possible scope. Among other things, you can define your loop indices in the loop syntax in you use the C99 mode (-std=c99).

Once rewritten (but still wrong), your code looks like :

int kth_smallest_number(int A[], int n, int k){
    for(int i=0; i&lt;n; i++){
        /*Check whether the number A[i] satisfies
          the condition*/
        int smaller_than_count = 0;
        for(int j=0; j&lt;n; j++){
            if(A[i]&lt;=A[j]){
                smaller_than_count++;
            }
        }
        if(smaller_than_count == n-k){
            return A[i];
        }
    }
}




Edit : 

An attempt to correctness

Here what I have written , it seems to work fine but I won't promise anything.

int kth_smallest_number(int A[], int n, int k){
    for(int i=0; i&lt;n; i++){
        /*Check whether the number A[i] satisfies the condition*/
        int ai = A[i];
        int smaller_than_count = 0;
        int bigger_than_count = 0;
        for(int j=0; j&lt;n; j++){
            int aj = A[j];
            if (ai &lt; aj) {
                smaller_than_count++;
                if (smaller_than_count &gt;= n-k) break; // Optimisation
            } else if (ai &gt; aj) {
                bigger_than_count++;
                if (bigger_than_count &gt; k) break; // Optimisation
            }
        }
        if(smaller_than_count &lt; n-k &amp;&amp; bigger_than_count &lt;= k){
            return ai;
        }
    }
    return -1;
}