/******************************************************
 * CP-I warmup 1999-2000
 * Problem #13
 *****************************************************/

/*
 * Question:
 * Write a complete C program that first reads, row by row, a
 * nX n array, where n is an input.  The program should then
 * determine wether the array just read falls into any of the
 * following special cases:
 * (a) Symetric (a[j,i]=a[i,j] for all i,j)
 * (b) Upper triangular (aij=0 whenever i<j)
 * (c) diagonal (aij=0 whenever i!=j)
 */

#include <stdio.h>
#define MAX_SIZE        10

int matrix[MAX_SIZE][MAX_SIZE];
int size;
main()
{
        int i,j;
        
        printf("Give the size of square matrix (n): ");
        scanf("%d",&size);

        if(size>MAX_SIZE)
        {
                printf("This size is not supported. (size should be less than %d)\n",MAX_SIZE);
                exit(2);
        }

        for(i=0;i<size;i++)
                for(j=0;j<size;j++)
                {
                        printf("Give the a[%d][%d] element: ",i+1,j+1);
                        scanf("%d",&matrix[i][j]);
                }
        if(is_diagonal())
        {
                printf("The matrix is Diagonal, therefore it is Upper\
                        Triangular and Symmetrix also\n");
                exit(0);
        }       
        if(is_uppertriangular())
        {
                printf("The matrix is Upper Triangular\n");
                exit(0);
        }
        if(is_symmetric())
        {
                printf("The matrix is Symmetric\n");
                exit(0);
        }
}

int is_diagonal()
{
        int i,j;
        for(i=0;i<size;i++)
                for(j=0;j<size;j++)
                {
                        if(i!=j)
                        {
                                if(matrix[i][j])
                                        return 0;
                        }
                }
        return 1;
}

int is_uppertriangular()
{
        int i,j;
        for(i=0;i<size;i++)
                for(j=i+1;j<size;j++)
                {
                        if(matrix[i][j])
                                return 0;
                }
        return 1;
}

int is_symmetric()
{
        int i,j;
        for(i=0;i<size;i++)
                for(j=i;j<size;j++)
                {
                        if(matrix[i][j]!=matrix[j][i])
                                return 0;
                }
        return 1;
}