codescracker


c

C Two Dimensional Array Program



« Previous Program Next Program »


Two Dimensional Array Program in C

To initialize and print two dimensional array in C programming, you have to ask to the user to enter the row and columns size of the array for the array dimension, then ask to enter the array elements of entered dimension. To print back all the array element in two dimension (row by column), you have to use two for loops, the first one is outer for loop and the second one is inner for loop. Outer for loop is responsible for rows and the inner for loop is responsible for columns.

C Programming Code for Two Dimensional (2D) Array

Following C program ask to the user to enter row and column size of the array, then ask to the user to enter the array elements to initialize the array element in the array, and the program will display the two dimensional array:

/* C Program - Two Dimensional Array */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int arr[10][10], row, col, i, j;
	printf("Enter number of row for Array (max 10) : ");
	scanf("%d",&row);
	printf("Enter number of column for Array (max 10) : ");
	scanf("%d",&col);
	printf("Now Enter %d*%d Array Elements : ",row, col);
	for(i=0; i<row; i++)
	{
		for(j=0; j<col; j++)
		{
			scanf("%d",&arr[i][j]);
		}
	}
	printf("The Array is :\n");
	for(i=0; i<row; i++)
	{
		for(j=0; j<col; j++)
		{
			printf("%d  ",arr[i][j]);
		}
		printf("\n");
	}
	getch();
}

When the above c program is compile and executed, it will produce the following result:

two dimensional array in c

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test