adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

program in c to print upper triangular matrix

Program in C to print  Upper triangular matrix

Upper triangular matrix :- A square matrix in which all the elements below its principal diagonal are zero, is called an upper triangular matrix. For example 




#include<stdio.h>
#include<conio.h>
   int main()
    {
     int m[3][3],i,j;
  printf("Enter a matrix of size 3 * 3::-\n");
  for(i=0;i<3;i++)
    {
     for(j=0;j<3;j++)
      scanf("%d",&m[i][j]);
    }
    printf("Upper triangular matrix is as follows:-\n");
    for(i=0;i<3;i++)
         {
    for(j=0;j<3;j++)
            if(i<=j)
        printf("%3d",m[i][j]);
     else
        printf("  0");
              printf("\n");
      }
      getch();
     }
Output:-









Program in C to print  Upper triangular matrix using Function


#include<stdio.h>
#include<conio.h>
 void upper(int m1[][3],int r,int c)
    {
   int i,j;
   printf("\nUsing function");
   printf(" Upper triangular matrix is as follows:-\n");
   for(i=0;i<r;i++)
        {
         for(j=0;j<c;j++)
           if(i<=j)
        printf("%3d",m1[i][j]);
    else
       printf("  0");
           printf("\n");
       }
    }
   int main()
    {
     int m[3][3],i,j;
     printf("Enter a matrix of size 3 * 3::-\n");
     for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
     scanf("%d",&m[i][j]);
   }
 upper(m,3,3);  // calling upper function
      getch();
     return 0;
     }
Output:-




Related programs
  1. Program in C to print  Lower triangular matrix

Post a Comment

0 Comments