I need to write a small function to populate a 2D array from the 1D array called array. My array needs to be in this format and the remaining values need to be calculated by dividing the value on the left by the corresponding value on the top i.e. element x will be 0.64/.99. Any ideas gratefully received. Thank you
1 0.99 0.64 121.42 4.65
0.99 x
0.64
121.42
4.65
#include <stdio.h>
#define DATA_FILE "rates.txt"
void get_data(double array[5]);
void main(void)
{
double array[5];
get_data(array);
}
/*sub-program*/
/*Fills the array with data from file q1new.txt */
void get_data (double array [5])
{
int i;
FILE *fp;
fp = fopen(DATA_FILE, "r"
for (i=0; i < 5; ++i)
fscanf ( fp, "%lf", &array );
fclose(fp);
}
}
1 0.99 0.64 121.42 4.65
0.99 x
0.64
121.42
4.65
#include <stdio.h>
#define DATA_FILE "rates.txt"
void get_data(double array[5]);
void main(void)
{
double array[5];
get_data(array);
}
/*sub-program*/
/*Fills the array with data from file q1new.txt */
void get_data (double array [5])
{
int i;
FILE *fp;
fp = fopen(DATA_FILE, "r"
for (i=0; i < 5; ++i)
fscanf ( fp, "%lf", &array );
fclose(fp);
}
}