Given an array C of size N-1 and given that there are numbers from 1 to N with one element missing, the missing number is to be found.
Input: The first line of input contains an integer T denoting the number of test cases. For each test case first line contains N(size of array). The subsequent line contains N-1 array elements.
Output: Print the missing number in array.
This problem is to find the missing number in a series of n integers. but, while using the below code I could not get the output as expected.
#include <stdio.h>
int main()
{
//code
int T,run,i;
scanf("%d", &T);
long N,res,C,en;
long arra[1];
for (run = 0;run <T; run++ )
{
long arra[T];
scanf("%ld", &N);
res =0;
for (i = 0; i <N-1; i++)
{
scanf("%ld",&C);
res = res + C;
}
en = ((N*(N+1))/2)- res; // subtracting the overall sum of array elements from N integers
arra[run]=en; //saving it to array
}
for(run = 0; run < T; run++)
{
printf("%ld ",arra[run]);
}
return 0;
}
I expected the below input and output:
Input:
2
5
1 2 3 5
10
1 2 3 4 5 6 7 8 10
Output:
4
9
but actual output is
1 -8719623343620674816