Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Algorytm eliminacji Gaussa Jordana */
- #include<iostream>
- #include<conio.h>
- using namespace std;
- int main()
- {
- int i, j, k, n;
- float a[10][10] = { 0 }, x;
- cout << " Algorytm eliminacji Gaussa Jordana " << endl <<endl ;
- cout << "Podaj ilosc rownan: ";
- cin >> n;
- cout << endl << "Wpisz macierz: " << endl;
- for (i = 1; i <= n; i++)
- for (j = 1; j <= n; j++)
- cin >> a[i][j];
- for (i = 1; i <= n; i++)
- for (j = 1; j <= 2 * n; j++)
- if (j == (i + n))
- a[i][j] = 1;
- cout << endl;
- /* czesciowe odwracanie */
- for (i = n; i > 1; i--)
- {
- if (a[i - 1][1] < a[i][1])
- for (j = 1; j <= n * 2; j++)
- {
- x = a[i][j];
- a[i][j] = a[i - 1][j];
- a[i - 1][j] = x;
- }
- }
- cout << "Odwrocone: " << endl;
- for (i = 1; i <= n; i++)
- {
- for (j = 1; j <= n * 2; j++)
- cout << a[i][j] << " ";
- cout << endl;
- }
- /* Redukcja */
- for (i = 1; i <= n; i++)
- {
- for (j = 1; j <= n * 2; j++)
- if (j != i)
- {
- x = a[j][i] / a[i][i];
- for (k = 1; k <= n * 2; k++)
- a[j][k] -= a[i][k] * x;
- }
- }
- /* Redukcja */
- for (i = 1; i <= n; i++)
- {
- x = a[i][i];
- for (j = 1; j <= n * 2; j++)
- a[i][j] = a[i][j] / x;
- }
- cout << endl <<"Twoj wynik to: " << endl;
- for (i = 1; i <= n; i++)
- {
- for (j = n + 1; j <= n * 2; j++)
- cout << a[i][j] << " | ";
- cout << endl;
- }
- cout << endl << "Aby zamknac nacisnij Enter";
- getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment