Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          array-2.c - C Program with two a dimensional array.Lecture 1 - slide 20 : 34
Program 6

#include <stdio.h>
#include <stdlib.h>

int main(void) {

  double b[][3] = {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}},
         sum1 = 0.0, sum2 = 0.0;
  int i, j, k;

  b[1][2] += 0.1;

  for (i = 0; i < 2; i++)      /* Sum of elements */
    for (j = 0; j < 3; j++){
      printf("b[%d][%d] = %f\n", i, j, b[i][j]);
      sum1 += b[i][j];  
    }

  for (k = 0; k < 2 * 3; k++)  /* An alternative summation */
    sum2 += *(&b[0][0] + k);   /* Same result */

  printf("Sum1 = %f, sum2 = %f\n", sum1, sum2);
  /* Sum1 = 21.100000, sum2 = 21.100000 */
  
  return 0;
}