Advertisement
Guest User

cuda

a guest
Dec 5th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <utility>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <fstream>
  7. #include <cassert>
  8. #include <vector>                              
  9. #include <string>
  10. #include <cstdio>
  11. #include <cmath>
  12. #include <queue>
  13. #include <ctime>
  14. #include <stack>
  15. #include <set>
  16. #include <map>
  17.  
  18.  
  19. #define pb push_back
  20. #define F first
  21. #define S second
  22. #define mp make_pair
  23. #define sz(c) (int)c.size()
  24.  
  25. using namespace std;
  26.  
  27. int n, number_of_itereations;
  28. double x[123], a[123][123], b[123], c[123];
  29.  
  30. int main() {
  31.    
  32.     cout << "Please enter the number of unknowns : \n";
  33.     cin >> n;
  34.    
  35.     cout << "Please enter the number of iterations : \n";
  36.     cin >> number_of_iterations;
  37.    
  38.     cout<<"Please enter the right hand side constants : \n";
  39.     for(int i = 0; i < n; i++) {
  40.         cin >> b[i];
  41.     }
  42.    
  43.     cout<<"Please enter the coefficients row wise : \n";
  44.     for(int i = 0; i< n; i++) {
  45.         x[i] = 0;
  46.         for(int j = 0; j < n; j++) {
  47.             cin >> a[i][j];
  48.         }
  49.     }
  50.    
  51.     int cnt = 1;
  52.    
  53.     while(cnt <= number_of_itereations) {
  54.         for(int i = 0; i < n; i++) {
  55.             c[i] = b[i];
  56.             for(int j = 0; j < n; j++) {
  57.                 if(i != j) {
  58.                     c[i] = c[i] - a[i][j]*x[j];
  59.                 }
  60.             }
  61.         }
  62.         for(int i = 0; i < n; i++) {
  63.             x[i] = c[i]/a[i][i];
  64.         }
  65.         cnt++;
  66.     }
  67.    
  68.     cout <<"The Solution is : \n";
  69.     for(int i = 0; i < n; i++) {
  70.         cout <<"x[" << i << "] = "<< x[i] <<"\n";
  71.     }
  72.    
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement