lucacodorean

Untitled

Mar 17th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<cmath>
  4. using namespace std;
  5. ifstream fin("complex.in");
  6. ofstream fout("complex.out");
  7. struct complex
  8. {
  9.     double re,im;
  10. } z;
  11. void citire(struct complex &z)
  12. {
  13.     fin>>z.re>>z.im;
  14. }
  15. void maxim(struct complex z1,struct complex z2)
  16. {
  17.     double ma1=0,ma2=0;
  18.     ma1+=sqrt((z1.re*z1.re)+(z1.im*z1.im));
  19.     ma2+=sqrt((z2.re*z2.re)+(z2.im*z2.im));
  20.     if(ma1>ma2)
  21.     {
  22.         fout<<z1.re;
  23.         if(z1.im<0)
  24.         {
  25.             fout<<'-'<<z1.im;
  26.         }
  27.         else if(z1.im>=1)
  28.         {
  29.             fout<<'+'<<-z1.im;
  30.         }
  31.     }
  32.     else
  33.     {
  34.         fout<<z2.re;
  35.         if(z2.im<0)
  36.         {
  37.             fout<<'-'<<z2.im;
  38.         }
  39.         else if (z2.im>=1)
  40.         {
  41.             fout<<'+'<<z2.im;
  42.         }
  43.     }
  44. }
  45. int main()
  46. {
  47.     complex z1,z2;
  48.     citire(z1);
  49.     citire(z2);
  50.     maxim(z1,z2), fout<<"*i";
  51.     fin.close();
  52.     fout.close();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment