#include "stdafx.h" #include <cassert> void check_sum(int * arr, size_t len, int sum) { assert(arr); int i=0,j=len-1; while(i<j) { int cur_sum = arr[i]+arr[j]; if(cur_sum == sum) { printf("%d %d\n", arr[i], arr[j]); i++; j--; } else if(cur_sum > sum) j--; else i++; } } int _tmain(int argc, _TCHAR* argv[]) { int arr[5] = {1,2,3,4,5}; check_sum(arr,5,11); return 0; }