User Tools

Site Tools


c:c_adjacent_differences_of_elements_in_array

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
c:c_adjacent_differences_of_elements_in_array [2020/04/15 08:11] – removed peterc: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 <iostream>
 +#include <functional>
 +#include <numeric>
 +using namespace std;
 + 
 +int diff (int x, int y) {return x+y;}
 + 
 +int main () {
 +  int a[] = {1,2,3,4,5,6,7,8,9,10};
 +  int b[10];
 +
 +  cout<<"Given Elements:";
 +
 +  for (int i=0; i<10; i++) cout << a[i] << ' ';
 +    adjacent_difference (a, a+10, b);
 +
 +  cout << "\nDifference between adjacent numbers:";
 +
 +  for (int i=0; i<10; i++) 
 +    cout << b[i] << ' ';
 +
 +  cout << endl;
 + 
 +  adjacent_difference (a, a+10, b, multiplies<int>());
 +
 +  cout << "Multiplying adjacent numbers using adjacent_difference: ";
 +
 +  for (int i=0; i<10; i++) 
 +    cout << b[i] << ' ';
 +
 +  cout << endl;
 + 
 +  adjacent_difference (a, a+10, b, diff);
 +
 +  cout << "adding adjacent numbers using adjacent_difference:";
 +
 +  for (int i=0; i<10; i++) 
 +    cout << b[i] << ' ';
 +
 +  cout << endl;
 +  cout<<"Partial Sum:";
 +
 +  partial_sum(&a[0], &a[10], &b[0]);
 +
 +  for (int i=0; i<10; i++) 
 +    cout << b[i] << ' ';
 +
 +  return 0;
 +}
 +</code>
  
c/c_adjacent_differences_of_elements_in_array.1586938307.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki