This functions assigns the difference between the corresponding elements of an array to another array. It returns the adjacent difference of all the set of values lying between [ First, last ).
For Example: If a represents an element in provided range [first, last) and b represents the result.
b = a b = a – a b = a – a b = a – a b = a – a ... ... ...
adjacent_difference(first, last, b); adjacent_difference(first, last, b, myfun ); adjacent_difference(first, last, b, multiplies() ) ; first, last : address of first and last element of range whose elements are to be added b:index of array where corresponding partial sum will be stored; myfun : a user defined function for performing any specific task multiplies():a pre defined function.
Result using adjacent_difference: 1 1 1 1 1 1 Result using accumulate with user-defined function: 1 3 5 7 9 11 Result using accumulate with pre-defined function: 1 2 6 12 20 30
This function returns the result of addition of var with the inner products of the pairs formed by the elements of two ranges starting at first1 and first2.
inner_product(first, last, b, var) ; inner_product(a, a+3, b, var, fun, fun1) ; inner_product(a , a+3, b, init, minus (), divides () ); first, last : address of first and last element of range whose elements are to be added b: index of array where corresponding partial sum will be stored; fun, fun1: a user defined function for performing any specific task minus(), divides() : pre defined function.
Result using inner_product 355 Result using inner_product with pre-defined function: 181 Result using inner_product with user-defined function: 146
This function assigns a value to the elements in the range [first,last ) of the array which is incremented at each step by val++ .
iota(first, last,val) ; first, last : address of first and last element of range whose elements are to be added val: initial value to store, the expression ++value must be well-formed
a: 100 101 102 103 104 105 106
This article is contributed by Abhinav Tiwari . If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Array algorithms in C++ STL (all_of, any_of, none_of, copy_n and iota)
- accumulate() and partial_sum() in C++ STL : numeric header
- std::iota in C++
- <numeric> library in C++ STL
- Namespace in C++ | Set 3 (Accessing, creating header, nesting and aliasing)
- random header in C++ | Set 1(Generators)
- random header | Set 2 (Distributions)
- random header in C++ | Set 3 (Distributions)
- What’s difference between header files "stdio.h" and "stdlib.h" ?
- Difference between Header file and Library
- Print "Hello World" in C/C++ without using any header file
- Comment in header file name?
- How to write your own header file in C?
- clocale header file in C++
- time.h header file in C with Examples
- <complex.h> header file in C with Examples
- Exception header in C++ with examples
- Header files in C/C++ with Examples
- ASCII NUL, ASCII 0 ('0') and Numeric literal 0
- Split numeric, alphabetic and special symbols from a String