fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using ll = long long int;
  4. #define fo(i,start,end) for(int i=start;i<end;i++)
  5. using namespace std;
  6.  
  7. int main() {
  8. // your code goes here
  9. int arr[] = {1,5,2,4,1} ;
  10. int k = 4;
  11. int n = 5;
  12. fo(i,0,n){
  13. fo(j,i+1,n){
  14. if(arr[i] - arr[j] == k){
  15. cout<<"The pairs are:{"<<i<<","<<j<<"}"<<endl;
  16. return 0;
  17. }
  18. }
  19. }
  20. cout<<"No valid pairs found"<<endl;
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
The pairs are:{1,4}