Skip to main content

Two dimensional array in C language or matrix program in c language

 Two dimensional arrays:

1.Two dimensional array is known as matrix.
2.An array with two subscripts is termed as two-dimensional array.
3.We know that a one dimensional array can store a row of elements, so a two-dimensional array enables us to store multiple roes of elements.

The syntax of declaring a two-dimensional array is :

Data-type array name[row][column];


For reading value :


for(k=0;k<4;k++)
{
for(l=0;l<3;l++)
{
scanf("%d",&a[k][l]);
}
}


For displaying value :


for(k=0;k<4;k++)
{
for(l=0;l<3;l++)
{
printf("%d",a[k][l]);
}
printf("\n");
}

Simple Matrix Program :

#include"stdio.h"
int main()
{
int a[3][3];
int k,l;
printf("Enter the array elements: \n");
for(k=0;k<3;k++)  //for reading value//
{
for(l=0;l<3;l++)
{
printf("Enter a[%d][%d] :",k,l);
scanf("%d",&a[k][l]);
}
}
printf("\n\nMatrix are: \n");
for(k=0;k<3;k++)  //for displaying value//
{
for(l=0;l<3;l++)
{
printf("%d\t",a[k][l]);
}
printf("\n");
}
}


Output are:

Enter the array elements:
Enter a[0][0] :1
Enter a[0][1] :4
Enter a[0][2] :5
Enter a[1][0] :7
Enter a[1][1] :12
Enter a[1][2] :8
Enter a[2][0] :96
Enter a[2][1] :10
Enter a[2][2] :3

Matrix are:
1       4       5
7      12      8
96    10      3












Comments

Popular posts from this blog

One dimensional array declaration in c language basic of array

One D array **Definition of array** Array can be define as a collection of data object which are stored in consecutive memory location with a common variable name.                                                                                                        or  Array is the collection of similar data types or collection of similar entity stored in contiguous memory location . **Initialization of array** Array can be made initialization at the time of declaration itself. The general form of array initialization is as below  1.Data type array name[size] 2. Data type array name[size]={element1,element2,element3,.....} Example: int a[[4]={1,5,8,4} char d[3]={'A','R',u...

Age calculating through date of birth program in C language

DATE OF BIRTH PROGRAM IN C LANGUAGE          Today's date - your date of birth = your current age  There are fifth condition are happening.. @1.IF today date 13.7.2021 and date of birth 15.9.2001 age are (2021-2001).(7-9).(13-15) = 20.-2.-2   but it's wrong real age will be 19year.9month.28days .Then first condition will be (days < 0)&&(month<0) @2.IF today date 13.7.2021 and date of birth 12.9.2001 age are(2021-2001).(7-9).(13-12) = 20.-2.1 but it's wrong real age will be 19 year . 10 month . 1 days .Then  second condition will be (days>0)&&(month<0). @3.IF today date 13.7.2021 and date of birth 13.9.2001 age are(2021-2001).(7-9).(13-13) = 20.-2.0 but it's wrong real age will be 19 year . 10 month . 0days .Then  third condition will be (days==0)&&(month<0). @4.IF today date 13.7.2021 and date of birth 13.9.2001 age are(2021-2001).(7-9).(13-13) = 20.1.0 but it's wrong real age will be 19...