Print 2 double arrrays, the second one should be cumulative totals of the elements of the first array Please tell me how bad is the code...in the book he said it's possible with either nested loop, or 1 loop

The user should provide the 8 double numbers for the program to set the cumulative totals in the second array.

This is the code:

#include &lt;stdio.h&gt;
#define ASIZE 8

int main()

{
    int index = 0, x, index2;
    double cal;
    double array1[ASIZE], array2[ASIZE];

    printf("Please enter 8 numbers:\n");
    for (index = 0; index &lt; ASIZE; index++)//adding the numbers to the first array 
    {
        scanf("%lf", &amp;array1[index]);
    }

    for (x = 0,index2 = 0,index = 0; x &lt; ASIZE; x++, index2++)//adding the second array the elements
    {
        cal += array1[index++];
        array2[index2] = cal;
    }

    printf("the first array numbers are:\n");//printing the first array numbers 
    for (index = 0; index &lt; ASIZE; index++)
    {
        printf("%.1lf ", array1[index]);
    }
    printf("\n");
    printf("\n");
    printf("the second array numbers are:\n");//printing the second array
    for (index2 = 0; index2 &lt; ASIZE; index2++)
    {
        printf("%.1lf ", array2[index2]);
    }



}


I'm a beginner in C, and its important for me to know how to get better.
About the only thing I would change is this loop

for (x = 0,index2 = 0,index = 0; x &lt; ASIZE; x++, index2++)//adding the second array the elements
{
    cal += array1[index++];
    array2[index2] = cal;
}


You don't need x (its really index1. As all the variables are tracking each other you don't need index2 as index1 is the same value each iteration (and allways do the increment in the for() loop.

The only bug I see is the cal is not initialized to zero and can thus have an indeterminate value.

I would have written it like this:

cal = 0.0;
for (index = 0; index &lt; ASIZE; index++)//adding the second array the elements
{
    cal += array1[index];
    array2[index] = cal;
}


A minor note:

As the code may be changed to have bigger arrays by modifying ASIZE. I would make the user instructions reflect this automaically.

printf("Please enter 8 numbers:\n");

// Try:

printf("Please enter %d numbers:\n", ASIZE);