Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MNOZENIE ZESPOLONYCH
- //.h
- #ifndef NAGLOWEK_H
- #define NAGLOWEK_H
- #include<iostream>
- #include<cstdlib>
- #include<math.h>
- #include<vector>
- #include<string>
- #include<fstream>
- #include<stdio.h>
- #include<algorithm>
- #include<regex>
- #include <stdlib.h>
- #include <string>
- #include <cmath>
- #include <ctime>
- struct Zespolona{
- float Re;
- float Im;
- };
- Zespolona iloczyn(Zespolona &a, Zespolona &b);
- #endif
- //funkcje.cpp
- #include "Naglowek.h"
- using namespace std;
- Zespolona iloczyn(Zespolona &a, Zespolona &b)
- {
- // z1, z2 - mnozone liczby zespolone
- // r - rzeczywista
- // j - urojona
- // z1 * z2 = (r + j)(r + j) = r*r + r*j +j*r + j*j
- Zespolona P;
- int rr; //r*r
- int jj; //j*j
- int rj; //r*j + j*r
- int wynik;
- // nie wiem czemu [i-1] itd, ale tylko tak działało, chodzi o mnozenie dwóch sąsiednich liczb zespolonych
- rr = a.Re * b.Re;
- // to będzie oddzielnie wyswietlone z literką 'j'przy liczbie
- rj = (a.Re * b.Im) + (a.Im * b.Re);
- // MINUS PRZED NAWIASEM BO J*J = -1
- jj = -(a.Im * b.Im);
- // mozna dodac bo j*j = -1
- wynik = rr + jj;
- P.Re = wynik;
- P.Im = rj;
- return P;
- }
- //main.cpp
- #include "Naglowek.h"
- using namespace std;
- int main(){
- srand(time(NULL));
- Zespolona a, b, c;
- a.Re = rand() % 25 - 7;
- a.Im = rand() % 25 - 7;
- b.Re = rand() % 25 - 7;
- b.Im = rand() % 25 - 7;
- cout << " a = " << a.Re << " + " << a.Im << "j " << endl;
- cout << " b = " << b.Re << " + " << b.Im << "j " << endl;
- c = iloczyn(a,b);
- cout << " c = " << c.Re << " + " << c.Im << "j " << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement