Question: cprogram Lab 4 Q.6 High Dimension Dot-Product Description Lab4-6. High Dimension Dot-Product This is an extension to the previous array exercise on calculating the dot

cprogram

Lab 4 Q.6 High Dimension Dot-Product

Description

Lab4-6. High Dimension Dot-Product

This is an extension to the previous array exercise on calculating the dot product of two 3-element vectors.

Instead of limiting ourselves to 3-dimension, let's try n-dimension!

A square (2D), cube (3D) and tesseract (4D) visualization. Source:https://en.wikipedia.org/wiki/Dimension#/media/File:Squarecubetesseract.png

Write a C program to ask the user for an input integer n (which is assumed to be positive and not more than 100). Then ask for two vectors v and w. Each vector has n double-type values that are stored in an n-element array, e.g., v[0], v[1], ..., v[n-1] and w[0], w[1], ..., w[n-1] for vectors v and w respectively. Calculate and print the dot product (scalar product) of v and w, in 2 decimal places.

Deadline: 24 Feb, 2023 (Mon)

Input

The first line has an integer n, indicating the dimension. You can assume n <= 10.

Second and third line contains n numbers separated by a space, corresponding to vectors v and w.

Output

In the format, "Dot product = ", print the value in 2 decimal places.

Sample Input 1

3 -4 0 2.5 3 -9.876 5 

Sample Output 1

Dot product = 0.50 

Sample Input 2

10 1 2 3 4 5 6 7 8 9 10 10 0 0 0 0 0 0 0 0 9 

Sample Output 2

Dot product = 100.00 

Sample Input 3

5 47 -4 -28 -21 -62 95 -3 -18 -91 -50

Sample Output 3

Dot product = 9992.00

Sample Input 4

10 38.78 92.55 -81.53 -41.35 -93.1 15.9 5.3 -19.43 77.33 -10.41 9.05 -19.58 56.68 -60.32 -14.91 34.25 34.77 11.61 73.58 -13.89

Sample Output 4

Dot product = 4137.87

Source

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!