Upper Triangular Matrix


Submit solution

Points: 10 (partial)
Time limit: 2.0s
Memory limit: 12M

Authors:
Problem type
Allowed languages
C

Task

To display the upper triangular matrix of an array.

Input

Read the size of array followed by elements in the same line separated by space.

Output

Print the result in a new line in matrix format.

Sample Input1

2 3 1 2 4 2 3 4

Sample output1

Not a square matrix

Sample Input2

3 3 1 2 3 2 1 1 3 3 3

Sample output2

1 2 3

0 1 1

0 0 3


Comments


  • 1
    Guruprasad  commented on May 13, 2023, 3:54 p.m.

    include <stdio.h>

    include <stdbool.h>

    int main() { int a,b,i,j; bool f=false; scanf("%i %i",&a,&b); if(a!=b) { printf("Not a square matrix"); } else { int A[a][b]; for(i=0;i<a;i++) { for(j=0;j<b;j++) {

    scanf("%d",&A[i][j]);

    } } A[1][0]=0; A[2][1]=0; A[2][0]=0; for(i=0;i<a;i++) { for(j=0;j<b;j++) { printf(" %d",A[i][j]); } printf("\n"); }

    } return 0;

    }