C examples for Array:Multidimensional Arrays
Declares two dimensional array, print the values, double all the values, and then display the new values
#include <stdio.h> #define ROWS 3 /*from w w w.j ava 2 s . c o m*/ #define COLS 5 void times2(int ar[][COLS], int r); void showarr2(int ar[][COLS], int r); int main(void) { int stuff[ROWS][COLS] = { {1,2,3,4,5}, {6,7,8,-22,13}, {11,12,13,14,15} }; showarr2(stuff, ROWS); putchar('\n'); times2(stuff, ROWS); showarr2(stuff, ROWS); return 0; } void times2(int ar[][COLS], int r) { int row, col; for (row = 0; row < r; row++) for (col = 0; col < COLS; col++) ar[row][col] *= 2; } void showarr2(int ar[][COLS], int r){ int row, col; for (row = 0; row < r; row++){ for (col = 0; col < COLS; col++) printf("%d ", ar[row][col]); putchar('\n'); } }