SCALAR MATRIX OR NOT

Consider the following I/O samples.

 


SAMPLE INPUT :      3

                                  4 0 0
                                  0 4 0
                                  0 0 4


SAMPLE OUTPUT: SCALAR MATRIX
 

The SCALAR MATRIX is a square matrix in which all the off-diagonal elements are zero and all the on-diagonal elements are equal
 

                                 


 

C PROGRAM:

#include<stdio.h>
int main()
{
    int row,col,arr[100][100],i,j;
    scanf("%d",&row);
    scanf("%d",&col);
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            scanf("%d",&arr[i][j]);
        }
    }
    int a=0;
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            if(i!=j && arr[i][j]!=0)
            {
                a=1;
                break;
            }
            if(i==j && arr[i][j]!=arr[i][j])
            {
                a=1;
                break;
            }
        }
    }
    if(a == 1)
        printf("Not a Scalar Matrix");
    else

        printf("Scalar Matrix");


    
        return 0; 

}

 



OUTPUT:

 

                        


                       



The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 
If you have any feedback about this article and want to improve this, please comment in the comment section.

 

Comments

Popular posts from this blog

INVERTED PYRAMID STAR PATTERN

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

C PROGRAM TO PRINT THE REMAINING DAYS AND COMPLETED DAYS FROM A GIVEN DATE