Input n
N Max. Min.
Input
5
1 5 2 3 6
Output
1 6
#include<iostream>#include<algorithm>using namespace std;int main(){ int n, i, a[1000]; while(cin>>n) { for(i=0; i<n;i++) cin>>a[i]; sort(a,a+n);cout<<a[0]<<" "<<a[n-1]<<endl; }}
View code
# Include <iostream>
# Include <algorithm>
Using namespace STD;
Int main ()
{
Int N, I, a [1000];
While (CIN> N)
{
For (I = 0; I <n; I ++)
Cin> A [I];
Sort (A, A + n );
Cout <A [0] <"" <A [n-1] <Endl;
}
}
#include<iostream>#include<algorithm>using namespace std;int main(){ int n, i, a[1000],m1,m2; while(cin>>n) { for(i=0; i<n;i++) cin>>a[i]; if(i==0) m1=m2=a[0]; if(a[i]>m2) m2=a[i]; if(a[i]<m1) m1=a[i];cout<<m1<<" "<<m2<<endl; }}
View code
# Include <iostream>
# Include <algorithm>
Using namespace STD;
Int main ()
{
Int N, I, a [1000], M1, M2;
While (CIN> N)
{
For (I = 0; I <n; I ++)
Cin> A [I];
If (I = 0) M1 = m2 = A [0];
If (A [I]> m2) m2 = A [I];
If (A [I] <M1) M1 = A [I];
Cout <M1 <"" <m2 <Endl;
}
}
**************************************** ****************
# Include <iostream>
# Include <algorithm>
Using namespace STD;
# Define INF 1000000
Int main ()
{
Int N, I, a [1000], M1, M2;
While (CIN> N)
{
For (I = 0; I <n; I ++)
Cin> A [I];
M1 =-INF; M2 = inf;
If (A [I]> m2) m2 = A [I];
If (A [I] <M1) M1 = A [I];
Cout <M1 <"" <m2 <Endl;
}
}
**************************************** ***************
2's 31 Power ----------------------------- use of the calculator
# Include <iostream>
# Include <algorithm>
Using namespace STD;
# Define INF 1 <31
Int main ()
{
Int N, I, a [1000], M1, M2;
While (CIN> N)
{
For (I = 0; I <n; I ++)
Cin> A [I];
M1 =-INF; M2 = inf;
If (A [I]> m2) m2 = A [I];
If (A [I] <M1) M1 = A [I];
Cout <M1 <"" <m2 <Endl;
}
}
# Include <iostream>
# Include <algorithm>
Using namespace STD;
# Define INF 2147483648
Int main ()
{
Int N, I, a [1000], M1, M2;
While (CIN> N)
{
For (I = 0; I <n; I ++)
Cin> A [I];
M1 =-INF; M2 = inf;
If (A [I]> m2) m2 = A [I];
If (A [I] <M1) M1 = A [I];
Cout <M1 <"" <m2 <Endl;
}
}
**************************************** *****************************
Verify the power of 1 <31 2 to the power of 31 using a program
Use a program to calculate the power 31 of 1 <31 2
Use % d % u for data range format characters