Two Dimensional Array can be created in C - Program.Sometime it called "matrix".Two Dimensional Array has two subscript or index.The declaration of Two Dimensional Array is :
Data_Type Array_Name [row] [column]
Here row and column are sizes of these array.EX :
int table [3][2];
The above table is a Two Dimensional Array with 3 rows and 2 columns.
Two Dimensional Array Initialization :
There are many ways to Initialize Two Dimensional Array:Like :
int table [4][2]={
{1,2},
{3,4},
{5,6},
{7,8},
};
We can also initialize it like this : int table[4][2]={1,2,3,4,5,6,7,8};
We must mention second index for initializing Two Dimensional Array:EX :
int table [][2]={1,2,3,4,5,6,7,8}; //correct form
Watch The program : #include<stdio.h>
#include<conio.h>
#define ROLL 4
#define NUM 2
main()
{
int student [ROLL] [NUM];
int p;
printf("Type Roll And Marks :");
for(p=0;p<=3;p++)
{
scanf("%d%d",&student [p][0],&student [p][1]);
}
for(p=0;p<=3;p++)
{
printf("\n%d%d",student[p][0],student[p][1]);
}
getch();
}
INPUT : Type Roll And Marks :
1
2
3
4
5
6
7
8
OUTPUT : 1,2
3,4
5,6
7,8
Hope all of you understand how Two Dimensional Array works.Thank you very much for reading.
Post a Comment