Course Content
Programming Language C
About Lesson
C
Matrix - 2d array. It is used to store data in form of rows and columns.

syntax:

datatype matrix_name[rows][cols];
     0    1   2
0   12    6  10
1    7    8   5
2    5    3   3
eg.

 int a[3][3]

     0      1       2
0   0,0    0,1     0,2
1   1,0    1,1     1,2
2   2,0    2,1     2,2

printf("%d",a[0][0]); // 1
a[0][0]=12;
a[0][2]=10;
*/

#include<stdio.h>


int main()
{
  int a[3][3],i,j;
 
  for(i=0;i<3;i++) // 0,1,2, (3) stop
  {
    for(j=0;j<3;j++) //0=>0,1,2 (3), 1=>0,1,2 (3), 2=>0,1,2 (3)
    {
      printf("\nenter an element:");
      scanf("%d",&a[i][j]);// 1,2,3, 4,5,6, 7,8,9
    }
  }
  printf("\nyour matrix output is \n");
  for(i=0;i<3;i++)
  {
    for(j=0;j<3;j++)
    {
      printf("%d\t",a[i][j]);
    }
    printf("\n");
  }
 return 0;
}
C
/*
Transpose of 3x3 Matrix
*/
#include<stdio.h>

int main()
{
  int a[3][3],i,j;
 
  for(i=0;i<3;i++)
  {
    for(j=0;j<3;j++)
    {
     printf("\nenter an element : ");
     scanf("%d",&a[i][j]);
    }
  }
  printf("\n Your matrix transpose output is \n");
  for(i=0;i<3;i++)
  {
    for(j=0;j<3;j++)
    {
     printf("%d\t",a[j][i]);
    }
    printf("\n");
  }
return 0;
}
C
/*
3x3 matrix left diognal.
*/
#include<stdio.h>
int main()
{
  int a[3][3],i,j;
  
  for(i=0;i<3;i++)
  {
    for(j=0;j<3;j++)
    {
     printf("\nenter an element : ");
     scanf("%d",&a[i][j]);
    }
  }
  printf("\n Your matrix left diognal is \n");
  for(i=0;i<3;i++)
  {
    for(j=0;j<3;j++)
    {
     if(i==j)
     printf("%d\t",a[j][i]);
     else
     printf("\t");
    }
    printf("\n");
  }
  return 0;
}
C
/*
3x3 matrix right diognal
*/
#include<stdio.h>
#include<conio.h>
void main()
{
  int a[3][3],i,j;
  clrscr();
  for(i=0;i<3;i++)
  {
    for(j=0;j<3;j++)
    {
     printf("\nenter an element : ");
     scanf("%d",&a[i][j]);
    }
  }
  printf("\n Your matrix right diognal is \n");
  for(i=0;i<3;i++)
  {
    for(j=0;j<3;j++)
    {
     if(i+j==2)
     printf("%d\t",a[i][j]);
     else
     printf("\t");
    }
    printf("\n");
  }
  getch();
}
C
/*
3x3 matrix lower triangle
*/
#include<stdio.h>
#include<conio.h>
void main()
{
  int a[3][3],i,j;
  clrscr();
  for(i=0;i<3;i++)
  {
    for(j=0;j<3;j++)
    {
     printf("\nenter an element : ");
     scanf("%d",&a[i][j]);
    }
  }
  printf("\n Your matrix lower triangle is \n");
  for(i=0;i<3;i++)
  {
    for(j=0;j<=i;j++)
    {

     printf("%d\t",a[j][i]);

    }
    printf("\n");
  }
  getch();
}
/*
1. Upper Triangle
2. sum of 2 matrix
3. product of 2 matrix
*/