Please provide the detailed solution of this code:
Integer x,y,z
Set x=3
Set y=90
while(y is greater than 0);
y=y/3
x=x+6
c=x+y
while(c is greater than 30):
if(c mod 3 is equals to 0):
Write x
else:
Write y
c=c/5
Write c

Use the A.P summation formula , Sum = n/2(first term + Last term)…… where last term =200 and first term =105.
n=20 bcoz there are total 20 nos. which are multiple of 5 between 100 and 200(exlcluding 100). Sum will come out to be 3050 and then subtract it by 1 bcoz x initial value was 1. The answer will be -3049

Please explain this code in details:
Integer a,b,c
Set a=6,b=84
while(b>0)
b=b/2
a=a+6
c=a+b
while(c>40)
if(c mod 2 IS EQUAL TO 0)
Print a
else
Print b
c=c/10
End while
End while
Print c

Hey Sourik, it’ll be a bit tricky, we’ll try to explain it step by step, lets start
initially a=6 , b=84
compiler will enter while loop
1st iteration – b=42 , a=12, c= a+b = 54(compiler will enter 2nd while loop)
(if condition gets true) – it will print a = 12
2nd iteration – b=21, a=18, c= a+b = 39(compiler will not enter 2nd while loop)
3rd iteration – b=10, a=24, c= a+b = 34(compiler will not enter 2nd while loop)
4th iteration – b=5, a=10, c= a+b = 35(compiler will not enter 2nd while loop)
5th iteration – b=2, a=36, c= a+b = 38(compiler will not enter 2nd while loop)
6th iteration – b=1, a=42, c= a+b = 43(compiler will enter 2nd while loop)
(if condition gets false), else will be executed and it will print b – 1
now, c=c/10, that makes c=4
7th iteration – b=0, a=48, c= a+b = 48(compiler will enter 2nd while loop)
(if condition gets true), it will print a – 48
now, c=c/10, that makes c=4
compiler get out of both the while loops
it will print c – that is 4
Hence the output will be
12 1 48 4
We hope, this will solve out your queries

In your given solution in the 7th iteration – b=0
But according to the question the first loop can only run while (b>0) and hence it should not run in that case only, so how is the 7th iteration even possible?

Integer a,b,c
Set a=6,b=84
while(b>0)
b=b/2
a=a+6
c=a+b
while(c>40)
if(c mod 2 IS EQUAL TO 0)
Print a
else
Print b
c=c/10
End while
End while
Print c
Can you provide the detailed solution?

Hey Riya, lets start
initially a=6 , b=84
compiler will enter while loop
1st iteration – b=42 , a=12, c= a+b = 54(compiler will enter 2nd while loop)
(if condition gets true) – it will print a = 12
2nd iteration – b=21, a=18, c= a+b = 39(compiler will not enter 2nd while loop)
3rd iteration – b=10, a=24, c= a+b = 34(compiler will not enter 2nd while loop)
4th iteration – b=5, a=10, c= a+b = 35(compiler will not enter 2nd while loop)
5th iteration – b=2, a=36, c= a+b = 38(compiler will not enter 2nd while loop)
6th iteration – b=1, a=42, c= a+b = 43(compiler will enter 2nd while loop)
(if condition gets false), else will be executed and it will print b – 1
now, c=c/10, that makes c=4
7th iteration – b=0, a=48, c= a+b = 48(compiler will enter 2nd while loop)
(if condition gets true), it will print a – 48
now, c=c/10, that makes c=4
compiler get out of both the while loops
it will print c – that is 4
Hence the output will be
12 1 48 4
We hope, this will solve out your queries

Set x to 0;
Set n to 1;
while(n<=100)
x=x+n;
n=n+1;
end while
write x

In the above question, counting the value of n = 1 to <= 100 will be a lot of time taking during the exam time, is there any trick that could solve the problem faster?

Hey Darshna, yes sure there is an alternative method, you can use the formula n(n+1)/2, and get the value of x pretty much faster than the orthodox way

Hey Kriti, this code is simply for confusing the students, but its output is pretty simple.
There are two for loops in the program, the inner for loop is changing the order of the elements of the array everytime
Like on executing the first time the array will be {3, 56, 34 , 2}
On executing the second time the array will be {56, 34 , 2 , 3}
On executing the third time the array will be {34 , 2 , 3, 56}
On executing for the fourth and last time the array will be { 2 , 3, 56 , 34}
Hence the array becomes the same after coming out both the for loops, and that’s why when you are printing the array for the final time, it will give you the same output, as the input

3-What will be the output of the following pseudocode?
Integer a,b,c
Set a=6,b=84
while(b>0)
b=b/2
a=a+6
c=a+b
while(c>40)
if(c mod 2 IS EQUAL TO 0)
Print a
else
Print b
c=c/10
End while
End while
Print c
Please explain this question

Please provide the detailed solution of this code:

Integer x,y,z

Set x=3

Set y=90

while(y is greater than 0);

y=y/3

x=x+6

c=x+y

while(c is greater than 30):

if(c mod 3 is equals to 0):

Write x

else:

Write y

c=c/5

Write c

Set x = 1

Set n = 200

while(n>100):

x=x-n

n=n-5

end while

Write x

Is there any trick that could solve the problem faster?

Use the A.P summation formula , Sum = n/2(first term + Last term)…… where last term =200 and first term =105.

n=20 bcoz there are total 20 nos. which are multiple of 5 between 100 and 200(exlcluding 100). Sum will come out to be 3050 and then subtract it by 1 bcoz x initial value was 1. The answer will be -3049

Please explain this code in details:

Integer a,b,c

Set a=6,b=84

while(b>0)

b=b/2

a=a+6

c=a+b

while(c>40)

if(c mod 2 IS EQUAL TO 0)

Print a

else

Print b

c=c/10

End while

End while

Print c

Hey Sourik, it’ll be a bit tricky, we’ll try to explain it step by step, lets start

initially a=6 , b=84

compiler will enter while loop

1st iteration – b=42 , a=12, c= a+b = 54(compiler will enter 2nd while loop)

(if condition gets true) – it will print a = 12

2nd iteration – b=21, a=18, c= a+b = 39(compiler will not enter 2nd while loop)

3rd iteration – b=10, a=24, c= a+b = 34(compiler will not enter 2nd while loop)

4th iteration – b=5, a=10, c= a+b = 35(compiler will not enter 2nd while loop)

5th iteration – b=2, a=36, c= a+b = 38(compiler will not enter 2nd while loop)

6th iteration – b=1, a=42, c= a+b = 43(compiler will enter 2nd while loop)

(if condition gets false), else will be executed and it will print b – 1

now, c=c/10, that makes c=4

7th iteration – b=0, a=48, c= a+b = 48(compiler will enter 2nd while loop)

(if condition gets true), it will print a – 48

now, c=c/10, that makes c=4

compiler get out of both the while loops

it will print c – that is 4

Hence the output will be

12 1 48 4

We hope, this will solve out your queries

In your given solution in the 7th iteration – b=0

But according to the question the first loop can only run while (b>0) and hence it should not run in that case only, so how is the 7th iteration even possible?

The value of b decreases to zero in the 7th iteration, that’s why there is no 8th iteration.

Integer a,b,c

Set a=6,b=84

while(b>0)

b=b/2

a=a+6

c=a+b

while(c>40)

if(c mod 2 IS EQUAL TO 0)

Print a

else

Print b

c=c/10

End while

End while

Print c

Can you provide the detailed solution?

Hey Riya, lets start

initially a=6 , b=84

compiler will enter while loop

1st iteration – b=42 , a=12, c= a+b = 54(compiler will enter 2nd while loop)

(if condition gets true) – it will print a = 12

2nd iteration – b=21, a=18, c= a+b = 39(compiler will not enter 2nd while loop)

3rd iteration – b=10, a=24, c= a+b = 34(compiler will not enter 2nd while loop)

4th iteration – b=5, a=10, c= a+b = 35(compiler will not enter 2nd while loop)

5th iteration – b=2, a=36, c= a+b = 38(compiler will not enter 2nd while loop)

6th iteration – b=1, a=42, c= a+b = 43(compiler will enter 2nd while loop)

(if condition gets false), else will be executed and it will print b – 1

now, c=c/10, that makes c=4

7th iteration – b=0, a=48, c= a+b = 48(compiler will enter 2nd while loop)

(if condition gets true), it will print a – 48

now, c=c/10, that makes c=4

compiler get out of both the while loops

it will print c – that is 4

Hence the output will be

12 1 48 4

We hope, this will solve out your queries

why i the output 12 1 48 4 hen only 4 should be printed right because on 7th iteration we are getting out of the while loops

Set x to 0;

Set n to 1;

while(n<=100)

x=x+n;

n=n+1;

end while

write x

In the above question, counting the value of n = 1 to <= 100 will be a lot of time taking during the exam time, is there any trick that could solve the problem faster?

Hey Darshna, yes sure there is an alternative method, you can use the formula n(n+1)/2, and get the value of x pretty much faster than the orthodox way

Please provide a detailed explanation of this code.

Integer array1[10] = {2, 3, 56, 34}

Integer k, a, j, n

Set a = 3, n = 4

for(each k from 0 to n-1)

Set array1[n] = array1[0]

for(each j from 0 to n-1)

Set array1[j] = array1[j+1]

End for

End for

for(each k from 0 to n-1)

Print array1[k]

End for

Hey Kriti, this code is simply for confusing the students, but its output is pretty simple.

There are two for loops in the program, the inner for loop is changing the order of the elements of the array everytime

Like on executing the first time the array will be {3, 56, 34 , 2}

On executing the second time the array will be {56, 34 , 2 , 3}

On executing the third time the array will be {34 , 2 , 3, 56}

On executing for the fourth and last time the array will be { 2 , 3, 56 , 34}

Hence the array becomes the same after coming out both the for loops, and that’s why when you are printing the array for the final time, it will give you the same output, as the input

i am getting only 1to 10 question after that i am not getting anything

Hey Kartheekh, each mock test consits of 10 questions, please try to open the other mock tests, there you’ll find more questions

3-What will be the output of the following pseudocode?

Integer a,b,c

Set a=6,b=84

while(b>0)

b=b/2

a=a+6

c=a+b

while(c>40)

if(c mod 2 IS EQUAL TO 0)

Print a

else

Print b

c=c/10

End while

End while

Print c

Please explain this question

Hey Dinesh the output will be 12 1 48 4

Will you elaborate as acc to me it only prints 2 times.

Hey Dhruv, try putting blank spaces before a, b, c in cout statement, you’ll the the desired output