Determine the output of the following C code fragment You mu

Determine the output of the following C code fragment. You must trace the code to show how you reached the answer. int i = 10; while (i >= 3) {i = i - 1; if (i % 2 == 0) continue; printf(\"**\ \"); i = i - 1; if (i == 4) break;} Determine the output of the following code segment. You must trace the code to show how you reached the answer. int x = 2, y = 3; x = x + y; y = x - y; x = x - y. printf(\"x is %d\ \", x); printf(\"y is %d\ \", y);

Solution

1. ** will be printed thrice in three lines

int main()
{
   int i=10;
   while(i>=3) // i=10
   {
       i--; // i become 9
       if(i%2==0) /// this will be non 0
       continue;
       printf(\"**\ \"); // so this will be printed
       i--; // i becomes 8 thus
       if(i==4) // this is false so next iteration
           break;
   }
  
}

// Similarly in next iteration value of i is 8 which becomes 7 after decrement so ** will be printed then i is decremented again and becomes 6 then next iteration takes place with i as 6
// In next iteration i becomes 5 at first decrement and thus ** will be printed third time and then after decrement i becomes 4 and thus break statement will be executed.
// Thus ** will be printed thrice

2.
x is 3
y is 2 will be the output

int main()
{
   int x=2, y=3;
   x=x+y; // x will be 2+3 = 5
   y=x-y; // y will be 5-2 = 3 because x is now 5
   x=x-y; // x = 5- 3 =2 becuase y is now 3
   printf(\"x is %d\ \", x);
   printf(\"y is %d\ \", y);
  
  
}

 Determine the output of the following C code fragment. You must trace the code to show how you reached the answer. int i = 10; while (i >= 3) {i = i - 1; if

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site