2D Array Example
      An array is a contiguous block of memory.In a 2D array there are many rows.The total number of elements in the array is row x columnWe use 2 for loops to access elements of the array
/*
	http://www.ProbCOMP.com
	
	An array is a contiguous block of memory.In a 2D array there are many rows.The total number of elements in the array is row x column
	We use 2 for loops to access elements of the array.

*/

#include<stdio.h>
#define ROW 3
#define COL 2

void display(int arr[ROW][COL])
{
	for(int i=0;i<ROW;i++)
	{
		for(int j=0;j<COL;j++)
		{
				printf("%d",arr[i][j]);
		}
		printf("\n");
	}
}

void main()
{
	int arr1[ROW][COL]={0}; // all the elements of 3x3 array are intialized ot 0
	printf("\narray 1\n");
	display(arr1);
	int arr2[ROW][COL] = {{1,2},{3,4},{5,6}};
	printf("\narray 2\n");
	display(arr2);
	int arr3[ROW][COL]={1,2,3,4,5,6};//the array is determined by itself
	printf("\narray 3\n");
	display(arr3);
	int arr4[ROW][COL];
	printf("\nScan an array\n"); //scanning an array
	printf("enter values for a %dx%d array\n",ROW,COL);
	for(int i=0;i<ROW;i++)
	{
		for(int j=0;j<COL;j++)
		{
				scanf("%d",&arr4[i][j]);
		}
		
	}
	printf("\nyou entered array 4 as\n");
	display(arr4);
	
}									

Download Program
Did You Know ?
IP address is a numerical label that is assigned to devices participating in a computer network. Read More