R Program to multiply two vectors of integers type and length 3

February 7, 2023, Learn eTutorial
1282

How do the multiplication of two vectors?

To do the multiplication of vectors in R, we use the product (*) operator.

How two vectors are multiplied using the R Program?

In this R program, we accept the vector values into variables A and B. The result value of vectors is assigned to variable C as C = A*B. Finally, variable C is printed as the output vector.

ALGORITHM

STEP 1: take the two vector values into the variables A, B

STEP 2: Consider C as the result vector

STEP 3: Calculate the vector product using the operator

STEP 4: First print the original vectors

STEP 5: Assign the result of product value to vector C as C=A*B

STEP 6: print the vector C as the result vector

R Source Code

```                                          ```A = c(10, 20, 30)
B = c(20, 10, 40)
print("Original Vectors are:")
print(A)
print(B)
print("Product of two Vectors:")
C = A * B
print(C)```
```

OUTPUT

```[1] "Original Vectors:"
[1] 10 30 6
[1] 20 10 40
[1] "Product of two Vectors:"
[1] 200 300 240
```

VIEW ALL
VIEW ALL