i have tried this

Code:

#include <stdio.h>
#include <conio.h>
#include <math.h>
void main() {
int inputs[20], numInputs;
int queries[4], numQueries;
int i, j, a=1, b=1;
clrscr();
printf("Enter number of inputs: ");
scanf("%d", &numInputs);
printf("\nEnter input values: ");
for(i=0; i<numInputs; i++)
scanf("%d", &inputs[i]);
printf("\n\nEnter number of queries: ");
scanf("%d", &numQueries);
printf("\nEnter query values: ");
for(i=0; i<numQueries; i++)
scanf("%d", &queries[i]);
for(i=0; i<numQueries; i++)
{
for(j=0; j<numInputs; j++)
if (abs(queries[i] - inputs[a]) > abs(queries[i] - inputs[j]))
a = j;
for(j=0; j<numInputs; j++)
{
if (j == a)
j++;
if ((abs(queries[i] - inputs[b]) > abs(queries[i] - inputs[j])))
b = j;
}
printf("\n\nSum of values closest to %d is %d", queries[i], inputs[a]+inputs[b]);
a=1;
b=1;
}
getch();

but the output is little diverted from supposed output .

instead of

Case 1:

Closest sum to 1 is 15.

Closest sum to 51 is 51.

Closest sum to 30 is 29.

i am getting

Case 1:

Closest sum to 1 is 15.

Closest sum to 51 is 67

Closest sum to 30 is 67.