Print lower triangular matrix using Array in C


This program is about get and print the element in a two dimensional lower triangle matrix array using array and for loops.

Source Code

#include<stdio.h>
int main()
{
  int a[10][10],i,j,r,c,z=0,o=0;
  printf("\nEnter the No of Rows:");
  scanf("%d",&r);
  printf("\nEnter the No of Columns:");
  scanf("%d",&c);
  printf("\nEnter the matrix Values:");
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
       scanf("%d",&a[i][j]);
    }
  }
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
       printf("\t%d",a[i][j]);
    }
    printf("\n");
  }
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
       if(i<j)
       {
          if(a[i][j]==0)
          {
            z++;
          }
       }
       else
       {
           o++;
       }
    }
  }
  if((r*c)==(z+o))
  {
    printf("\n %d*%d Lower Matrix",r,c);
  }
  else
  {
    printf("\n %d*%d Not Lower Matrix",r,c);
  }
  return 0;
}
To download raw file Click Here

Output

Enter the No of Rows:3
Enter the No of Columns:3
Enter the matrix Values:1
0
0
1
1
0
1
1
1
    1    0    0
	1    0    0
	1    1    1
3*3 Lower Matrix


List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes