valarray::operator%=
Obtains the remainder of dividing the elements of an array element-wise either by a specified valarray or by a value of the element type.
valarray<Type>& operator%=(
const valarray<Type>& _Right
);
valarray<Type>& operator%=(
const Type& _Right
);
Parameters
- _Right
The valarray or value of an element type identical to that of the operand valarray that is to divide, element-wise, the operand valarray.
Return Value
A valarray whose elements are the remainder from the element-wise division of the operand valarray by _Right.
Example
// valarray_class_op_rem.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<int> vaL ( 6 ), vaR ( 6 );
for ( i = 0 ; i < 6 ; i += 2 )
vaL [ i ] = 53;
for ( i = 1 ; i < 6 ; i += 2 )
vaL [ i ] = -67;
for ( i = 0 ; i < 6 ; i++ )
vaR [ i ] = 3*i+1;
cout << "The initial valarray is: ( ";
for ( i = 0 ; i < 6 ; i++ )
cout << vaL [ i ] << " ";
cout << ")." << endl;
cout << "The initial _Right valarray is: ( ";
for ( i = 0 ; i < 6 ; i++ )
cout << vaR [ i ] << " ";
cout << ")." << endl;
vaL %= vaR;
cout << "The remainders from the element-by-element "
<< "division is the\n valarray: ( ";
for ( i = 0 ; i < 6 ; i++ )
cout << vaL [ i ] << " ";
cout << ")." << endl;
}
The initial valarray is: ( 53 -67 53 -67 53 -67 ).
The initial _Right valarray is: ( 1 4 7 10 13 16 ).
The remainders from the element-by-element division is the
valarray: ( 0 -3 4 -7 1 -3 ).
Requirements
Header: <valarray>
Namespace: std