Advertisement
caiiiok254

Untitled

Feb 28th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. printf("\nGauss method: \n");
  2. for (int diag = 0; diag < rows - 1; diag++) {
  3. for (int k = diag + 1; k < rows; k++) {
  4. float ratio = -(array[k][diag]/array[diag][diag]);
  5. for (int l = 0; l < cols; l++) {
  6. array[k][l] += array[diag][l] * ratio;
  7. }
  8. for (int k = 0; k < rows; k++) {
  9. for (int l = 0; l < cols; l++) {
  10. if (l == cols - 1) printf(" | ");
  11. printf("%1.1f ", array[k][l]);
  12. }
  13. printf("\n");
  14. }
  15. printf("\n");
  16. }
  17. }
  18. int size = cols - 1;
  19. float *result = new float [size];
  20. result[0] = array[rows - 1][cols - 1]/array[rows - 1][cols - 2];
  21. float temp;
  22. int index_1 = 1;
  23. for (int m = rows - 2; m >= 0; m--) {
  24. int index_2 = 0;
  25. temp = -array[m][cols - 1];
  26. for (int p = cols - 2; p >= m; p--) {
  27. if (p == m) {
  28. temp /= array[m][p];
  29. result[index_1++] = -temp;
  30. }
  31. else {
  32. temp += array[m][p] * result[index_2++];
  33. }
  34. }
  35. }
  36. printf("Result: ");
  37. for (int p = size - 1; p >= 0; p--) {
  38. printf("%1.1f ", result[p]);
  39. }
  40. printf("\n\n");
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement