Tuesday, February 13, 2024

21. WAP to implement Symmetric Matrix using one-dimensional array.

 21. WAP to implement Symmetric Matrix using one-dimensional array.


PROGRAME CODE

#include<stdio.h>

#include<iostream>

using namespace std;

class symmetric{

                int arr[50][50],row,col,arr1[50][50],arr2[100];

                public:

                                symmetric(){

                                                row=0;

                                                col=0;

                                }

                                void getdata(){

                                                cout<<"ENTER THE VALUE OF THE ROW ......."<<endl;

                                                cin>>row;

                                                cout<<"ENTER THE VALUE OF THE COLOM ......."<<endl;

                                                cin>>col;

                                                cout<<"ENTER THE ELEMENTS OF THE MATRIX ......."<<endl;

                                                for(int i=0;i<row;i++){

                                                                for(int j=0;j<col;j++)

                                                                                cin>>arr[i][j];

                                                }

                                                if(check())

                                                                cout<<"THE MATRIX IS A SYMMETRIC MATRIX ....."<<endl;

                                                else

                                                                cout<<"THE MATRIX IS A ASYMMETRIC MATRIX....."<<endl;

                                }

                                int check(){

                                                int m=0,n=0,r=0,q=0;

                                                for(int i=0;i<row;i++){

                                                                for(int j=0;j<col;j++)

                                                                                                arr1[j][i]=arr[i][j];

                                                }

                                                for(int k=0;k<row;k++){

                                                                for(int l=0;l<col;l++){

                                                                                if(arr[k][l]!=arr1[k][l])

                                                                                                return 0;

                                                                }

                                                }

                                                return 1;

                                }

                                void dispaly(){

                                                for(int i=0;i<row;i++){

                                                                for(int j=0;j<col;j++)

                                                                                cout<<arr[i][j]<<"  ";

                                                                cout<<endl;

                                                }                                             

                                }

                                void present_sym(){

                                                int k=0;

                                                for(int i=0;i<row;i++){

                                                                for(int j=0;j<col;j++){

                                                                                arr2[k]=arr[i][j];

                                                                                k++;

                                                                }

                                                }

                                                cout<<"THE SYMMETRIC ELEMENTS ARE ->"<<endl;

                                                for(int p=0;p<(row*col);p++)

                                                                cout<<arr2[p]<<"  ";

                                                cout<<endl;

                                }

};

int main(){

                symmetric ob;

                int opt=0;

                do{

                                cout<<"\nPRESS 0 TO EXIT ........"<<endl;

                                cout<<"PRESS 1 TO ENTER DATA ......."<<endl;

                                cout<<"PRESS 2 TO DISPLAY MATRIX ....."<<endl;

                                cout<<"PRESS 3 TO DISPLAY ALL SYMMETRIC ELEMENTS ......"<<endl;

                                cin>>opt;

                                switch(opt){

                                                case 0:

                                                                break;

                                                case 1:

                                                                ob.getdata();

                                                                break;

                                                case 2:

                                                                ob.dispaly();

                                                                break;

                                                case 3:

                                                                ob.present_sym();

                                                                break;

                                                default:

                                                                cout<<"ERROR CHOICE ........."<<endl;

                                }

                }while(opt!=0);

                return 0;

}


No comments:

Post a Comment