Demo entry 3548684

Pairs

   

Submitted by anonymous on Jan 17, 2016 at 17:18
Language: C. Code size: 364 Bytes.

void find_pairs(int* arr, int n, int x){
    int i = 0;
    int j = n-1;

    // regularly step i
    for(i=0; i < n; i++){

        // variably step j as long as sum is greater than x
        while(arr[i] + arr[j] > x){
            j--;
       }

       if(arr[i] + arr[j] == x)
           fprintf(stdout, "pair found at (%d, %d)\n", i, j);
    }
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).