Creates two eight-element arrays of doubles and uses a loop to let the user enter values for the eight elements of the first array. - C Array

C examples for Array:Array Value

Description

Creates two eight-element arrays of doubles and uses a loop to let the user enter values for the eight elements of the first array.

Demo Code

#include <stdio.h>

int main(void)
{
  int int_array[8], cumulative_sum[8];
  int sum = 0;// w w w.  ja  v  a 2 s . c om

  printf("Enter 8 integers:\n");
  for (int i = 0; i < 8; i++)
  {
    scanf("%d", &int_array[i]);
    sum += int_array[i];
    cumulative_sum[i] = sum;
  }
  printf("\n");

  printf("      Integers:");
  for (int i = 0; i < 8; i++)  {
    printf("%6d ", int_array[i]);
  }
  printf("\n");
  printf("Cumulative sum:");
  for (int i = 0; i < 8; i++)
  {
    printf("%6d ", cumulative_sum[i]);
  }
  return 0;
}

Result


Related Tutorials