Symmetric check for a matrix.

Discussion in 'C' started by adroit89, Jan 6, 2007.

  1. adroit89

    adroit89 New Member

    Joined:
    Jan 5, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    A Program to check whether entered matrix is symmetric or not.
    Code:
    #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();
    }
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    clrscr() gives error in MS compilers. I am not sure about the other compilers.
     
  3. Peter_APIIT

    Peter_APIIT New Member

    Joined:
    Apr 11, 2007
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Malaysia
    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.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    conio.h is supported by the VC compiler but its just some functions which are obsolete.
     
  5. Peter_APIIT

    Peter_APIIT New Member

    Joined:
    Apr 11, 2007
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Malaysia
    Then how to add the clrscr() function so that the VS compiler can accessed the header file.

    Thanks for your help.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    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.
     
  7. Peter_APIIT

    Peter_APIIT New Member

    Joined:
    Apr 11, 2007
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Malaysia
    Thanks for your help.
     
  8. billu

    billu New Member

    Joined:
    Sep 23, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Sep 23, 2009
  9. kiddo

    kiddo New Member

    Joined:
    Apr 11, 2009
    Messages:
    65
    Likes Received:
    1
    Trophy Points:
    0
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice