Thread: see how many can figure this out.

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    2

    see how many can figure this out.

    Write a program that inputs two integer vectors, computes the dot product of the vectors, and displays the results. The dot product of two vectors is calculated by summing the product of corresponding terms. For example:

    [ 1 3 5 ] · [ 2 4 6 ] = 1·2 + 3·4 + 5·6 = 44

    Allow for up to 100 elements per vector, and store each vector in an array. After displaying the dot product, ask the user if they want to compute another dot product. Here is a sample run:

    Enter number of terms: 3
    Enter first vector: 1 3 5
    Enter second vector: 2 4 6
    The dot product is 44
    Compute another dot product? (y/n) n
    computer: Good-bye!
    Implement the dot product logic as a function using the following prototype:

    int dotProduct(int a[], int b[], int n);
    where a and b are the two vectors, and n is the number of terms in each vector

  2. #2
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    Vector? like geometric vectors?
    01011001 01101111 01110101 00100000 01110100 01101111 01101111 1101011 00100000 01110100 01101000 01101001 01110011 00100000 01101101 01110101 01100011 01101000 00100000 01110100 01101000 01101101 01100101 00100000 01110100 01101111 00100000 01110010 01100101 01100001 01100100 00100000 01011001 01101000 01101001 01110011 00111111 00100000 01000100 01100001 01101101 01101110 00100001 00000000

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    2
    yes like geomerty vectors.

  4. #4
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    the only vector's I've learned are 2-D (not 3-D, which it seems you want to do)..

    So, basically, you want to calculate the distance of a vector?
    01011001 01101111 01110101 00100000 01110100 01101111 01101111 1101011 00100000 01110100 01101000 01101001 01110011 00100000 01101101 01110101 01100011 01101000 00100000 01110100 01101000 01101101 01100101 00100000 01110100 01101111 00100000 01110010 01100101 01100001 01100100 00100000 01011001 01101000 01101001 01110011 00111111 00100000 01000100 01100001 01101101 01101110 00100001 00000000

  5. #5
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    this must be homework right?
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  6. #6
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by kinghajj
    the only vector's I've learned are 2-D (not 3-D, which it seems you want to do)..

    So, basically, you want to calculate the distance of a vector?
    If there are two integers then it would be 2D wouldnt it?

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The function to calculate the dot product takes only one for loop. The entire program takes only two loops. Post your code. I've just given you your "see if anyone can do this" answer. Now how about we see if you can do it. Oh, while you're at it, read this and this.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Figure out how method was called?
    By jcafaro10 in forum C++ Programming
    Replies: 2
    Last Post: 02-07-2009, 10:43 AM
  2. 3 dimensional figure volume
    By thekautz in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2009, 05:22 PM
  3. trying to figure out someone's code for a plugin
    By paulpars in forum C++ Programming
    Replies: 4
    Last Post: 07-20-2006, 10:57 AM
  4. newb to C, cant figure something out.
    By Phate4219 in forum C Programming
    Replies: 16
    Last Post: 03-06-2006, 01:47 AM
  5. ahh i can't figure out this loop
    By blindleaf in forum C Programming
    Replies: 1
    Last Post: 03-18-2003, 09:42 AM