Write a declaration statement for a 1-D array called timedata with a length of n
ID: 3807460 • Letter: W
Question
Write a declaration statement for a 1-D array called timedata with a length of n, where n is a pre-declared integer variable. (In other words, n has already been declared in advance.) (Remember, you cannot initialize variable-length arrays in a declaration statement) Write a declaration statement for a 2-D array called wavedata with a width of 2 and a length of 10. Write the same declaration, but for a 2-Darray with a width of 2 and a length of n. Write the declaration statement for a file pointer to represent wave data, and then write a file assignment statement for that pointer that opens a file, defined as a symbolic constant FILENAME, as a read file. Write a for loop that will run a total of n times, and in each iteration will read three floating point values from the pointer declared in the last question, storing the first in the array timedata and the other two in the columns of the array wavedata. (Remember that arrays in c go from subscript (0) to (n-1). Write a for loop that will run a total of n times. Use this loop to add up the values of each column of wavedata, and then find the average of each column. Write a statement that calculates the percent error between variables containing amplitude data for two separate waves. Percent Difference = |A - B/(A + B/2)| 100%Explanation / Answer
Solution:
1) int timedata[n];
2) int wavedata[10][2];
3) int wavedata[n][2];
4) FILE *wavedata
wavedata = fopen("example.txt", "r");
5) for(int i=0; i<n; i++)
{
timedata[]= *wavedata;
wavedata[10][i]= *wavedata;
}
6) for(int i=1; i<=n; i++)
{
int sum1+= wavedata[i][1];
int sum2+= wavedata[i][2];
}
avg1= sum1/n;
avg2= sum2/n;
7) percentDifference= (A-B)/((A+B)/2)*100;
if (percentDifference<0)
percentDifference= (B-A)/((A+B)/2)*100;
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.