Minimum sum of numbers The code reads an input with numbers and find the sum with the minimum difference of the first two big numbers. The sums are three.

Is there is any way to make the code cleaner? (Note that I don't need to take any restrictions such as NULL parameters, etc)

Moreover, there is an int in my program pA = -1 with that value. Now, because the pA used as pointer you see below that I have the statement ProfitA = array[pA];, that statement doesn't give any problems, but I just wanted to point it out in case you could clean my code a bit.

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;limits.h&gt;

#define TRUE 1
#define FALSE 0
#define min(ProfitA, ProfitB, ProfitC) ProfitA &gt; (ProfitB &gt; ProfitC ? ProfitB : ProfitC) ? ProfitA : (ProfitB &gt; ProfitC ? ProfitB : ProfitC)

int main() {

    FILE* input = fopen("share.in","r");
    int bestMin = INT_MAX;
    int N = 0;
    fscanf(input,"%d",&amp;N);

    int *array = malloc(N * sizeof(int));



    int pA = -1, pB = N - 1;
    int ProfitA = 0, ProfitC = 0, ProfitB = 0;

    for (int i = 0; i &lt; N; i++) {
        fscanf(input,"%d",&amp;array[i]);
        ProfitB += array[i];

    }


    ProfitB = ProfitB - array[pA] - array[pB];
    ProfitA = array[pA];
    ProfitC = array[pB];


    fclose(input);

    short flag = TRUE;
    int check_L = 0, check_R = 0;

    while ((pB - pA != 1) &amp;&amp; (flag == TRUE)) {
        flag = FALSE;

        check_L += ProfitA + array[pA + 1];
        check_R += ProfitC + array[pB - 1];


        if (check_L &lt; check_R) {

            ProfitA = check_L;
            ProfitB -= array[pA + 1];
            pA++;
            flag = TRUE;

        }
        else {

            ProfitC = check_R;
            ProfitB -= array[pB - 1];
            pB--;
            flag = TRUE;
        }
      check_R = 0, check_L = 0;

        printf("k1 = %d, k3 = %d, k2 = %d\n",ProfitA,ProfitB,ProfitC);

           int  currentMin = min(ProfitA, ProfitB, ProfitC); 

            if (currentMin &lt; bestMin) {
                bestMin = currentMin;
            }


    }
    printf("%d\n",bestMin);

    return 0;
}
You definitely can make your code cleaner :


Your function main does all the job, that's usually quite bad. You can, at least, separate two aspects : reading the input (and store it in an array) and processing the input. That would be a little bit easier to read
Use comments ! Not even one here, that's pretty bad.
Better use of new lines : you really tend to use way too much of them. Multiple new lines should be used to separate parts of code that do quite different things, but in no case you should use two just after an if
Better variable naming : just one example, but it's because it's very common : i . I really don't like it, because by reading the index, you don't know through what you iterate. The best example for that are matrices, i and j are far less understandable than iRow and iCol
The indentation is also quite bad, especially at the end
You don't free the memory you have allocated.
Have you tried removing your condition on flag in your while ? You set it to false, then there's an if/else, and in both cases, it's set to true again.