-->
Showing posts with label WAP to print lower triangular matrix of order mxn.. Show all posts
Showing posts with label WAP to print lower triangular matrix of order mxn.. Show all posts

WAP to print lower triangular matrix of order mxn.

using codeblock
---------------------------
//WAP to print lower triangular matrix  of order mxn.// comment about our program
#include<stdio.h>                                    // header file where are libraries are stored
int main()                                          // main function
{
int matrics_1[100][100];                     // declaration of matrix of maximum size 100
int i,j      ;                                        // variables declaration
int total_row,total_col;                     // variables for rows and columns
printf("the matrix must be square for upper triangular\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // input for total number of rows of matrix
printf("enter total columns(n)\n");
scanf("%d",&total_col);                     // input for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("matrix is\n");                  // matrix message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           printf("%d",matrics_1[i][j]); // display of matrix with elements
        }
        printf("\n");                    // display in next row
}
printf("lower triangular matrix is\n");  // message for lower triangular matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                // nested loop
       {
           if(i>=j)                       // testing the condition
           {
            printf("%d",matrics_1[i][j]);// display of lower triangular matrix with elements
           }
           else
           {
               printf("0");               // display of zero elements below diagonal if the condition did not satisfy.
           }
       }
       printf("\n");
}
 return 0;
}
----------------------------
using turboC++
--------------------------
//WAP to print lower triangular matrix  of order mxn.// comment about our program
#include<stdio.h>                                    // header file where are libraries are stored
#include<conio.h>
void main()                                          // main function
{
int matrics_1[100][100];                     // declaration of matrix of maximum size 100
int i,j      ;                                        // variables declaration
int total_row,total_col;                     // variables for rows and columns
printf("the matrix must be square for upper triangular\n");
printf("enter total number of rows(m)\n");
scanf("%d",&total_row);                     // input for total number of rows of matrix
printf("enter total columns(n)\n");
scanf("%d",&total_col);                     // input for total number of columns of matrix
printf("enter elements of matrix\n");
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                  // nested loop for input of elements
       {
           scanf("%d",&matrics_1[i][j]);   // getting inputs from user
        }
}
printf("matrix is\n");                  // matrix message display
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)
       {
           printf("%d",matrics_1[i][j]); // display of matrix with elements
        }
        printf("\n");                    // display in next row
}
printf("lower triangular matrix is\n");  // message for lower triangular matrix
for(i=0;i<total_row;i++)
{
  for(j=0;j<total_col;j++)                // nested loop
       {
           if(i>=j)                       // testing the condition
           {
            printf("%d",matrics_1[i][j]);// display of lower triangular matrix with elements
           }
           else
           {
               printf("0");               // display of zero elements below diagonal if the condition did not satisfy.
           }
       }
       printf("\n");
}
 getch();
}