/* --------------------------------------------------------------------- ** Figure 10.9: Walking on memory. ** --------------------------------------------------------------------- */ #include "tools.h" void main( void ) { int k; /* Loop counter. */ float v[3]; /* A vector in 3-space. */ float sum; /* The sum of the squares of the components. */ float magnitude; puts( "\n Subscript Demo: Walking on Memory" ); printf( " Please enter one float vector component at each prompt.\n" ); for (sum = 0.0, k = 0; k <= 3; ++k) { /* Loop goes too far. */ printf( "\tv[%i]: ", k ); scanf( "%g", &v[k] ); sum += v[k]*v[k]; } magnitude = sqrt( sum ); printf( " The magnitude of vector ( %g, %g, %g ) is %g \n", v[0], v[1], v[2], magnitude ); bye(); }