Skip to content

Commit

Permalink
Merge pull request rathoresrikant#37 from shreyateeza/master
Browse files Browse the repository at this point in the history
maxpairsum in c++ added
  • Loading branch information
Srikant Singh authored Apr 24, 2019
2 parents 1cd1ffc + 867a6ad commit f90caf3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Algorithms/Array/maxpairsum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<bits/stdc++.h>
using namespace std;

int main(){

int A[] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,3,27,9,81,243,729,8,7};
int n = sizeof(A)/sizeof(int);
int sum = 0, index1 = 0, index2 = 1;
int max = A[0] + A[1];

for(int i=1; i<n; i++){
for(int j=i+1; j<n; j++){
sum = A[i] + A[j];
if(sum>max){
max = sum;
index1 = i;
index2 = j;
}
}
}

cout<<"The maximum pair sum is "<<max<<" at index "<<i<<" and "<<j<<endl;
return 0;
}

0 comments on commit f90caf3

Please sign in to comment.