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