Computer Science, asked by sukanyaverma2475, 1 year ago

Write a program to find the largest 2 numbers and the smallest 2 numbers in the given array

Answers

Answered by MissGulabo
2

C++ or JAVA OR PYTHON

Answered by zoekar26
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