Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Exercice 22 nombres complexes (structures) pag.60
- #include <iostream>
- using namespace std;
- struct complexe {
- double x;
- double y;
- };
- void affiche (complexe const num);
- complexe addition (complexe const a,complexe const b);
- complexe soustraction (complexe const a,complexe const b);
- complexe multiplication (complexe const a,complexe const b);
- complexe division (complexe const a,complexe const b);
- int main(){
- complexe a{2,-3};
- complexe b{1,1};
- affiche (addition (a,b));
- affiche (soustraction (a,b));
- affiche (multiplication (a,b));
- affiche (division(a,b));
- return 0;
- };
- //----------------------------------------------------------------------
- //----------------------------------------------------------------------
- void affiche (complexe const num){
- cout <<'('<<num.x << ","<<num.y<<')'<<endl;
- }
- //----------------------------------------------------------------------
- complexe addition (complexe const a,complexe const b){
- return {a.x+b.x,a.y+b.y};
- };
- //----------------------------------------------------------------------
- complexe soustraction (complexe const a,complexe const b){
- complexe c(b);
- c.x*=-1;
- c.y*=-1;
- return addition(a,c);
- }
- //----------------------------------------------------------------------
- complexe multiplication (complexe const a,complexe const b){
- return {a.x*b.x -a.y*b.y,a.x*b.x+b.y*a.x};
- }
- //----------------------------------------------------------------------
- complexe division (complexe const a,complexe const b){
- return {(a.x*b.x+a.y*b.y)/(b.x*b.x+b.y*b.y), (a.y*b.x-a.x*b.y)/(b.x * b.x +b.y*b.y)};
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement