1 0 1 0 1 0 1 0 1 

, 2.

1 1 0 0 1 1 0 0 1

, 3.

 0 0 0 0 1 1 1 1 1 

, 4.

1 1 1 1 1 0 0 0 0

">
MCQs > IT & Programming > Embedded C >

What will be the output of the following program?

#include <stdio.h>

void abc(int num1[], int size)

{

  int a = 0, b = size–1;

  while (a < b)

  {

while (num1[a] == 0 && a < b)

a++;

while (num1[b] == 1 && a < b)

b––;

if (a < b)

{

  num1[a] = 0;

  num1[b] = 1;

  a++;

  b––;

}

  }

}

int main()

{

  int num[] = {1, 0, 1, 0, 1, 0, 1, 1, 0};

  int z = 9, x = 0;

  abc(num, z);

  for (x = 0; x < 9; x++)

  printf("%d ", num[x]);

  getchar();

  return 0;

}


Embedded C MCQs

What will be the output of the following program?

#include <stdio.h>

void abc(int num1[], int size)

{

  int a = 0, b = size–1;

  while (a < b)

  {

while (num1[a] == 0 && a < b)

a++;

while (num1[b] == 1 && a < b)

b––;

if (a < b)

{

  num1[a] = 0;

  num1[b] = 1;

  a++;

  b––;

}

  }

}

int main()

{

  int num[] = {1, 0, 1, 0, 1, 0, 1, 1, 0};

  int z = 9, x = 0;

  abc(num, z);

  for (x = 0; x < 9; x++)

  printf("%d ", num[x]);

  getchar();

  return 0;

}


Answer

Correct Answer:

 0 0 0 0 1 1 1 1 1 

Explanation:

Note: This Question is unanswered, help us to find answer for this one

Embedded C Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

More Embedded C MCQ Questions

search

Embedded C Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it