Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Linux Foundation Training and Certification

Teach Your Child To Read

Disclosure: My content contains affiliate links.

32,304 questions

42,479 answers

573 users

How to calculate the dot product of two arrays in Rust

1 Answer

0 votes
fn calculate_dot_product(arr1: &[i32], arr2: &[i32]) -> i32 {
    let mut product = 0;
    let size = arr1.len();

    for i in 0..size {
        product += arr1[i] * arr2[i];
    }

    product
}

fn main() {
    let arr1 = [1, 4, 8, 9, 6];
    let arr2 = [0, 7, 1, 3, 40];

    println!("Dot product = {}", calculate_dot_product(&arr1, &arr2));
}



  
/*
run:

Dot product = 303

*/

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered 5 days ago by avibootz

Related questions

1 answer 6 views
1 answer 9 views
3 answers 68 views
2 answers 55 views
...