32

, 2.

33

, 3.

34

, 4.

35

">
MCQs > IT & Programming > Embedded C >

Find the output of the following code and choose the correct answer from the given options.

#include <stdio.h>

int funct1(int num1[], int num2[], int n)

{

  int x1 = 0;

  int x2 = 0;

  int total;

  int k1 = –1, k2 = –1;

  for (total = 0; total <= n; total++)

  {

if (x1 == n)

{

  k1 = k2;

  k2 = num2[0];

  break;

}

else if (x2 == n)

{

  k1 = k2;

  k2 = num1[0];

  break;

}

if (num1[x1] < num2[x2])

{

  k1 = k2;

  k2 = num1[x1];

  x1++;

}

else

{

  k1 = k2;

  k2 = num2[x2];

  x2++;

}

  }

  return (k1 + k2)/2;

}

int main()

{

  int num1[] = {22, 27, 34, 31, 39};

  int num2[] = {22, 54, 67, 74, 46};

  int p1 = sizeof(num1) / sizeof(num1[0]);

  int p2 = sizeof(num2) / sizeof(num2[0]);

  if (p1 == p2)

  printf("%d", funct1(num1, num2, p1));

  else

  printf("failure");

  return 0;

}


Embedded C MCQs

Find the output of the following code and choose the correct answer from the given options.

#include <stdio.h>

int funct1(int num1[], int num2[], int n)

{

  int x1 = 0;

  int x2 = 0;

  int total;

  int k1 = –1, k2 = –1;

  for (total = 0; total <= n; total++)

  {

if (x1 == n)

{

  k1 = k2;

  k2 = num2[0];

  break;

}

else if (x2 == n)

{

  k1 = k2;

  k2 = num1[0];

  break;

}

if (num1[x1] < num2[x2])

{

  k1 = k2;

  k2 = num1[x1];

  x1++;

}

else

{

  k1 = k2;

  k2 = num2[x2];

  x2++;

}

  }

  return (k1 + k2)/2;

}

int main()

{

  int num1[] = {22, 27, 34, 31, 39};

  int num2[] = {22, 54, 67, 74, 46};

  int p1 = sizeof(num1) / sizeof(num1[0]);

  int p2 = sizeof(num2) / sizeof(num2[0]);

  if (p1 == p2)

  printf("%d", funct1(num1, num2, p1));

  else

  printf("failure");

  return 0;

}


Answer

Correct Answer:

35

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