Question

In: Computer Science

Q in c++ Write a program that will find the inverse of any two dimensional array...

Q in c++ Write a program that will find the inverse of any two dimensional array without the usage of the built-in function.? plz answer in while or do while loop

Solutions

Expert Solution

Points to consider:

  1. We need to find the determinant of the given matrix
  2. Then we need to find the inverse of the matrix.

Code

#include<iostream>

using namespace std;

int main(){
   int mat[3][3], i, j;
   float determinant = 0;
  
   cout<<"Enter elements of matrix row wise:\n";
   i = 0;j=0;
   while(i<3)
   {
       j = 0;
       while(j<3)
       {
           cin>>mat[i][j];
           j++;  
       }
       i++;
   }
   printf("\nGiven matrix is:");
   i = 0;j=0;
   while(i<3){
       cout<<"\n";
       j=0;
       while(j<3){
           cout<<mat[i][j]<<"\t";
           j++;  
       }
       i++;
   }
   // This following is the calculation of the determinant.
  
   i = 0;
   while(i<3)
   {
       determinant = determinant + (mat[0][i] * (mat[1][(i+1)%3] * mat[2][(i+2)%3] - mat[1][(i+2)%3] * mat[2][(i+1)%3]));
       i++;
   }
      
   cout<<"\n\ndeterminant: "<<determinant;
  
   cout<<"\n\nInverse of matrix is: \n";
   i = 0;j= 0;
   while(i<3)
   {
       j= 0;
       while(j<3)
       {
           cout<<((mat[(j+1)%3][(i+1)%3] * mat[(j+2)%3][(i+2)%3]) - (mat[(j+1)%3][(i+2)%3] * mat[(j+2)%3][(i+1)%3]))/ determinant<<"\t";
          
           j++;
       }
       cout<<"\n";
       i++;
   }
  

return 0;
}

Output

Friend, That was a nice question to answer
If you have any doubts in understanding do let me know in the comment section. I will be happy to help you further.
Please like it if you think effort deserves like.
Thanks

- O X C:\Users\visha OneDrive Documents\C++\inverse.exe FEnter elements of matrix row wise: 3 0 2 2 0 -2 0 1 1 3 Given matrix is: © 2 120 -2 0 1 1 determinant: 10 Inverse of matrix is: -0.2 0.2 0 -0.2 0.3 1 -0.2 -0.3 0 ------------------------------- - Process exited after 95.67 seconds with return value o Press any key to continue ...


Related Solutions

C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write Matrix Addition 2 D (dimensional) Array program in c++.
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data...
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: -getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. -getAverage. This method should accept a two-dimensional array as its argument and return the average of all the values in the array. -getRowTotal. This method should accept a two-dimensional array as...
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data...
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: fillRandom. Accepts a reference to a two-dimensional array and fills it with random integers from 0 to 99 formatPrint. This method should accept a two-dimensional array and print it out row by row getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in...
[C++ Coding question] write a program which inputs data to a two-dimensional array: - Input number...
[C++ Coding question] write a program which inputs data to a two-dimensional array: - Input number of rows r aand number of columns c - Create a two-dimensional array of integers int numbers[r][c] -input data for each element of numbers Your program must compute and display the largest number is each row and column of the number array
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. These methods MUST be your original code.   Your program should output all the values in the array and then output the average high and the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT