Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
80 views
in Computer by (67.7k points)
closed by

Consider the following snippet of a C program. Assume that swap (&x, &y) exchanges the contents of x and y.

int main( ) {

int array[ ]={3,5,1,4,6,2};

int done = 0;

int i;

while (done == 0) {

done = 1;

for (i=0; i <=4; i++) {

if (array [i] < array [i+1]) { 

swap (& array [i], &array [i+1]); 

done = 0;

  }

}

for (i=5; i >=1; i--) {

if (array[i]> array [i-1]) { 

swap ( & array [i], &array [i-1]); 

done = 0;

}

  }

}

printf ("%d", array [3] ); 

}

The output of the program is ___.

1 Answer

+1 vote
by (68.9k points)
selected by
 
Best answer

Correct answer is 3

The final contents of the array is

∴a[3] = 3will be printed

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...