Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <math.h>
  4.  
  5. #define PI 3.14159
  6.  
  7. struct Number {
  8. Number(double Re, double Im) : Re(Re), Im(Im) {};
  9. Number() : Re(0), Im(0) {};
  10. double Re, Im;
  11. };
  12.  
  13. int main() {
  14. std::fstream file;
  15. int ammount;
  16. file.open("in.txt", std::ios::in);
  17. file >> ammount;
  18. Number* N = new Number[ammount];
  19.  
  20. for (int i = 0; i < ammount; i++) {
  21. file >> N[i].Re >> N[i].Im;
  22. }
  23.  
  24. Number* Cn = new Number[ammount];
  25. for (int i = 0; i < ammount; i++) {
  26. Cn[i].Re = 0;
  27. Cn[i].Im = 0;
  28. }
  29.  
  30. for (int i = 0; i < ammount; i++) {
  31. for (int j = 0; j < ammount; j++) {
  32. Cn[i].Re += N[j].Re * cos((PI * 2 * j * i) / ammount);
  33. Cn[i].Im += N[j].Re * sin((PI * 2 * j * i) / ammount);
  34. }
  35. if (Cn[i].Re < 0.01 && Cn[i].Re > -0.001) Cn[i].Re = 0;
  36. if (Cn[i].Im < 0.01 && Cn[i].Im > -0.001) Cn[i].Im = 0;
  37. std::cout << "Cn" << i << ": " << Cn[i].Re << " " << Cn[i].Im << std::endl;
  38. }
  39.  
  40. delete[] Cn;
  41. delete[] N;
  42. system("pause");;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement