Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <utility>
- #include <cstdlib>
- #include <cstring>
- #include <fstream>
- #include <cassert>
- #include <vector>
- #include <string>
- #include <cstdio>
- #include <cmath>
- #include <queue>
- #include <ctime>
- #include <stack>
- #include <set>
- #include <map>
- #define pb push_back
- #define F first
- #define S second
- #define mp make_pair
- #define sz(c) (int)c.size()
- using namespace std;
- int n, number_of_itereations;
- double x[123], a[123][123], b[123], c[123];
- int main() {
- cout << "Please enter the number of unknowns : \n";
- cin >> n;
- cout << "Please enter the number of iterations : \n";
- cin >> number_of_iterations;
- cout<<"Please enter the right hand side constants : \n";
- for(int i = 0; i < n; i++) {
- cin >> b[i];
- }
- cout<<"Please enter the coefficients row wise : \n";
- for(int i = 0; i< n; i++) {
- x[i] = 0;
- for(int j = 0; j < n; j++) {
- cin >> a[i][j];
- }
- }
- int cnt = 1;
- while(cnt <= number_of_itereations) {
- for(int i = 0; i < n; i++) {
- c[i] = b[i];
- for(int j = 0; j < n; j++) {
- if(i != j) {
- c[i] = c[i] - a[i][j]*x[j];
- }
- }
- }
- for(int i = 0; i < n; i++) {
- x[i] = c[i]/a[i][i];
- }
- cnt++;
- }
- cout <<"The Solution is : \n";
- for(int i = 0; i < n; i++) {
- cout <<"x[" << i << "] = "<< x[i] <<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement