Write a for loop that will run a total of n times and in eac
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).
Solution
Hi, Please find my implementation.
Please let me know in case of any issue.
#include <stdio.h>
#include <stdlib.h>
int main(){
int n, i;
float f1, f2, f3;
printf(\"Enter value of n: \");
scanf(\"%d\", &n);
// Lets assume that memory of following pointer is created like this
// declaring floating point array
float *timedata = (float *)malloc(n*sizeof(float));
// declaring 2-D floating pointer
float **wavedata = (float **)malloc(n);
for( i=0; i<n; i++)
*wavedata = (float *)malloc(2*sizeof(float));
// reading user input
for(i=0; i<n; i++){
printf(\"Enter 3 floating point: \ \");
scanf(\"%f%f%f\", &f1, &f2, &f3);
// storing
timedata[i] = f1;
wavedata[i][0] = f2;
wavedata[i][2] = f3;
}
return 0;
}
