Page MenuHomec4science

complexes.cc
No OneTemporary

File Metadata

Created
Sat, May 4, 08:24

complexes.cc

// complexes.cc
// Auteur : Quentin Berling
// Version : 1.0
#include <iostream>
using namespace std;
struct Complexe {
double Re;
double Im;
};
void affiche(Complexe const &z);
Complexe soustraction(Complexe const &z1, Complexe const &z2);
Complexe multiplication(Complexe const &z1, Complexe const &z2);
Complexe division(Complexe const &z1, Complexe const &z2);
void affiche(Complexe const &z) {
if (z.Re != 0) {
cout << "z=" << z.Re;
if (z.Im > 0) {
cout << "+";
}
}
if (z.Im !=0) {
cout << z.Im << "i" << endl;
}
}
Complexe soustraction(Complexe const &z1, Complexe const &z2) {
Complexe z;
z.Re=z1.Re-z2.Re;
z.Im=z1.Im-z2.Im;
return z;
}
Complexe multiplication(Complexe const &z1, Complexe const &z2) {
Complexe z;
z.Re=z1.Re*z2.Re-z1.Im*z2.Im;
z.Im=z1.Re*z2.Im+z2.Re*z1.Im;
return z;
}
Complexe division(Complexe const &z1, Complexe const &z2) {
Complexe z;
z.Re=(z1.Re*z2.Re+z1.Im*z2.Im)/(z2.Re*z2.Re+z2.Im*z2.Im);
z.Im=(z2.Re*z1.Im-z1.Re*z2.Im)/(z2.Re*z2.Re+z2.Im*z2.Im);
return z;
}
int main() {
Complexe z1{3,5};
Complexe z2{7,9};
Complexe z;
z=division(z1,z2);
affiche(z);
return 0;
}

Event Timeline