#include<stdio.h>
#ifdef _WIN32
	#include<conio.h>
	#include<Windows.h>
#endif

#define domain 20 

void readfile(char fn[13],char adjacency[domain+1][domain+1]);

void main()
{
	int i,j,k,test;
	char fn[13] = "pp2-1.dat";
	char adjacencymx[domain+1][domain+1];
	char reflexivity, symmetry,transitivity;

	for(i=1;i<=domain;i++)
	{
		for(j=1;j<=domain;j++)
		{
			adjacencymx[i][j] = 0;
		}
	}
	
	/*printf("file name for read ? ");
	scanf("%s",fn);*/

	readfile(fn,adjacencymx);

	printf("\n*******************************\n\n");

	reflexivity = 1;

	for(i=1;i<=domain;i++)
	{
		if(adjacencymx[i][i] == 0)
		{
			reflexivity = 0;
			break;
		}
	}

	if(reflexivity == 1)
	{
		printf("%5cR is reflexive relation\n",' ');
	}else
	{
		printf("%5cR is not reflexive relation\n",' ');
	}

	symmetry = 1;
	test = 1;

	for(i=1;i<=domain;i++)
	{
		for(j=1;j<=domain;j++)
		{
			if(adjacencymx[i][j] == 1 && adjacencymx[j][i] == 0)
			{
				symmetry = 0;
				test = 0;
				break;
			}
		}

		if(test == 0)
		{
			break;
		}
	}

	if(symmetry == 1)
	{
		printf("%5cR is symmetric relation\n", ' ');
	}else
	{
		printf("%5cR is not symmetric relation\n", ' ');
	}


	transitivity = 1;
	test = 1;

	for(i=1;i<=domain;i++)
	{
		for(j=1;j<=domain;j++)
		{
			if(adjacencymx[i][j] == 1)
			{
				for(k=1;k<=5;k++)
				{
					if(adjacencymx[j][k] == 1 && adjacencymx[i][k] == 0)
					{
						transitivity = 0;
						test = 0;
						break;
					}
				}
				if(test == 0)
				{
					break;
				}
			}
		}
		if(test == 0)
		{
			break;
		}
	}

	if(transitivity == 1)
	{
		printf("%5cR is transitive relation\n",' ');
	}else
	{
		printf("%5cR is not transitive relation\n",' ');
	}

	system("PAUSE");
}

void readfile(char fn[13],char adjacency[domain+1][domain+1])
{
	FILE *fp;
	int x,y;
	
	fp = fopen(fn,"r");

	while(!feof(fp))
	{
		fscanf(fp,"%d %d",&x,&y);

		adjacency[x][y] = 1;
		printf("%2c(%2d, %2d)\t",' ',x,y);
	}
	fclose(fp);
}