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

WAP to print upper triangular matrix of order mxn.

using codeblocks
-----------------------------------
//WAP to print upper triangular matrix  of order mxn.
#include<stdio.h>
int main()
{
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("upper triangular matrix is\n");  // message for upper 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 upper 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 upper triangular matrix  of order mxn.
#include<stdio.h>
#include<conio.h>
void main()
{
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("upper triangular matrix is\n");  // message for upper 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 upper triangular matrix with elements
           }
           else
           {
               printf("0");               // display of zero elements below diagonal if the condition did not satisfy.
           }
       }
       printf("\n");
}
 getch();       
}