Symmetric check for a matrix.

adroit89's Avatar author of Symmetric check for a matrix.
This is an article on Symmetric check for a matrix. in C.
Rated 5.00 By 1 users
A Program to check whether entered matrix is symmetric or not.
Code: C
#include<stdio.h>
#include<conio.h>
main()
{
    int a[10][10],at[10][10],k,i,j,m,n;
    clrscr();
    printf("enter the order of matrix");
    scanf("%d %d",&m,&n);
    printf("enter the matrix");
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
            scanf("%d",&a[i][j]);
    }
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
            at[i][j]=a[j][i];
    }
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            if(at[i][j]!=a[i][j])
                k=1;
        }
    }
    if(k==1)
        printf("not symmetric");
    else
        printf("symmetric");
    getch();
}
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
clrscr() gives error in MS compilers. I am not sure about the other compilers.
0
Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
Hello, shabbir. I alos facing the same problem. I have read some of the article mentioned that conio.h is a dos function. That's the MS VC++ 6.0 complaint the error.

I think the conio.h(clrscr()) is compiled in borland and Turbo++ IDE. BY the way, how to add the file so that my compiler is able to accessed the file(conio.h) in MS VC++ 6.0 .


Your help is greatly appreciated by me and others.

Thanks for your help.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
conio.h is supported by the VC compiler but its just some functions which are obsolete.
0
Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
Then how to add the clrscr() function so that the VS compiler can accessed the header file.

Thanks for your help.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
clrscr function is not defined in the header file used by the VC compiler and if you manage to use the other header file you will not be able to get the correct implementation.
0
Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
Thanks for your help.
0
billu's Avatar, Join Date: Sep 2009
Newbie Member
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10];
int i,j,n,m,sym=1;
clrscr();
printf("Enter the order of matrix\n");
scanf("%d%d",&m,&n);
if(m==n)
{
    printf("Enter the matrix elements\n");
    for(i=0;i<m;i++)
    for(j=0;j<n;j++)
    scanf("%d",&a[i][j]);

    for(i=0;i<m;i++)
    for(j=0;j<n;j++)
    {
        if(a[i][j]!=a[j][i])
        {
            sym=0;
        }
    }
    printf("Matrix\n");
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        printf("%d\t",a[i][j]);
        printf("\n");
    }

    if(sym==1)
        printf("is a symmetric matrix\n");
    else
        printf("is not a symmetric matrix\n");
}
else printf("Not a square matrix\n");
getch();
}

Last edited by shabbir; 23Sep2009 at 20:14.. Reason: Code blocks
0
kiddo's Avatar
Contributor
Instead of using clrscr() from conio.h header,
you can try "system("cls");" ( without "").

I'm using dev-C++ and it works.
clrscr() is not ANSI, so you can't use it on C++ ANSI compiler.