--- In [email protected], "s_zhbjvd" <[EMAIL PROTECTED]> wrote:
>
> ok sir I have made a program plz tell me if it is all right and plz
> give me the brief algorithm of how to make adjoint in 3x3 matrix.
> I have a difficulty in making this program continualy work.
There is a problem in the while(num!=n) but I cant fig it out can
somebody help. I shall be very grateful.
>
>
>
>
> # include <iostream.h>
>
> int main ()
>
> {
>
> const int t = 6; //Here t is arraysize
> double A[t][t]={0};
> double B[t][t]={0};
> int row1,row2,colum1,colum2,i,j,re1,re2;
> char x;
> int y;
> char n;
> char num;
>
> //The Appearance at first sight of output
>
>
> cout<<"WELCOME TO THE WORLD OF MATRICES:"<<endl;
> cout<<endl<<endl<<endl;
>
> while (num!=n)
> {
>
>
> //For matrix A
>
> while (re1!=1)
> {
>
>
> //This will generate error if user enters a number
> which is out of limit i.e greater than six
> ///or less than Zero
>
> cout<<"Maximum number of rows & colums
> are "<<t<<endl<<endl;
> cout<<"The number of rows for matric A is ";
> cin>>row1;
> while (row1 < 0 || row1 > t || row1 ==
> 0) //Using OR statement inside while loop for
> Rows
>
> {
>
> cout<<"ERROR try entering a non zero value
> below 7"<<endl<<endl<<endl;
> cout<<"The number of rows for matric A
> is ";
> cin>>row1;
> }
> cout<<"The number of colums for matric A is ";
> cin>>colum1;
> while (colum1 < 0 || colum1 > t || colum1 ==
> 0) //Using OR statement inside while loop for Columns
> {
> cout<<"ERROR try entering a non zero value
> below 7"<<endl<<endl<<endl;
> cout<<"The number of colums for matric A
> is ";
> cin>>colum1;
> }
> cout<<endl<<endl;
>
>
>
> //Giving user the authority to enter elements of
> Matrix A
>
>
> cout<<"Enter the values for the matrices
> A"<<endl<<endl;
> for(i = 0 ; i < row1 ; i++)
> {
> for(j = 0 ; j < colum1 ; j++)
> {
> cin>>A[i][j];
> }
> }
>
>
> //////////////////////////////////////////////////////////////
> //////////////////////////////////////////
>
>
> cout<<"the matrice A is "<<endl<<endl<<endl;
> for (i = 0 ; i < row1 ; i++)
> {
> for (j = 0 ; j < colum1 ; j++)
> {
> cout<<"\t"<<A[i][j];
> cout<<"\t";
>
> }
> cout<<endl<<endl<<endl;
> }
>
>
> //////////////////////////////////////////////////////////////
> //////////////////////////////////////////
>
>
> cout<<"If you want to edit the matrice press any key
> else then n to continue"<<endl;
> cin>>x;
>
> if (x == 110)
> {
> re1=1;
> }
> }
> cout<<endl<<endl;
>
>
>
>
> //For matrix B
>
> while (re2!=1)
> {
>
>
>
> //////////////////////////////////////////////////////////////
> //////////////////////////////////////////
>
>
> cout<<"Maximum number of rows & colums
> are "<<t<<endl<<endl;
> cout<<"The number of rows for matric B is ";
> cin>>row2;
> while (row2 < 0 || row2 > t|| row2 == 0)
> {
> cout<<"ERROR try entering a non zero value
> below 7"<<endl<<endl<<endl;
> cout<<"The number of rows for matric B
> is ";
> cin>>row2;
> }
> cout<<"The number of colums for matric B is ";
> cin>>colum2;
> while (colum2 < 0 || colum2 > t || colum2 == 0)
> {
> cout<<"ERROR try entering a non zero value
> below 7"<<endl<<endl<<endl;
> cout<<"The number of colums for matric B
> is ";
> cin>>colum2;
> }
> cout<<endl<<endl;
>
>
> //Giving user the authority to enter elements of
> Matrix B
>
> cout<<"Enter the values for the matrices
> B"<<endl<<endl;
> for(i = 0 ; i < row2 ; i++)
> {
> for(j = 0 ; j < colum2 ; j++)
> {
> cin>>B[i][j];
> }
> }
>
>
> //////////////////////////////////////////////////////////////
> //////////////////////////////////////////
>
>
> cout<<"the matrice B is "<<endl<<endl<<endl;
> for (i = 0 ; i < row2 ; i++)
> {
> for (j = 0 ; j < colum2 ; j++)
> {
> cout<<"\t"<<B[i][j];
> cout<<"\t";
> }
> cout<<endl<<endl<<endl;
> }
>
>
> //////////////////////////////////////////////////////////////
> //////////////////////////////////////////
>
>
> cout<<"If you want to edit the matrice press any key
> else then n to continue"<<endl;
> cin>>x;
>
> if (x == 110)
> {
> re2=1;
> }
> }
> cout<<endl<<endl<<endl;
>
> cout<<"Press\n";
> cout<<"1.A+B\n";
> cout<<"2.A-B\n";
> cout<<"3.AxB\n";
> cout<<"4.det(A) and det(B) only 3x3\n";
>
> cin>>y;
>
> switch(y)
> {
> case 1:
>
> {
>
> //Addition of Matrix
> double anb[t][t];
>
> if (row1 == row2 && colum1 == colum2)
> {
> for (i = 0 ; i < row1 ; i++)
> {
> for(j = 0 ; j < colum1 ; j++)
> {
> anb[i][j]=A[i][j]+B[i][j];
> }
> }
> cout<<"A + B = "<<endl<<endl<<endl;
> for (i = 0 ; i < row1 ; i++)
> {
> for (j = 0 ; j < colum1 ; j++)
> {
> cout<<"\t"<<anb[i][j];
> cout<<"\t";
> }
> cout<<endl<<endl<<endl;
> }
>
> }
> else
> {
> cout<<"The order of matrix is different"<<endl;
> cout<<"Unable to perform addition"<<endl;
> cout<<"Try again"<<endl;
> cout<<endl<<endl<<endl;
> }
> break;
>
> }
>
>
>
> case 2:
> {
>
> //Subtraction of matrix A & B
>
> double aminb[t][t];
>
> if (row1 == row2 && colum1 == colum2)
> {
> for (i = 0 ; i < row1 ; i++)
> {
> for(j = 0 ; j < colum1 ; j++)
> {
> aminb[i][j]=A[i][j]-B[i][j];
> }
> }
> cout<<"A + B = "<<endl<<endl<<endl;
> for (i = 0 ; i < row1 ; i++)
> {
> for (j = 0 ; j < colum1 ; j++)
> {
> cout<<"\t"<<aminb[i][j];
> cout<<"\t";
> }
> cout<<endl<<endl<<endl;
> }
>
> }
> else
> {
>
> cout<<"The order of matrix is different"<<endl;
> cout<<"Unable to perform addition"<<endl;
> cout<<"Try again"<<endl;
> cout<<endl<<endl<<endl;
> }
> break;
> }
>
>
>
>
> case 3:
> {
>
>
> //Multiplication of Matrix A & B
>
>
> double ab[t][t] = {0};
>
> if (row1 == colum2 && row2 == colum1 && row1 < 4 && row2 < 4
> && colum1 < 4 && colum2 < 4)
> {
> ab[0][0] = A[0][0] * B[0][0] + A[0][1] * B[1][0] + A
> [0][2] * B[2][0];
> ab[0][1] = A[0][0] * B[0][1] + A[0][1] * B[1][1] + A
> [0][2] * B[2][1];
> ab[0][2] = A[0][0] * B[0][2] + A[0][1] * B[1][2] + A
> [0][2] * B[2][2];
> ab[1][0] = A[1][0] * B[0][0] + A[1][1] * B[1][0] + A
> [1][2] * B[2][0];
> ab[1][1] = A[1][0] * B[0][1] + A[1][1] * B[1][1] + A
> [1][2] * B[2][1];
> ab[1][2] = A[1][0] * B[0][2] + A[1][1] * B[1][2] + A
> [1][2] * B[2][2];
> ab[2][0] = A[2][0] * B[0][0] + A[2][1] * B[1][0] + A
> [2][2] * B[2][0];
> ab[2][1] = A[2][0] * B[0][1] + A[2][1] * B[1][1] + A
> [2][2] * B[2][1];
> ab[2][2] = A[2][0] * B[0][2] + A[2][1] * B[1][2] + A
> [2][2] * B[2][2];
>
> cout<<"A * B ="<<endl<<endl<<endl;
> for (i = 0 ; i < row1 ; i++)
> {
> for (j = 0 ; j < colum2 ; j++)
> {
> cout<<"\t"<<ab[i][j];
> cout<<"\t";
> }
> cout<<endl<<endl<<endl;
> }
> }
> else
> {
>
> cout<<"The number of rows is not equal to number of
> columns"<<endl;
> cout<<"Function cannot be performed"<<endl;
> cout<<"Try again"<<endl;
> cout<<endl<<endl<<endl;
> }
> break;
>
> }
>
>
>
>
>
> case 4:
> {
>
> /////////////
> ////////////
> //////////
> ////////FOR THREE CROSS THREE MATRIX
> //Determinent of A
>
> double deta[t][t];
>
>
> if (row1 == 3 && colum1 == 3)
>
> {
> deta[t][t] = A[0][0]*(A[1][1]*A[2][2] - A[1][2]*A[2]
> [1]) - A[0][1]*(A[1][0]*A[2][2] - A[2][0]*A[1][2]) + A[0][2]*(A[1]
[0]
> *A[2][1] - A[2][0]*A[1][1]) ;
>
> cout<< deta[t][t] << endl;
>
>
> for (i = 0 ; i < 4 ; i++)
> {
> for (j = 0 ; j < 4 ; j++)
> {
>
> cout<<" |A| = ";
> cout<<deta[i][j];
>
> cout<<endl<<endl;
>
>
> }}}
> else
> {
> cout<<"Unable to Take determinent"<<endl;
> cout<<"Enter a 3 cross 3 matrix"<<endl;
> cout<<"Try again"<<endl;
>
> }
>
>
> double detb[t][t];
>
>
>
>
> if (row2 == 3 && colum2 == 3)
>
> {
> detb[t][t] = B[0][0]*(B[1][1]*B[2][2] - B[1][2]*B[2]
> [1]) - B[0][1]*(B[1][0]*B[2][2] - B[2][0]*B[1][2]) + B[0][2]*(B[1]
[0]
> *B[2][1] - B[2][0]*B[1][1]) ;
>
> cout<<"|B| = ";
> cout<< deta[t][t] << endl;
>
>
> for (i = 0 ; i < 4 ; i++)
> {
> for (j = 0 ; j < 4 ; j++)
> {
>
> cout<<detb[i][j];
>
> cout<<endl<<endl;
>
>
> }}}
> else
> {
> cout<<"Unable to Take determinent"<<endl;
> cout<<"Enter a 3 cross 3 matrix"<<endl;
> cout<<"Try again"<<endl;
>
> }
> break;
> }
>
> default:
> cout<<"Invalid Entry";
>
> }//switch ends here
>
>
> cout<<"Press "y" to continue and "n" to exit\n";
> cin>>num;
>
> }
>
> //////////////////////////////////////////////////////////////
> //////////////////////////////////////////
> //////////////////////////////////////////////////////////////
> //////////////////////////////////////////
> //////////////////////////////////////////////////////////////
> //////////////////////////////////////////
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> return 0;
> }
>