Advertisement
AntonioVillanueva

Exercice 22 nombres complexes (structures)

Nov 26th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. //Exercice 22 nombres complexes (structures) pag.60
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. struct complexe {
  7.     double x;
  8.     double y;
  9.     };
  10.    
  11. void affiche (complexe const num);
  12. complexe addition (complexe const a,complexe const b);
  13. complexe soustraction (complexe const a,complexe const b);
  14. complexe multiplication (complexe const a,complexe const b);
  15. complexe division (complexe const a,complexe const b);
  16. int main(){
  17.     complexe a{2,-3};
  18.     complexe b{1,1};
  19.     affiche (addition (a,b));
  20.     affiche (soustraction (a,b));
  21.     affiche (multiplication (a,b));
  22.     affiche (division(a,b));   
  23.  
  24. return 0;
  25. };
  26. //----------------------------------------------------------------------
  27. //----------------------------------------------------------------------
  28. void affiche (complexe const num){
  29.     cout <<'('<<num.x << ","<<num.y<<')'<<endl;
  30. }
  31. //----------------------------------------------------------------------
  32. complexe addition (complexe const a,complexe const b){
  33.     return {a.x+b.x,a.y+b.y};
  34. };
  35. //----------------------------------------------------------------------
  36. complexe soustraction (complexe const a,complexe const b){
  37.     complexe c(b);
  38.     c.x*=-1;
  39.     c.y*=-1;
  40.     return addition(a,c);
  41. }
  42. //----------------------------------------------------------------------
  43. complexe multiplication (complexe const a,complexe const b){
  44.     return {a.x*b.x -a.y*b.y,a.x*b.x+b.y*a.x}; 
  45. }
  46. //----------------------------------------------------------------------
  47. complexe division (complexe const a,complexe const b){
  48.     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)};
  49. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement