fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arr[]= {1, 5, 3, 4, 2};
  6. int n=sizeof(arr)/sizeof(arr[0]);
  7. int diff=2;
  8. int count=0;
  9. for(int i=0;i<n;i++){
  10. for(int j=i+1;j<n;j++){
  11. if(arr[i]-arr[j]==diff)
  12. count++;
  13. }
  14. }
  15. cout<<count;
  16. }
  17.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
2