Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maximum product in an array solved #1275

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
25 changes: 25 additions & 0 deletions Algorithms/Array/Max_Sum_Pair/maxProduct.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<bits/stdc++.h>
using namespace std;

int main(){
int n;
cout<<"Enter the size of array ";
cin>>n;
vector<int> v(n);
cout<<"Enter the elements of the array ";
for(int i=0; i<n; i++){
cin>>v[i];
}
int first = 0, second = 0;
for(int i=0; i<n; i++){
if(v[i] > first){
second = first;
first = v[i];
}
else if(v[i] > second){
second=v[i];
}
}
cout<<"The pair of elements with maximum product is "<<first<<" and "<<second<<endl;
cout<<"And their product is "<<first*second;
}
Binary file added Algorithms/Array/Max_Sum_Pair/maxProduct.exe
Binary file not shown.