Sum of products of two arrays (dotproduct)

前端 未结 6 1346
难免孤独
难免孤独 2021-02-04 05:49

First off, I know my title can be formulated better, but my math classes are so far gone I can\'t remember the correct words anymore..

I need to do something like this (

6条回答
  •  别那么骄傲
    2021-02-04 06:26

    Very simply, do a loop.

    int sum = 0;
    for(int i = 0; i < digits1.length && i < digits2.length; i++)
    {
        sum += digits1[i] * digits2[i];
    }
    

    Boom.

提交回复
热议问题