Advertisement
IlincaMuresan

Tema_2(Muresan Ilinca)

Mar 21st, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<cmath>
  4. using namespace std;
  5. ifstream fin("complexe.in");
  6. ofstream fout("complexe.out");
  7. struct complex
  8. {
  9. double real;double imaginar;
  10. }z,z1,z2,v[100];
  11.  
  12. void citire(struct complex &z)
  13. {
  14. fin>>z.real>>z.imaginar;
  15. }
  16. void scriere(struct complex z)
  17. {
  18. if(z.imaginar>0)
  19. {
  20. fout<<z.real<<'+'<<z.imaginar<<"*i"<<endl;
  21. }
  22. if(z.imaginar<0)
  23. {
  24. fout<<z.real<<z.imaginar<<"*i"<<endl;
  25. }
  26. if(z.imaginar==0)
  27. {
  28. fout<<z.real<<endl;
  29. }
  30. }
  31. complex suma(struct complex z1,struct complex z2)
  32. {
  33. complex suma_elemente;
  34. suma_elemente.real=z1.real+z2.real;
  35. suma_elemente.imaginar=z1.imaginar+z2.imaginar;
  36. return suma_elemente;
  37. }
  38. complex maxim(struct complex z1,struct complex z2)
  39. {
  40.  
  41. double modul1=0,modul2=0;
  42. modul1+=sqrt((z1.real*z1.real)+(z1.imaginar*z1.imaginar));
  43. modul2+=sqrt((z2.real*z2.real)+(z2.imaginar*z2.imaginar));
  44. if(modul1>modul2)
  45. {
  46. return z1;
  47. }
  48. else
  49. {
  50. return z2;
  51. }
  52. }
  53. int modul( struct complex z)
  54. {
  55. double modul=0;
  56. modul+=sqrt((z.real*z.real)+(z.imaginar*z.imaginar));
  57. return modul;
  58. }
  59. int main()
  60. {
  61. int n,i,j;
  62. complex suma_,maxim_,aux;
  63. fin>>n;
  64. suma_={0};
  65. maxim_={0};
  66. for(i=1;i<=n;i++)
  67. {
  68. citire(z);
  69. v[i]=z;
  70. scriere(v[i]);
  71. }
  72. fout<<endl;
  73.  
  74. for(i=1;i<=n;i++)
  75. {
  76. suma_=suma(suma_,v[i]);
  77.  
  78. }
  79. scriere(suma_);
  80. fout<<endl;
  81.  
  82. for(i=1;i<n;i++)
  83. {
  84. maxim_=maxim(maxim_,v[i]);
  85. }
  86. scriere(maxim_);
  87. fout<<endl;
  88.  
  89. for(i=1;i<=n;i++)
  90. {
  91. for(j=i+1;j<=n;j++)
  92. {
  93. if(modul(v[i])>modul(v[j]))
  94. {
  95. aux=v[i];
  96. v[i]=v[j];
  97. v[j]=aux;
  98. }
  99. }
  100. }
  101. for(i=1;i<=n;i++)
  102. {
  103. scriere(v[i]);
  104. }
  105. fin.close();
  106. fout.close();
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement