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 <stdio.h>
#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 < ASIZE; index++)//adding the numbers to the first array
{
scanf("%lf", &array1[index]);
}
for (x = 0,index2 = 0,index = 0; x < 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 < 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 < ASIZE; index2++)
{
printf("%.1lf ", array2[index2]);
}
}
I'm a beginner in C, and its important for me to know how to get better.
