Design a flow chart based on this C++ code #include<stdio.h> #include<math.h> #d
ID: 3844386 • Letter: D
Question
Design a flow chart based on this C++ code
#include<stdio.h>
#include<math.h>
#define PI 3.14159265
const int k = 20;
struct DFT_Coefficient {
double real, img;
};
int main(int argc, char **argv) {
const int N = 10;
float a, b, c;
int i, j;
struct DFT_Coefficient dft_val[k];
double cosine[N];
double sine[N];
printf("Discrete Fourier Transform using naive method ");
printf("Enter the coefficient of simple linear function: ");
printf("ax + by = c ");
scanf_s("%f", &a);
scanf_s("%f", &b);
scanf_s("%f", &c);
double function[N];
for (i = 0; i < N; i++) {
function[i] = (((a * (double)i) + (b * (double)i)) - c);
//System.out.print( " "+function[i] + " ");
}
for (i = 0; i < N; i++) {
cosine[i] = cos((2 * i * k * PI) / N);
sine[i] = sin((2 * i * k * PI) / N);
}
printf("The coefficients are: ");
for (j = 0; j < k; j++) {
for (i = 0; i < N; i++) {
dft_val[j].real += function[i] * cosine[i];
dft_val[j].img += function[i] * sine[i];
}
printf("( %e ) - ( %e i) ", dft_val[j].real, dft_val[j].img);
}
return 0;
}
Explanation / Answer
Solution:-
First of all please note that we have run this entire program and we got output as and flow chart is also shown below:-
Flow chart structure is as follows. Please just put it in box and flow chart is all ready.
1) Start
2) const no. N= 10;
3) Let the iniitial numbers are a, b, c, i and j
4) double cosine constant value N & double sine constant value N
5) If i < N ----> YES then
function[i] = (((a * (double)i) + (b * (double)i)) - c)
cosine[i] = cos((2 * i * k * PI) / N)
sine[i] = sin((2 * i * k * PI) / N)
Then coefficients are -----
6) If j < k and i <N then
val[j] real= function[i] * cosine[i];
val[j] img = function[i] * sine[i];
7) If above is true then printf("val[j] real, val[j] img)
Otherwise
8) Value is zero
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.