What will be the output of the following Pseudocode?int c = 0, d = 0 while ( d< 6 ) d=d+2 c=c+1 end while loop print c3564
Question
What will be the output of the following Pseudocode?
int c = 0, d = 0
while ( d < 6 )
d = d + 2
c = c + 1
end while loop
print c
3564
Solution
The pseudocode provided is a simple loop that increments the variable 'd' by 2 and 'c' by 1 in each iteration until 'd' is no longer less than 6. Here's a step-by-step breakdown:
- Initialize 'c' and 'd' to 0.
- Enter the while loop. Check if 'd' is less than 6. It is, so we continue.
- Increment 'd' by 2. 'd' is now 2.
- Increment 'c' by 1. 'c' is now 1.
- Go back to the start of the loop. Check if 'd' is less than 6. It is, so we continue.
- Increment 'd' by 2. 'd' is now 4.
- Increment 'c' by 1. 'c' is now 2.
- Go back to the start of the loop. Check if 'd' is less than 6. It is, so we continue.
- Increment 'd' by 2. 'd' is now 6.
- Increment 'c' by 1. 'c' is now 3.
- Go back to the start of the loop. Check if 'd' is less than 6. It is not, so we exit the loop.
- Print 'c'. The output is 3.
So, the output of the pseudocode will be 3.
Similar Questions
What will be the output of the following Pseudocode? int a=9, b=7, c=8, d=4, e e = (a + b + c + d) / 4 if (e >5) print "PASS" else print "FAIL"FAIL01PASS
What is the output of the following piece of code?int i;i = 10;while (i < 20){ printf("%d", i % 2); i++;}
What will be the output of the following code? int i = 1;while(i<10){ if (i / 2 == 2) cout << i << “ ”;i++;}
What will be the output for the following code?i=0while(i<3): j=0 while(j<3): print(i,j,end=" ") j+=1 print()
What will be the output of the following C code?#include <stdio.h>int main() { int i; for (i = 0; i < 5; i++); printf("%d\n", i); return 0;}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.