/*
  This program demonstrates how to sum all the elements of an array.
*/

#include <stdio.h>

main()
{
  /*  Declaration Statements  */
  char month[12][4];
  short units[12];
  double sales[12];
  double ss;            /* ss stands for sum of sales */
  short i, j, su, k;    /* su stands for sum of units */

  clrscr();
  printf("C52.C -> How to sum all the elements of an array \n");

  /*  Assignment Statements  */
  for (i = 1; i <= 12; i++) {
    printf("\nMonth (Jan,Feb,...) : ");
    scanf("%s",month[i-1]);
    printf("\nUnits Sold          : ");
    scanf("%hd", &units[i - 1]);
    printf("\nSales (in million $): ");
    scanf("%lg", &sales[i - 1]);
  }

  i = 0;
  for (j = 1; j <= 4; j++) {
    su = 0;
    ss = 0.0;
    for (k = 1; k <= 3; k++) {
      i++;
      su += units[i - 1];
      ss += sales[i - 1];
    }  /*  End of inner for{} loop  */

    /*  Print result by quarter  */
    printf("\nquarter%2d%7d cars     $%5.1f m\n\n", j, su, ss);
  }  /*  End of outer for{} loop  */

  return(0);
}
/* End of Program C52 */