c:c_adjacent_differences_of_elements_in_array
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
c:c_adjacent_differences_of_elements_in_array [2020/04/15 08:11] – removed peter | c:c_adjacent_differences_of_elements_in_array [2020/07/15 09:30] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== C - C++ Adjacent differences of elements in array ====== | ||
+ | |||
+ | <code cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | using namespace std; | ||
+ | |||
+ | int diff (int x, int y) {return x+y;} | ||
+ | |||
+ | int main () { | ||
+ | int a[] = {1, | ||
+ | int b[10]; | ||
+ | |||
+ | cout<<" | ||
+ | |||
+ | for (int i=0; i<10; i++) cout << a[i] << ' '; | ||
+ | adjacent_difference (a, a+10, b); | ||
+ | |||
+ | cout << " | ||
+ | |||
+ | for (int i=0; i<10; i++) | ||
+ | cout << b[i] << ' '; | ||
+ | |||
+ | cout << endl; | ||
+ | |||
+ | adjacent_difference (a, a+10, b, multiplies< | ||
+ | |||
+ | cout << " | ||
+ | |||
+ | for (int i=0; i<10; i++) | ||
+ | cout << b[i] << ' '; | ||
+ | |||
+ | cout << endl; | ||
+ | |||
+ | adjacent_difference (a, a+10, b, diff); | ||
+ | |||
+ | cout << " | ||
+ | |||
+ | for (int i=0; i<10; i++) | ||
+ | cout << b[i] << ' '; | ||
+ | |||
+ | cout << endl; | ||
+ | cout<<" | ||
+ | |||
+ | partial_sum(& | ||
+ | |||
+ | for (int i=0; i<10; i++) | ||
+ | cout << b[i] << ' '; | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
c/c_adjacent_differences_of_elements_in_array.1586938307.txt.gz · Last modified: 2020/07/15 09:30 (external edit)