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

Arithmetic program in C language || Calculator program in C language

  Calculator  program in C language .           First of all let us know its logic .how is this working . Now let's see it's process . In C language , %d is used to define it's integers and %f is used to define it's floats. In C language , the (+) sign is used as a plus , the (-) sign used as a minus , the (*) sign is used for multiplies and the (/) sign is used for division.                %0.2f it means any float value like 52.987 = 52.98.it show only 2 place of the decimal. PROGRAM                          /*ARITHMETIC PROGRAM IN C LANGUAGE*/ #include"stdio.h" int main() { float a,b,sum,sub,mult,div ; char sign; printf("SELECT ANY SIGN (+ - * / ) :"); scanf("%c",&sign); printf("ENTER THE FIRST NUMERIC VALUE:"); scanf("%f",&a); printf("ENTER THE SECOND NUMERIC VALUE:"); scanf("%f",&b); switch(sign) { case '+':...

Matrix Addition and subtraction program in C language

  Matrix Addition and Subtraction program in C language Today here you will be able to learn about multiple tasks in Matrix-like addition, subtraction, and multiplication. @#1.Matrix Addition   Suppose that we have two matrices of 3X3 orders. This matrix A and B. In this program   C is the addition of A & B; i and k are used for initialization. Matrix Addition Program  #include"stdio.h" int main() { int A[10][10],B[10][10],C[10][10],i,k,row,col; printf("Enter The Matrix row & col = "); scanf("%d %d",&row,&col); printf("Enter the First matrix :\n"); for(i=0;i Output is:  Enter The Matrix row & col = 2 3 Enter the First matrix : Enter matrix[0][0]=2 Enter matrix[0][1]=1 Enter matrix[0][2]=3 Enter matrix[1][0]=6 Enter matrix[1][1]=54 Enter matrix[1][2]=7 First matrix are: 2       1       3 6       54      7 Enter the Second matrix : Enter matrix[0][0]=8 Enter matrix[0][1...