C program- To check if matrix is symmetric

Posted: January 13, 2012 in Lab 1
#include<stdio.h>
int symmcheck(int *, int,int);
int symmcheck(int *k, int row, int col)
{
	int i,j,mat[2][2],x=0;
	for(i=0;i<row;i++)
		for(j=0;j<col;j++)
      {
		
			mat[i][j]=*(k+i*col+j);
		
	}
for(i=0;i<row;i++)
		for(j=0;j<col;j++)
			//printf("%d\n",mat[i][j]);

for(i=0;i<row;i++)
		for(j=0;j<col;j++)
	if(mat[i][j]!=mat[j][i])
				x++;
	if(x==0)
		printf("symmetric");
	else
		printf("not symmetric");
}
int main()
{
	int i,j,r,c;
	printf("Enter no. of rows and columns\n");
	scanf("%d%d",&r,&c);
	int arr[r][c];
	printf("Enter elements\n");
for(i=0;i<r;i++)
		for(j=0;j<c;j++)
			scanf("%d",&arr[i][j]);
	symmcheck(&arr[0][0],r,c);
	return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s