valarray abs() function in C++ Last Updated : 24 Oct, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The abs() function is defined in valarray header file. This function is used to calculate the absolute value of each element in the valarray and returns a valarray containing the absolute values of all the elements. Syntax: abs(varr); Parameter: This function takes a mandatory parameter varr which represents valarray. Returns: This function returns a valarray containing the absolute values of all the elements. Below programs illustrate the above function: Example 1:- CPP // C++ program to demonstrate // example of abs() function. #include <bits/stdc++.h> using namespace std; int main() { // Initializing valarray valarray<int> varr = { 20, 12, -20, 0, -30 }; // Declaring new valarray valarray<int> varr1; // use of abs() function // for finding abs value varr1 = abs(varr); // Displaying new elements value cout << "The new valarray with" << " manipulated values is : "; for (int& x : varr1) { cout << x << " "; } cout << endl; return 0; } Output: The new valarray with manipulated values is : 20 12 20 0 30 Example 2:- CPP // c++ program to demonstrate // example of abs() function. #include <bits/stdc++.h> using namespace std; int main() { // Initializing valarray valarray<int> varr = { -36, -369, -20, 0, -30 }; // Declaring new valarray valarray<int> varr1; // use of abs() function // for finding abs value varr1 = abs(varr); // Displaying new elements value cout << "The new valarray" << " with manipulated values is : "; for (int& x : varr1) { cout << x << " "; } cout << endl; return 0; } Output: The new valarray with manipulated values is : 36 369 20 0 30 Comment More infoAdvertise with us Next Article negate function in C++ STL B bansal_rtk_ Follow Improve Article Tags : Misc C++ CPP-Functions cpp-valarray Practice Tags : CPPMisc Similar Reads valarray acos() function in C++ The acos() function is defined in valarray header file. This function is used to calculate arc cosine of the value of each element in valarray and returns a valarray containing the arc cosine of all the elements. Syntax: acos(varr); Parameter: This function takes a mandatory parameter varr which rep 2 min read abs(), labs(), llabs() functions in C/C++ The std::abs(), std::labs() and std::llabs() in C++ are built-in functions that are used to find the absolute value of any number that is given as the argument. Absolute value is the value of a number without any sign. These functions are defined inside the <cmath> header file.In this article, 3 min read negate function in C++ STL This function is used to negate the given values i.e. to change the sign of the values. It changes the positive values to negative and vice-versa. Note: Objects of this class can be used on standard algorithms such as transform. Syntax: transform(arr_begin, arr_end, arr2_begin, negate()) Parameters: 2 min read PHP abs() Function The abs() function is an inbuilt function in PHP which is used to return the absolute (positive) value of a number. The abs() function in PHP is identical to what we call modulus in mathematics. The modulus or absolute value of a negative number is positive. Syntaxnumber abs( value )ParametersThe ab 1 min read abs() function for complex number in c++ The abs() function for complex number is defined in the complex header file. This function is used to return the absolute value of the complex number z. Syntax: template<class T> T abs (const complex<T>& z); Parameter: z: It represents the given complex number. Return: It returns the 2 min read Program for Mean Absolute Deviation Given an array of size n, find mean absolute deviation. Prerequisite : Mean, Variance and Standard DeviationExamples: Input : arr[] = {10, 15, 15, 17, 18, 21} Output : 2.66667 Input : arr[] = {23.54, 56, 34.56, 67, 45.34, 56.78, 78, 21} Output : 16.6675 Mean absolute deviation or Average absolute de 6 min read Like