Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- void wypisz(int** t,int N,int M)
- {
- for(int w=0;w<N;w++)
- {
- for(int k=0;k<M;k++)
- {
- cout << t[w][k] << "\t";
- }
- cout << endl;
- }
- }
- int** losuj(int N,int M)
- {
- int** t=new int*[N];
- for(int i=0;i<N;i++)
- {
- t[i]=new int[M];
- }
- for(int w=0;w<N;w++)
- {
- for(int k=0;k<M;k++)
- {
- t[w][k]=rand()%10;
- }
- }
- return t;
- }
- int** pomnoz(int **t,int N,int M,int a)
- {
- int** t2=new int*[N];
- for(int i=0;i<N;i++)
- {
- t2[i]=new int[M];
- }
- for(int w=0;w<N;w++)
- {
- for(int k=0;k<M;k++)
- {
- t2[w][k]=t[w][k]*a;
- }
- }
- return t2;
- }
- float srednia(int **t,int N,int M)
- {
- float s=0;
- for(int w=0;w<N;w++)
- {
- for(int k=0;k<M;k++)
- {
- s+=t[w][k];
- }
- }
- return s/(N*M);
- }
- int maks(int **t,int N,int M)
- {
- int m=t[0][0];
- for(int w=0;w<N;w++)
- {
- for(int k=0;k<M;k++)
- {
- if(t[w][k]>m)
- m=t[w][k];
- }
- }
- return m;
- }
- int mini(int **t,int N,int M)
- {
- int m=t[0][0];
- for(int w=0;w<N;w++)
- {
- for(int k=0;k<M;k++)
- {
- if(t[w][k]<m)
- m=t[w][k];
- }
- }
- return m;
- }
- int** dodaj(int **t1,int **t2,int N,int M)
- {
- int** t3=new int*[N];
- for(int i=0;i<N;i++)
- {
- t3[i]=new int[M];
- }
- for(int w=0;w<N;w++)
- {
- for(int k=0;k<M;k++)
- {
- t3[w][k]=t1[w][k]+t2[w][k];
- }
- }
- return t3;
- }
- int** odejmij(int **t1,int **t2,int N,int M)
- {
- int** t3=new int*[N];
- for(int i=0;i<N;i++)
- {
- t3[i]=new int[M];
- }
- for(int w=0;w<N;w++)
- {
- for(int k=0;k<M;k++)
- {
- t3[w][k]=t1[w][k]-t2[w][k];
- }
- }
- return t3;
- }
- int** pomnoz(int **t1,int **t2,int N,int M, int L)
- {
- int** t3=new int*[N];
- for(int i=0;i<N;i++)
- {
- t3[i]=new int[L];
- }
- for(int w=0;w<N;w++)
- {
- for(int k=0;k<L;k++)
- {
- t3[w][k]=0;
- for(int i=0;i<M;i++)
- {
- t3[w][k]+=t1[w][i]*t2[i][k];
- }
- }
- }
- return t3;
- }
- int wyznacznik(int **t,int N)
- {
- if(N==2)
- {
- return t[0][0]*t[1][1]-t[0][1]*t[1][0];
- }
- else if(N==1)
- {
- return t[0][0];
- }
- else if(N==3)
- {
- return t[0][0]*t[1][1]*t[2][2];
- }
- }
- char wyborDzialania()
- {
- char x;
- cout << "podaj dzialanie: + dodawanie, - odejmowanie, * mnozenie, d wyznacznik, k koniec" << endl;
- cin >> x;
- return x;
- }
- int main()
- {
- char x='a';
- while(x!='k')
- {
- int a,b,c,d;
- x=wyborDzialania();
- int **A;
- int **B;
- if(x=='+' || x=='-' || x=='*')
- {
- cout << "podaj wymiary pierwszej macierzy" << endl;
- cin >> a;
- cin >> b;
- cout << "podaj wymiary drugiej macierzy" << endl;
- cin >> c;
- cin >> d;
- A=new int*[a];
- for(int i=0;i<a;i++)
- {
- A[i]=new int[b];
- }
- B=new int*[c];
- for(int i=0;i<c;i++)
- {
- B[i]=new int[d];
- }
- cout << "podaj wspolczynniki 1 macierzy (wierszami)" << endl;
- for(int w=0;w<a;w++)
- {
- cout << "Wiersz: " << w+1 << endl;
- for(int k=0;k<b;k++)
- {
- cin >> A[w][k];
- }
- }
- cout << "podaj wspolczynniki 2 macierzy (wierszami)" << endl;
- for(int w=0;w<c;w++)
- {
- cout << "Wiersz: " << w+1 << endl;
- for(int k=0;k<d;k++)
- {
- cin >> B[w][k];
- }
- }
- }
- else if(x!='k')
- {
- cout << "podaj wymiary macierzy" << endl;
- cin >> a;
- cin >> b;
- A=new int*[a];
- for(int i=0;i<a;i++)
- {
- A[i]=new int[b];
- }
- cout << "podaj wspolczynniki macierzy (wierszami)" << endl;
- for(int w=0;w<a;w++)
- {
- cout << "Wiersz: " << w+1 << endl;
- for(int k=0;k<b;k++)
- {
- cin >> A[w][k];
- }
- }
- }
- if(x=='p')
- {
- int l;
- cout << "podaj liczbe" << endl;
- cin >> l;
- }
- if(x=='+')
- {
- if(a==c && b==d)
- {
- cout << "suma macierzy: " << endl;
- wypisz(A,a,b);
- cout << "i macierzy: " << endl;
- wypisz(B,c,d);
- cout << "wynosi: " << endl;
- wypisz(dodaj(A,B,a,b),a,b);
- }
- else
- cout << "wymiary sie nie zgadzaja" << endl;
- }
- else if(x=='-')
- {
- }
- else if(x=='*')
- {
- }
- else if(x=='d')
- {
- if(a==b)
- {
- cout << "wyznacznik macierzy: " << endl;
- wypisz(A,a,b);
- cout << "wynosi: " << wyznacznik(A,a) << endl;
- }
- else
- cout << "macierz nie jest kwadratowa" << endl;
- }
- else if(x=='p')
- {
- }
- else if(x=='k')
- {
- cout << "dziekuje za uwage" << endl;
- }
- else
- {
- cout << "wprowadziles zly znak" << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement