input data:- 56200.28 12300.36 67800.98 68700.68 59300.43 65778.29 67900.94 2340
ID: 3827360 • Letter: I
Question
input data:-
56200.28 12300.36 67800.98 68700.68 59300.43 65778.29
67900.94 23400.67 89000.52 87900.90 34500.88 36549.45
45600.89 54300.12 56700.45 45800.39 66700.88 76543.24
35600.12 86400.97 67300.51 85900.71 12300.69 26574.27
45678.13 65437.78 76312.14 38765.87 34598.53 65487.89
--------
This is what i have done so far, and it gives me errors:-
-----------------------------------------------------------------------------------------------
#include <stdio.h>
const int ARSIZE = 5;
const int CSIZE = 6;
FILE *inptr, *outptr;
void fninput(float [ ][CSIZE]);
void fncompute(float [ ][CSIZE], float [ ][CSIZE]);
void fnrowcolumnsums(float [ ][CSIZE], float [ ], float [ ]);
void fnoutput(float [ ][CSIZE]);
int main( )
{
float depth[RSIZE][CSIZE], avdepthrsum[RSIZE], avsepthcsum[CSIZE];
float pressure[RSiZE][CSIZE];
inptr = fopen("proj7in.dat", "r");
outptr = fopen("proj7out.dat", "w");
fninput(depth);
fncompute(depth, pressure);
fprintf(outptr," DEPTH ARRAY ");
fprintf(outptr," ============ ");
fnoutput(depth);
fprintf(outptr," PRESSURE ARRAY ");
fprintf(outptr," ============= ");
fnrowcolumnsums[pressure,
fnoutput(pressure, avpressuresum, avpressurecsum);
return 0;
}
/**********************************************************/
/* */
/* ARRAY DEPTH INPUT FUNCTION */
/* */
/**********************************************************/
void fninput(float d[ ][CSIZE])
{
int i, j;
for(i = 0; i < RSIZE; i++)
{
for(j = 0; j < CSIZE; j++)
{
fscanf(inptr, "%f ", &d[i][j]);
}
}
}
void fnoutput(float d[ ][CSIZE], float p[ ][CSIZE]);
{
void fninput(float d[ ][CSIZE])
{
int i, j;
for(i = 0; i < RSIZE; i++)
{
for(j = 0; j < CSIZE; j++)
{
p[i][j] = 0.4333 * d[i][j];
/**********************************************************/
/* */
/* COMPUTE THE PRESSURE ARRAY */
/* */
/**********************************************************/
void fmcompute(float d[ ][CSIZE], float p[ ][CSIZE]
{
int i, j;
for(i = 0; i < RSIZE; i++)
{
for(j = 0; j < CSIZE; j++)
------------------------
void fnrowcolmsums(float x[ ][CSIZE], float xrsum[RSIZE], float xcsum[CSIZE])
{
int i, j;
for(i= 0; i < RSIZE; i++)
{
for(j = 0; j < CSIZE; j++)
{
*(xrsum + i) = *(xrsum + i) + *(*x + i)+ j));
}
*(xrsum + i) = *(xrsum + i) / CSIZE;
}
for(j = 0; j < CSIZE; j++)
{
*(xrsum + i) = 0.0;
for
/**********************************************************/
/* */
/* ARRAY DEPTH OUTPUT FUNCTION */
/* */
/**********************************************************/
void fnoutput(float x[ ][CSIZE], float avxsum[RSIZE], float avxcsum[CSIZE])
{
int i, j
for(i = 0; i < RSIZE; i++)
{
for(j = 0; j < CSIZE; j++)
{
fprintf(outptr, "%10.2f ", x[i][j]);
}
fprintf(outptr, "%12.2f ", avxrsum[i]);
}
for( j = 0; j < CSIZE; j++)
{
fprintf(outptr, "%12.2f ", avxcsum[j]);
}
}
Explanation / Answer
#include <stdio.h>
const int RSIZE = 5;
const int CSIZE = 6;
const float constant_p = .4333;
FILE *inptr, *outptr;
void fninput(float[][CSIZE]);
void fncompute(float[][CSIZE], float[][CSIZE]);
void fnrowcolumnsums(float[][CSIZE], float[], float[]);
void fnoutput(float[][CSIZE], float[], float[]);
int main()
{
float depth[RSIZE][CSIZE], avdepthrsum[RSIZE], avsepthcsum[CSIZE];
float pressure[RSIZE][CSIZE];
float avgpressure_rsum[RSIZE], avgpressure_csum[CSIZE];
fopen_s(&inptr,"proj7in.txt","r");
fopen_s(&outptr,"proj7out.txt", "w");
fninput(depth);
fncompute(depth, pressure);
fnrowcolumnsums(depth, avdepthrsum, avsepthcsum);
fnrowcolumnsums(pressure, avgpressure_rsum, avgpressure_csum);
fprintf(outptr, " DEPTH ARRAY ");
fprintf(outptr, " ============ ");
fnoutput(depth, avdepthrsum, avsepthcsum);
fprintf(outptr, " PRESSURE ARRAY ");
fprintf(outptr, " ============= ");
fnoutput(pressure, avgpressure_rsum, avgpressure_csum);
return 0;
}
/**********************************************************/
/* */
/* ARRAY DEPTH INPUT FUNCTION */
/* */
/**********************************************************/
void fninput(float d[][CSIZE])
{
int i, j;
for (i = 0; i < RSIZE; i++)
{
for (j = 0; j < CSIZE; j++)
{
fscanf_s(inptr, "%f ", &d[i][j]);
}
}
}
/**********************************************************/
/* */
/* COMPUTE THE PRESSURE ARRAY */
/* */
/**********************************************************/
void fncompute(float d[][CSIZE], float p[][CSIZE])
{
int i, j;
for (i = 0; i < RSIZE; i++)
{
for (j = 0; j < CSIZE; j++)
{
p[i][j] = constant_p*d[i][j];
}
}
}
/**********************************************************/
/* */
/* COMPUTE THE PRESSURE/DEPTH row/col average ARRAY */
/* */
/**********************************************************/
void fnrowcolumnsums(float d[][CSIZE], float row[], float col[])
{
float col_avg = 0, row_avg = 0;
int i, j;
//for calculating row average
for (i = 0; i < RSIZE; i++)
{
row_avg = 0;
for (j = 0; j < CSIZE; j++)
{
row_avg = row_avg + d[i][j];
}
row[i] = row_avg;
}
//for calculating column average
for (i = 0; i < CSIZE; i++)
{
col_avg = 0;
for (j = 0; j < RSIZE; j++)
{
col_avg = col_avg + d[j][i];
}
col[i] = col_avg;
}
}
/**********************************************************/
/* */
/* ARRAY OUTPUT FUNCTION */
/* */
/**********************************************************/
void fnoutput(float x[][CSIZE], float avxrsum[RSIZE], float avxcsum[CSIZE])
{
int i, j;
for (i = 0; i < RSIZE; i++)
{
for (j = 0; j < CSIZE; j++)
{
fprintf(outptr, "%10.2f ", x[i][j]);
}
fprintf(outptr, " ");
}
fprintf(outptr, " Row Averages: ");
for (j = 0; j < RSIZE; j++)
fprintf(outptr, "%12.2f ", avxrsum[j]);
fprintf(outptr, " Column Averages: ");
for (j = 0; j < CSIZE; j++)
fprintf(outptr, "%12.2f ", avxcsum[j]);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.