C programming Q/A

Q6) In this assignment, you will be given an N×N matrix, with N>1 You have to determine whether the matrix is an upper triangular matrix. A matrix is upper triangular if every entry below the diagonal is 0. The following is an example of an upper triangular matrix: 1000140011001111 Note: The diagonal itself, and the entries above the diagonal can be zeroes or non-zero integers. Input ------- First, you will be given N, which is the size of the matrix. Then you will be given N rows of integers, where each row consists of N integers separated by spaces. Output --------- If the input matrix is upper triangular, then print 1. Otherwise, print 0.

    
    #include

int main()
{
int n, i, j, flag = 1;
scanf("%d", &n);
int a[n][n];
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
scanf("%d", &a[i][j]);
for(i = 0; i < n; i++)
for(j = i + 1; j < n; j++)
if(a[i][j] != 0)
flag = 0;
if(flag == 1)
printf("1\n");
else
printf("0\n");
return 0;
}
    
Previous Post Next Post