
Faculty Supervisor: Al Day
Some material derived from lessons authored by
Dr. Larry Genalo
HTML documentation by: Julie Sandberg
Date last updated: 7/24/96
![]()
Subscripted Array: A systematic diagrammatical
representation of a subscripted variable
In general they are multidimensional
![]()

![]()
NOTE: Arrays are declared with the other variables in the program.
![]()
double x[5] FILE *inp; inp = fopen("input.dat", "r"); for (n = 0; n < 5; ++n) fscanf(inp, "%lf", &x[n]); fclose(inp);
NOTE: Produces a column of output because of the newline character in the format specificationdouble x[5]; FILE *outp; outp = fopen ("OUT.DAT","w"); for (n = 0; n < 5; ++n) fprintf(outp, "%10.4 f\n", x[n]); fclose (outp);
![]()
#include < stdio.h >
int main(void) {
double x[100], big;
int j=1, i;
inp = fopen("IN.DAT", "r")
for (j=0; j < 100; ++j)
fscanf (inp, "%lf", & x[j]);
big = x[0];
for (i = 1; i < 100; ++i)
if (x[i] > big) big = x[i];
printf("LARGEST VALUE = %f/n", big);
fclose(inp);
return (0);
}
How can this program be modified so that the array is placed in order?
i.e. The largest array element becomes x[0], the second largest becomes
x[1], etc.
![]()
As always, the name of the array may be different
in each module, but it must be in the same position in the list and
agree in type.
![]()
If an array is to be used in a function as an input argument only, the type qualifier const can be used. Since the array is used only for input, the compiler doesn't need to make a copy or know the size. It can use the original.