Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TwoMax
//g++ 7.4.0 //write and test a function that returns through its reference parameters both the largest and second largest values stored in an array //this code is created by Rezaul Hoque on August 10,2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> using namespace std; const int n=10; void largest(int &,int &,int [],int); void largest(int& max1,int& max2,int a[],int n){ max1 = a[0]; for(int i=0;i<n;i++) if(a[i]>max1) max1=a[i]; max2 = a[0]; for(int i=0;i<n;i++) if(a[i]>max2 && a[i]<max1) max2=a[i]; cout<<"max1: "<<max1<<endl; cout<<"max2: "<<max2<<endl; } int main() { int a[]={10,9,5,8,30,26,32,1,78,20}; int max1,max2; largest(max1, max2,a,10); return 0; }
run
|
edit
|
history
|
help
0
BindWithContainer
Stock buy/sell, maximum subarray problem
te lo paso
Segment Tree
Caminho das Pontes
Test 1(2021)
parallel_for_each
scemo le
pointer to template function
Clementina