Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- #include <cstdio>
- #include <math.h>
- using namespace std;
- void wypisz(double**,int);
- int main(){
- cout.precision(16);
- int n;
- cout<<"podaj n"<<endl;
- cin>>n;
- cout << endl;
- double **tab;
- double *A;
- time_t now;
- time(&now);
- srand((unsigned int)now);
- tab=new double*[n];
- for (int i=0;i<n;i++){
- tab[i]=new double[n+1];
- }
- A=new double[n];
- for(int i=0; i<n; i++){
- //A[i]=pow(2.0f, rand()%10);
- //A[i]=rand()%20-10;
- A[i]=rand()/101.931;
- cout << A[i] << endl;
- }
- for (int i=0;i<n;i++){
- double temp=0;
- for (int j=0;j<n;j++){
- //tab[i][j]=pow(2.0f, rand()%10);
- //tab[i][j]=rand()%20-10;
- tab[i][j]=rand()/49.001;
- temp+=tab[i][j]*A[j];
- }
- tab[i][n]=temp;
- }
- for(int y=0; y<n; y++){
- double mnoznik=1/tab[y][y];
- for (int x=y;x<n+1;x++){
- tab[y][x]*=mnoznik;
- }
- for(int w=y+1; w<n; w++){
- double mnoznik=tab[w][y]/tab[y][y];
- for(int x=0; x<n+1; x++){
- tab[w][x]-=tab[y][x]*mnoznik;
- }
- }
- }
- for(int y=n-1; y>=0; y--){
- for(int w=y-1; w>=0; w--){
- tab[w][n]-=tab[y][n]*tab[w][y];
- tab[w][y]=0;
- }
- }
- cout << endl << endl;
- for(int i=0; i<n; i++)
- cout << tab[i][n] << endl;
- return 0;
- }
- void wypisz(double **tab, int n){
- cout<<endl;
- for (int i=0;i<n;i++){
- for (int j=0;j<n+1;j++){
- cout<<tab[i][j]<<" ";
- }
- cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement