need help! Vector magnitude

This is a discussion on need help! Vector magnitude within the C Programming forums, part of the General Programming Boards category; Hi guys, Im a C beginner..so the questions I got for my submission is to find the magnitude of a ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    5

    need help! Vector magnitude

    Hi guys, Im a C beginner..so the questions I got for my submission is to find the magnitude of a vector ||X||

    where:

    X = [ 2 3 4 4 6 12]

    I know ||X|| = sqrt(2^2+3^2+4^2+4^2+6^2+12^2)

    but I have no idea where to start, my lecturer gave me a header:

    double length(double a[], int n)


    can somebody help me?
    thank you soo much

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,751
    So what's your question?

    How to write a for loop to run for n iterations?
    How to square a number?
    How to add a series of numbers together?

    Post some effort showing what you can achieve by yourself.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    5
    er..to write a function that return the magnitude of the n dimensional vector a

    then using the code to test the vector X = [ 2 3 4 4 6 12]

    but the point is I don't know where to start, maybe a little hint for me? Im sorry..

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,751
    How much C do you actually know?

    You've got an array with those numbers, try printing out the array using a for loop.

    Then print out each number squared.

    You're almost done at that point.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Can you do "Hello World" yet?

    Hint: it usually starts with
    Code:
    int main(void)
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21