Advertisement
Imran_Mohammed

Two_Pointer

May 16th, 2022
303
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.    
  6.     //Finding Summation of 26 with two number :
  7.  
  8.     int a[] = {7,8,9,14,18,20};
  9.     int target = 26;
  10.  
  11.     int i=0, j=5;
  12.  
  13.     while(i<=j){
  14.  
  15.         if(a[i]+a[j] == target){
  16.             cout << a[i] << " " << a[j] << endl;
  17.             //return 0;
  18.         }
  19.  
  20.         else if(a[i]+a[j] > target){
  21.             j--;
  22.         }
  23.  
  24.         else if(a[i]+a[j] < target){
  25.             i++;
  26.         }
  27.     }
  28.     return 0;
  29. }
  30.  
Advertisement
RAW Paste Data Copied
Advertisement