Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PO(funkcje zaprzyjaznione - macierz):
- #include <iostream>
- #include <math.h>
- using namespace std;
- class macierz
- {
- float a[3][3];
- public:
- macierz(float b[3][3])
- {
- for(int i=0;i<3;i++) for(int j=0;j<3;j++) a[i][j]=b[i][j];
- }
- friend void wyswietl(macierz);
- friend float suma(macierz);
- friend void norma(macierz);
- };
- float suma(macierz m)
- {
- float s=0;
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- s+=m.a[i][j];
- }
- }
- return s;
- }
- void wyswietl(macierz m)
- {
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- cout<<m.a[i][j]<<"\t";
- }
- cout<<endl;
- }
- cout<<endl;
- }
- void norma(macierz m)
- {
- float n=0;
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- n+=m.a[i][j]*m.a[i][j];
- }
- }
- cout<<"Norma: "<<sqrt(n);
- }
- int main()
- {
- float q1[3][3]={{1,2,3},{3,4,5},{5,6,7}};
- macierz m1(q1);
- float q2[3][3]={{1,1,1},{0,1,0},{0,0,1}};
- macierz m2(q2);
- wyswietl(m1);
- wyswietl(m2);
- cout<<"Suma1: "<<suma(m1)<<endl;
- cout<<"Suma2: "<<suma(m2)<<endl;
- norma(m2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement