In C programming, there is a missing number in an array.

kulluM

New member
The missing number is to be determined given an array C of size N-1 with numbers from 1 to N with one entry missing.
INPUT: The first line of input contains the integer T, which represents the number of test cases. The first line of each test case includes N. (size of array). The line after that has N-1 array entries.
OUTPUT: Print the missing number in the array.
The goal of this problem is to find the missing number in a set of n integers like in this given example. However, when I ran the code below, I did not get the expected results.
Code:
#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;
}
 
Top