Advertisement
Tobiasz931

Big Fucking Gauss' Gun

Mar 19th, 2013
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <math.h>
  6.  
  7. using namespace std;
  8.  
  9. void wypisz(double**,int);
  10.  
  11. int main(){
  12.     cout.precision(16);
  13.     int n;
  14.     cout<<"podaj n"<<endl;
  15.     cin>>n;
  16.     cout << endl;
  17.     double **tab;
  18.     double *A;
  19.    
  20.     time_t now;
  21.     time(&now);
  22.     srand((unsigned int)now);
  23.  
  24.     tab=new double*[n];
  25.     for (int i=0;i<n;i++){
  26.         tab[i]=new double[n+1];
  27.     }
  28.     A=new double[n];
  29.     for(int i=0; i<n; i++){
  30.         //A[i]=pow(2.0f, rand()%10);
  31.         //A[i]=rand()%20-10;
  32.         A[i]=rand()/101.931;
  33.         cout << A[i] << endl;
  34.     }
  35.     for (int i=0;i<n;i++){
  36.         double temp=0;
  37.         for (int j=0;j<n;j++){
  38.             //tab[i][j]=pow(2.0f, rand()%10);
  39.             //tab[i][j]=rand()%20-10;
  40.             tab[i][j]=rand()/49.001;
  41.             temp+=tab[i][j]*A[j];
  42.         }
  43.         tab[i][n]=temp;
  44.     }
  45.     for(int y=0; y<n; y++){
  46.         double mnoznik=1/tab[y][y];
  47.         for (int x=y;x<n+1;x++){
  48.             tab[y][x]*=mnoznik;
  49.         }
  50.         for(int w=y+1; w<n; w++){
  51.             double mnoznik=tab[w][y]/tab[y][y];
  52.             for(int x=0; x<n+1; x++){
  53.                 tab[w][x]-=tab[y][x]*mnoznik;
  54.             }
  55.         }
  56.     }
  57.     for(int y=n-1; y>=0; y--){
  58.         for(int w=y-1; w>=0; w--){
  59.             tab[w][n]-=tab[y][n]*tab[w][y];
  60.             tab[w][y]=0;
  61.         }
  62.     }
  63.     cout << endl << endl;
  64.     for(int i=0; i<n; i++)
  65.         cout << tab[i][n] << endl;
  66.     return 0;
  67. }
  68.  
  69. void wypisz(double **tab, int n){
  70.     cout<<endl;
  71.     for (int i=0;i<n;i++){
  72.         for (int j=0;j<n+1;j++){
  73.             cout<<tab[i][j]<<"  ";
  74.         }
  75.         cout<<endl;
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement