
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What is a two-dimensional array in C language?
An array is a group of related items that store with a common name.
Syntax
The syntax is as follows for declaring an array −
datatype array_name [size];
Types of arrays
Arrays are broadly classified into three types. They are as follows −
- One – dimensional arrays
- Two – dimensional arrays
- Multi – dimensional arrays
Initialization
An array can be initialized in two ways, which are as follows −
- Compile time initialization.
- Runtime initialization.
Two multidimensional arrays
These are used in situations where a table of values have to be stored (or) in matrices applications.
Syntax
The syntax is given below −
datatype array_ name [rowsize] [column size];
For example int a[5] [5];
a[0][0] 10 | a[0][1] 20 | a[0][2] 30 |
a[1][0] 40 | a[1][1] 50 | a[1][2] 60 |
a[2][0] | a[2][1] | a[2][2] |
Following is the C Program for compile time initialization −
Example
#include<stdio.h> main ( ){ int a[3][3] = {10,20,30,40,50,60,70,80,90}; int i,j; printf ("elements of the array are"); for ( i=0; i<3; i++){ for (j=0;j<3; j++){ printf("%d \t", a[i] [j]); } printf("
"); } }
Output
The output is stated below −
elements of the array are: 10 20 30 40 50 60 70 80 90
Following is the C program for runtime initialization −
Example
#include<stdio.h> main ( ){ int a[3][3] ,i,j; printf ("enter elements of array"); for ( i=0; i<3; i++){ for (j=0;j<3; j++){ scanf("%d", &a[i] [j]); } } printf("elements of the array are"); for ( i=0; i<3; i++){ for (j=0;j<3; j++){ printf("%d\t", a[i] [j]); } printf("
"); } }
Output
The output is stated below −
Enter elements of array : 1 2 3 4 5 6 7 8 9 Elements of the array are 1 2 3 4 5 6 7 8 9
Given below is the C program to calculate sum and product of all elements in an array using run time compilation −
Example
#include<stdio.h> void main(){ //Declaring the array - run time// int A[2][3],B[2][3],i,j,sum[i][j],product[i][j]; //Reading elements into the array's A and B using for loop// printf("Enter elements into the array A:
"); for(i=0;i<2;i++){ for(j=0;j<3;j++){ printf("A[%d][%d] :",i,j); scanf("%d",&A[i][j]); } printf("
"); } for(i=0;i<2;i++){ for(j=0;j<3;j++){ printf("B[%d][%d] :",i,j); scanf("%d",&B[i][j]); } printf("
"); } //Calculating sum and printing output// printf("Sum array is :
"); for(i=0;i<2;i++){ for(j=0;j<3;j++){ sum[i][j]=A[i][j]+B[i][j]; printf("%d\t",sum[i][j]); } printf("
"); } //Calculating product and printing output// printf("Product array is :
"); for(i=0;i<2;i++){ for(j=0;j<3;j++){ product[i][j]=A[i][j]*B[i][j]; printf("%d\t",product[i][j]); } printf("
"); } }
Output
The output is stated below −
Enter elements into the array A: A[0][0] :2 A[0][1] :3 A[0][2] :1 A[1][0] :2 A[1][1] :4 A[1][2] :5 B[0][0] :1 B[0][1] :2 B[0][2] :3 B[1][0] :5 B[1][1] :6 B[1][2] :7 Sum array is : 3 5 4 7 10 12 Product array is : 2 6 3 10 24 35
- Related Articles
- What is a one-dimensional array in C language?
- What is a multi-dimensional array in C language?
- Explain pointers and two-dimensional array in C language
- Explain pointers and one-dimensional array in C language
- Explain the concept of one and two dimensional array processing using C language
- How to declare a two-dimensional array in C#
- What is a multidimensional array in C language?
- Passing two dimensional array to a C++ function
- How do I sort a two-dimensional array in C#
- C# program to Loop over a two dimensional array
- What is the simplest multi-dimensional array in C#?
- Split one-dimensional array into two-dimensional array JavaScript
- What are two-dimensional arrays in C#?
- Dimensional Array in C#?
- Transpose of a two-dimensional array - JavaScript

Advertisements