Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main() {
- double matrix[3][3], fs[3], dsm[3][2][2], pdet[3], det[3], determinant; int i, j, m, l; char a;
- for (i = 0; i < 3; i++) {
- for (j = 0; j < 3; j++) {
- std::cout << "Enter " << i + 1 << "," << j + 1 << " element of matrix: ";
- std::cin >> matrix[i][j];
- }
- }
- std::cout << "Do you matrix look like:" << std::endl;
- do {
- for (i = 0; i<3; i++) {
- for (j = 0; j < 3; j++) {
- std::cout << matrix[i][j] << " ";
- }
- std::cout << std::endl;
- }
- std::cout << "You should enter answer (y/n): ";
- std::cin >> a;
- if (a != 'y' && a != 'n') {
- std::cout << "You didn't answer" << std::endl;
- }
- else if (a == 'n') {
- std::cout << "What element is incorrect?" << std::endl;
- do {
- std::cout << "Please enter string number: ";
- std::cin >> i;
- if (i > 3 || i < 1) {
- std::cout << "Error. Incorrect number. Try again." << std::endl;
- }
- } while (i > 3 || i < 1);
- i = i - 1;
- do {
- std::cout << "Please enter column number: ";
- std::cin >> j;
- if (j > 3 || j < 1) {
- std::cout << "Error. Incorrect number. Try again." << std::endl;
- }
- } while (j > 3 || j < 1);
- j = j - 1;
- std::cout << "Please enter correct value: ";
- std::cin >> matrix[i][j];
- std::cout << "Now right?" << std::endl;
- }
- } while (a == 'n' || a != 'y');
- for (m = 0; m < 3; m++) {
- for (j = m; j < m + 1; j++) {
- if (m % 2 == 0) {
- fs[m] = matrix[0][j];
- }
- else {
- fs[m] = -matrix[0][j];
- }
- }
- }
- i = 0; j = -1; m = -1; l = -1;
- while (true) {
- m = m + 1;
- if (m == 3) { m = -1; break; }
- while (true) {
- i = i + 1;
- if (i == 3) { i = 0; break; }
- while (true) {
- j = j + 1;
- if (j == 3) { j = -1; l = -1; break; }
- else if (j == m) { continue; }
- l = l + 1;
- dsm[m][i - 1][l] = matrix[i][j];
- }
- }
- }
- for (m = 0; m < 3; m++) {
- i = 1; j = 1;
- pdet[m] = dsm[m][i - 1][j - 1] * dsm[m][i][j] - dsm[m][i - 1][j] * dsm[m][i][j - 1];
- det[m] = pdet[m] * fs[m];
- }
- determinant = det[0] + det[1] + det[2];
- std::cout << "Determinant is " << determinant << std::endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment