multiplication arrays


Multiplication of arrays

1
2
3
4
5
6
7
8
9
10
unsigned int trans_val_1[4];
unsigned int trans_val_2[4];


unsigned int mix_arr_0[4];


unsigned int perm_arr_0[4];

perm_arr_0 = trans_val_2 * mix_arr_0;


Errors
invalid operands of types ‘unsigned int [4]’ and ‘unsigned int [4]’ to binary ‘operator*’
Last edited on
Right! You can use "*" to multiply primitive data types like int, float etc. for multiplying arrays you need to loop through them and multiply each element of it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <valarray>

int main()
{
    // http://en.cppreference.com/w/cpp/numeric/valarray
    
    std::valarray<unsigned int> a = { 1, 2, 3, 4 } ;
    std::valarray<unsigned int> b = { 5, 6, 7, 8 } ;

    std::valarray<unsigned int> c = a * b ;
    for( auto i : c ) std::cout << i << ' ' ;
    std::cout << '\n' ;

    std::valarray<unsigned int> d = a * ( b + 10U ) ;
    for( auto i : d ) std::cout << i << ' ' ;
    std::cout << '\n' ;
}

http://coliru.stacked-crooked.com/a/296fab79ed6eb7de
Topic archived. No new replies allowed.