C program to find upper triangle and lower triangle of matrix

program:
   //Taking input for matrix
 printf("Enter Matrix :\n");
  for(i=0;i<rows;i++)
  {
  for(j=0;j<col;j++)
  {
   scanf("%d",&a[i][j]);
  }
  }
  printf("The given Matrix is :\n");
  for(i=0;i<rows;i++)
  {
  for(j=0;j<col;j++)
  {
   printf("%d\t",a[i][j]);
  }
  printf("\n");
  }
  printf("Upper Triangle of Matrix is :\n");
  for(i=0;i<rows;i++)
  {
    for(j=0;j<col;j++)
    {
     if(i<j)
     {
      printf("%d\n",a[i][j]);
     }
    }

  }

    printf("Lower Triangle of Matrix is :\n");
  for(i=0;i<rows;i++)
  {
    for(j=0;j<col;j++)
    {
     if(i>j)
     {
      printf("%d\n",a[i][j]);
     }
    }

  }
}
 else
 {
  printf("Not Possible \n");
 }
 return 0;
}
}
output:

Previous Post Next Post