Absolute Difference of all pairwise consecutive elements in an array | C ++ program to print the absolute difference of the consecutive elements ; Function to print pairwise absolute difference of consecutive elements ; absolute difference between consecutive numbers ; Driver Code
#include <iostream> NEW_LINE using namespace std ; void pairwiseDifference ( int arr [ ] , int n ) { int diff ; for ( int i = 0 ; i < n - 1 ; i ++ ) { diff = abs ( arr [ i ] - arr [ i + 1 ] ) ; cout << diff << " ▁ " ; } } int main ( ) { int arr [ ] = { 4 , 10 , 15 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; pairwiseDifference ( arr , n ) ; return 0 ; }