• + 26 comments

    Mostly agreed, it's a poorly written challenge. They want:

    #include <stdio.h>
    int main()
    {
        int n,sum=0;
        scanf("%d",&n);
        int *val = malloc(n*sizeof(int));
        for(int i=0;i<n;i++)
        {
            scanf("%d",&val[i]);
            sum+=val[i];
        }
        printf("%i",sum);
        free(val);
    }
    

    But there's no reason to store the values. There would be, if you were required to sum all values, then reprint each value. Otherwise you can just..

    #include <stdio.h>
    int main()
    {
        int n,val,sum=0;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d",&val);
            sum+=val;
        }
        printf("%i",sum);
    }