Beginner C++ problem
I'm assuming your goal was to produce the sum of absolute values and the sqrt of the sum of squares respectively. Your program is semantically correct however you have made two mistakes in reading your input. The first is that your fscanf call reads integers (you should have %f not %d). The second is that you are passing a dereferrenced float value as the last param of fscanf, you should be passing in the address. Thus the line should read either
fscanf(fin, "%f\n", x+q)
or
fscanf(fin, "%f\n", &x[q])
The first one uses pointer arithmetic to establish the memory location by determining the qth offset of a float stored in x and the second uses standard array access notation to resolve the *value* at the qth location and then derefrence it. Regardless of whether or not you choose to use C or C++ you should have a firm grasp of pointers. I highly recommend you read up on them.
P.S
You should consider asking this sort of question on a dedicated forum like stack overflow.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now