1. ## Array help!

There are a number of ways to normalize, or scale, a set of values. One common normalization technique scales the values such that the minimum value goes to 0, the maximum value goes to 1, and other values are scaled accordingly. For example, using this normalization, we can normalize the values in the following array:

Array values
-2, -1, 2, 0

Normalized array values
0.0, 0.25, 1.0, 0.5

The equation that computes the normalized value from a value xk in the array is

Normalized xk = (xk - min)/(max - min)

where min and max represent the minimum and maximum values in the array x, respectively. If you substitute the minimum value for xk in this equation, the numerator is zero, and thus the normalized value for the minimum is zero. If you substitute the maximum value for xk in this
equation, the numerator and denominator are the same value, and hence the normalized value for the maximum is 1.0.

Write a C program that normalizes a set of data. You may read the data from a data file or from the keyboard. However, the data must be stored in an array. Print out the original and normalized values in a table that is labeled. "
my attempt:

Code:
```main()
{
int x;
float a[100],
i,
normx,
max=a[0],
min=a[0];

printf("Enter the array separating each by a space:");
scanf("%f",&a[x]);

for(x=0; x < 100; x++)
{
if(a[x]<min)
min = a[x];
if(a[x]>max)
max = a[x];
}
normx = ((float)x-min)/(max-min);

printf("\n\n%f",a[normx]);

system("PAUSE");
return 0;
}```
compilation errors: a[normx] subscript needs to be an integer. however in my task, the normalized values need to be float.

2. main()

it should be int main(void) - read FAQ http://faq.cprogramming.com/cgi-bin/...&id=1043284376

Code:
```max=a[0],
min=a[0];```
as your a array is not initialized yet - your min and max values get garbage

scanf("&#37;f",&a[x]);
this line should be inside the loop - you have to give the user a possibility to enter less than 100 numbers

Code:
`normx = ((float)x-min)/(max-min);`
you should normalize a[x] not x
you should do it for every x - so enother loop is required here

Code:
`printf("\n\n%f",a[normx]);`
just horrible, what you are trying to achieve here? some random code put here and there?

3. Originally Posted by vart
Code:
```max=a[0],
min=a[0];```
as your a array is not initialized yet - your min and max values get garbage

Code:
`printf("\n\n%f",a[normx]);`
just horrible, what you are trying to achieve here? some random code put here and there?
what should i do about these then?

4. initialize min and max after you read a[0] from the user

add the second loop for normalizing members of the array
add the 3rd loop for output result

Originally Posted by killcapital

my attempt:

Code:
```main()
{
int x;
float a[100],
i,
normx,
max=a[0],  // a[0] contains a garbage value at this point.
min=a[0];

printf("Enter the array separating each by a space:");
scanf("%f",&a[x]);   /* This should be in a loop which allows the user to enter multiple values
into your array. Thereafter, assign max and min */

for(x=0; x < 100; x++)
{
if(a[x]<min)
min = a[x];
if(a[x]>max)
max = a[x];
}
normx = ((float)x-min)/(max-min);

printf("\n\n%f",a[normx]);  // An array index should be an interger type!!!

system("PAUSE");   // Why do you want to do that??? Comments??
return 0;
}```
compilation errors: a[normx] subscript needs to be an integer. however in my task, the normalized values need to be float.