I am a beginner. I'm trying to solve a pair-sum program. The program calls for the number of pairs being added and the actual pairs, then it returns the sum of each pair. I'm using an array to store the sum of each pair, but when I print out every element the last one is always wrong. This is what I have so far:
int c, val1, val2, x, i;
printf("Enter the number of pairs to sum: \n");
scanf("%d", &c);
int sum [c];
printf("Enter the pairs: \n");
for ( x = 0; x < (c - 1); ++x)
{
scanf("%d", &val1);
scanf("%d", &val2);
sum [x] = val1 + val2;
val1 = 0;
val2 = 0;
}
printf("The sum of each pair is: \n");
for (i = 0; i < c; ++i)
{
printf("%d\t", sum[i]);
}
(c-1)in one loop, and not the other...