fork download
  1. #include <iostream>
  2. using namespace std;
  3. int getCount(int arr[],int n,int k){
  4. int count=0;
  5. for(int i=0;i<n;i++){
  6. for(int j=i+1;j<n;j++){
  7. if(abs(arr[i]+arr[j])+abs(arr[i]-arr[j])==k){
  8. count++;
  9. }
  10. }
  11. }
  12. return count;
  13. }
  14.  
  15. int main() {
  16. // your code goes here
  17. int arr[]={1,4,-2,1};
  18. int n=sizeof(arr)/sizeof(arr[0]);
  19. int k;
  20. cin>>k;
  21. cout<<"The count of intersecting pairs are:"<<getCount(arr,n,k);
  22. return 0;
  23. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
The count of intersecting pairs are:0