writting a C program

Nov 14, 2008 at 3:40am
this is one of my practice quizzes for my upcoming test, i am having way too much trouble writing the code for it out, help on writing this code out will be appreciated

Write a C program that normalizes the vector vec[5], whose components
are in the file vec_in.dat (which you need to copy). The components
of the normalized vector are defined as the original components devided
by the norm of the vecor, which is: norm=sqrt(v[0]^2+v[1]^2+....).
Write the original and the normalized components on the screen and in
the output file vec_out.dat. Close the files.

Your solution should look like this (on the screen and in the output file):

Original Vector = [ 1.200000 -2.300000 0.530000 2.010000 -1.500000 ]

Normalized Vector = [ 0.329033 ............................. -0.411291 ]
Nov 14, 2008 at 7:18am
I certainly won't do your homework, but try to explicit separate steps, such as

1. reading the vector

2. computing its norm

3. normalizing the vector

And repeat this divide & conquer approach until each step is small enough to make it a C statement.

BTW, you are on a C++ forum, not a C one!

At last, take time to go to a library (with books on paper) and to read some books.

You need to learn how to do things by your own, not to have other people doing your homework
Nov 16, 2008 at 7:25pm
Topic archived. No new replies allowed.