There is a (much) more efficient way to do this.
Say the user input 3 and 5. You need to only start check in the sorted sums, for an 8.
That 8 could be found by a binary search, an indexed search, etc., but the very fastest way would be to have an array where all the sums values were assigned to the [index], of a second array.
Say it was called mysums[]. If mysums[8] was set to zero when mysums[] was created, and now mysums[8] has a value (of 8 or 1, just something other than zero), then your program would know that there was a sum with the value of 8, in the array of data the user entered.
User data: 3 + 12 + 5... sum[20] equals 1 or any nonzero value. Now:
Code:
if(mysums[sum])
printf("Matching sum was found.\n");
else
printf("No matching sum was found.\n");
Now the search, is reduced to checking just one value. This technique is the basis for an algorithm called "Counting Sort", btw. You can't always use it (negative numbers, really big numbers, floating point numbers), but when you can use it, it's VERY fast, indeed.
Do you want to change it to use counting sort, or stick with the first way you were trying to do it? Counting sort is pretty simple once you wrap your head around the concept.
And Welcome to the forum, Yong Jie!