Sunday, November 28, 2010

Equality of the Two Dimensional Arrays

Write a program to check the equality of an array with its transpose.

#include <iostream.h>

#include <conio.h>

void main()

{

    int a[3][3], b[3][3];

    int i, j, f;

    clrscr();

    //input array values

    for(i=0; i<3; i++)

    {

        for(j=0; j<3; j++)

            cin >> a[i][j];

    }

    //transpose occurs

    for(i=0; i<3; i++)

    {

        for(j=0; j<3; j++)

        {

            b[i][j]=a[j][i];

        }

    }

    //comparing the equality

    f=1;

    for(i=0; i<3; i++)

    {

        for(j=0; j<3; j++)

        {

            if(a[i][j]!=b[i][j])

            {

                f=0;

                break;

            }

        }

    if(j<=2)

        break;

    }

    if(f==1)

        cout << "Original and Transpose are equal!!!";

    else

        cout << "Original and Transpose are not equal...";

getch();

}

1 Comments:

Blogger Sagar alias jacky reloaded said...

thank you sir for the magic square

December 3, 2010 at 8:59 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home