Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/articles/c-tutorials/)
-   -   Symmetric check for a matrix. (http://www.go4expert.com/articles/symmetric-check-matrix-t2453/)

adroit89 6Jan2007 19:45

Symmetric check for a matrix.
 
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();
}


shabbir 7Jan2007 07:12

Re: Symmetric check for a matrix.
 
clrscr() gives error in MS compilers. I am not sure about the other compilers.

Peter_APIIT 12Apr2007 10:41

Re: Symmetric check for a matrix.
 
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.

shabbir 12Apr2007 10:48

Re: Symmetric check for a matrix.
 
conio.h is supported by the VC compiler but its just some functions which are obsolete.

Peter_APIIT 12Apr2007 17:59

Re: Symmetric check for a matrix.
 
Then how to add the clrscr() function so that the VS compiler can accessed the header file.

Thanks for your help.

shabbir 12Apr2007 18:00

Re: Symmetric check for a matrix.
 
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.

Peter_APIIT 12Apr2007 18:03

Re: Symmetric check for a matrix.
 
Thanks for your help.

billu 23Sep2009 19:03

Re: Symmetric check for a matrix.
 
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();
}


kiddo 17Nov2009 07:56

Re: Symmetric check for a matrix.
 
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.


All times are GMT +5.5. The time now is 07:36.