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.
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();
}
Go4Expert Founder
7Jan2007,07:12   #2
shabbir's Avatar
clrscr() gives error in MS compilers. I am not sure about the other compilers.
Contributor
12Apr2007,10:41   #3
Peter_APIIT's Avatar
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.
Go4Expert Founder
12Apr2007,10:48   #4
shabbir's Avatar
conio.h is supported by the VC compiler but its just some functions which are obsolete.
Contributor
12Apr2007,17:59   #5
Peter_APIIT's Avatar
Then how to add the clrscr() function so that the VS compiler can accessed the header file.

Thanks for your help.
Go4Expert Founder
12Apr2007,18:00   #6
shabbir's Avatar
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.
Contributor
12Apr2007,18:03   #7
Peter_APIIT's Avatar
Thanks for your help.
Newbie Member
23Sep2009,19:03   #8
billu's Avatar
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
Contributor
17Nov2009,07:56   #9
kiddo's Avatar
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.