先快速排序
#include <stdio.h> #define count(a) sizeof(a)/sizeof(int) int main() { int s[] = {-1,0,-2,1,2,2,3,4,7,9,11,13}; int sum = 7; int i = 0; int j = count(s)-1; int g = 0; while(i!=j) { if(s[i]+s[j] > sum) j--; else if(s[i]+s[j] < sum) i++; else { g = 1; printf("%d+%d=%d\n",s[i],s[j],sum); i++; } } if(!g) printf("Not found!\n"); return 0; }