Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61069237
complexes.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, May 4, 08:24
Size
1 KB
Mime Type
text/x-c
Expires
Mon, May 6, 08:24 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17460774
Attached To
R10932 CS-119
complexes.cc
View Options
// 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
Log In to Comment