Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <math.h>
- #define PI 3.14159
- struct Number {
- Number(double Re, double Im) : Re(Re), Im(Im) {};
- Number() : Re(0), Im(0) {};
- double Re, Im;
- };
- int main() {
- std::fstream file;
- int ammount;
- file.open("in.txt", std::ios::in);
- file >> ammount;
- Number* N = new Number[ammount];
- for (int i = 0; i < ammount; i++) {
- file >> N[i].Re >> N[i].Im;
- }
- Number* Cn = new Number[ammount];
- for (int i = 0; i < ammount; i++) {
- Cn[i].Re = 0;
- Cn[i].Im = 0;
- }
- for (int i = 0; i < ammount; i++) {
- for (int j = 0; j < ammount; j++) {
- Cn[i].Re += N[j].Re * cos((PI * 2 * j * i) / ammount);
- Cn[i].Im += N[j].Re * sin((PI * 2 * j * i) / ammount);
- }
- if (Cn[i].Re < 0.01 && Cn[i].Re > -0.001) Cn[i].Re = 0;
- if (Cn[i].Im < 0.01 && Cn[i].Im > -0.001) Cn[i].Im = 0;
- std::cout << "Cn" << i << ": " << Cn[i].Re << " " << Cn[i].Im << std::endl;
- }
- delete[] Cn;
- delete[] N;
- system("pause");;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement