Write a program to find the largest 2 numbers and the smallest 2 numbers in the given array
Answers
Answered by
2
C++ or JAVA OR PYTHON
Answered by
5
Answer:
Wrote it in C. Hope it helps
Explanation:
Assuming the array is given and integer. Let's call it pin[N] where N is defined.
int i, max1, max2, min1, min2;
max1 = pin[1];
max2=pin[1];
min1 = pin[1];
min2=pin[1]
for(i=0;i<N; i++){
if(pin[i]> max1)
max1 = pin[i];
}
for(i=0; i<N; i++){
if(pin[i]>max2 && pin[i]!=max1)
max2= pin[i];
}
for(i=0;i<N; i++){
if(pin[i]< max1)
min1 = pin[i];
}
for(i=0; i<N; i++){
if(pin[i]<min2 && pin[i]!=min1)
min2= pin[i];
}
Similar questions
English,
6 months ago
English,
6 months ago
Computer Science,
1 year ago
Computer Science,
1 year ago
Physics,
1 year ago
Science,
1 year ago
Math,
1 year ago