Program in C to print Upper triangular matrix
#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
Program in C to print Lower triangular matrix
0 Comments