Pseudo Code - Loops
Question 1
What will be the output of the following pseudocode?
Integer i
Set i = 3
do
print i + 3
i=i–1
while(i not equals 0)
end while
Question 1
A) 666
B) 656
C) 555
D) 654
Question 1
A) 666
B) 656
C) 555
D) 654
Question 2
What will be the output of the following pseudocode?
#include <iostream>
using namespace std;
int main ()
{
int n;
for (n = 5; n > 0; n--)
{
printf("%d",n);
if (n == 3)
break;
}
}
Question 2
A) 543
B) 54
C) 5432
D) 53
Question 2
A) 543
B) 54
C) 5432
D) 53
Question 3
What would be the output of the following
pseudocode?
Integer i, j, k
Set k = 8
for(each i from 1 to 1)
for(each j from the value of i to 1)
print k+1
end for
end for
Question 2
A) 2
B) 9
C) 7
D) 8
Question 2
A) 2
B) 9
C) 7
D) 8
Question 4
What will be the output of the following pseudocode?
Set x to 1
Set y to 1
while(x<20)
write x
x=x+5
y=y+5
End while
Question 4
A) 1 1 6 6 11 11 16 16
B) 1 5 10 15
C) 1 6 11 16
D) None of these
Question 4
A) 1 1 6 6 11 11 16 16
B) 1 5 10 15
C) 1 6 11 16
D) None of these
Question 5
What will be the output of the following pseudocode?
Input t = 6, h = 9 and set x = 0
Integer c
if (h > t)
for (c = t; c < h; c = c + 1)
x=x+c
End for loop
print x
else
print error message
Question 5
A) 21
B) 15
C) 9
D) 6
Question 5
A) 21
B) 15
C) 9
D) 6
Question 6
What will be the output of the following pseudocode? N=7
1. read the value of n
2. set m=1,t=0
3. if m >= n
4. go to line 9
5. else
6. t=t+m
7. m+=1
8. go to line 3
9. display T
Question 6
A) 32
B) 76
C) 28
D) 21
Question 6
A) 32
B) 76
C) 28
D) 21
Question 7
What will be the output of the following pseudocode?
Integer a, b, c, d
Set b = 18, c = 12
a=b–c
for (each c from 1 to a – 1)
b = b + c + 12
b = b/5
d=b+a
end for
c=a+b+c
Question 7
A) 539
B) 6 14 17
C) 6 4 14
D) 6 4 16
Question 7
A) 539
B) 6 14 17
C) 6 4 14
D) 6 4 16
Question 8
What will be the output of the following pseudocode? limit=6
Read limit
n1 = 0, n2= 1, n3=1, count = 1;
while count <= limit
count=count+1
print n3
n3 = n1 + n2
n1 = n2
n2 = n3
Question 8
A) 112358
B) 12358
C) 123581321
D) 12358132
Question 8
A) 112358
B) 12358
C) 123581321
D) 12358132
Question 9
What will be the output of the following pseudocode?
Set x =0 and y =1
for(int i=1; i<=4; i=i+1)
print x
x=x+y
y=x/y
End of loop
Question 9
A) 1024
B) 0138
C) 0124
D) 0123
Question 9
A) 1024
B) 0138
C) 0124
D) 0123
Question 10
What will be the output of the following pseudocode?
int main ()
{ int no = 1112, temp, digit, sum = 1;
temp = no;
while (no > 0)
{
digit = no % 10;
sum = sum * digit;
no /= 10;
}
Question 10
A) 25
B) 7
C) 5
D) 2
Question 10
A) 25
B) 7
C) 5
D) 2
Question 11
What will be the output of the following pseudocode?
integer a,b
Set a=2; b=90
while(b>9)
a = b%2 + a
if( a%2 != 0)
Print a
else
Print b
b = b/2
Question 11
A) 3 90 11 3
B) 11 3 3 90
C) 90 3 3 11
D) 3 3 90 11
Question 11
A) 3 90 11 3
B) 11 3 3 90
C) 90 3 3 11
D) 3 3 90 11
Question 12
What will be the output of the following pseudocode?
Integer n, rev, rem, orig; if(orig is Equal to rev)
Set n=1331; rev=0; Print Palindrome
Set orig=n; else
Repeat while n Not Equals 0 Print Not
Palindrome
rem=n%10; End if
rev=(rev*10)+rem;
n=n/10;
Question 12
A) Not Palindrome
B) Runtime Error
C) Palindrome
D) Compiletime Error
Question 12
A) Not Palindrome
B) Runtime Error
C) Palindrome
D) Compiletime Error
Question 13
What is the intention of the following pseudocode?
int main()
{
int p = 2, q = 3;
for (int i = 0; i <= 6; i = i + 2){
p = p + q + i;
p = p + q;
q = p - q;
printf("%d ",q);
}
Question 13
A) 30 10 27 70
B) 5 15 39 99
C) 13 10 47 70
D) 13 10 27 70
Question 13
A) 30 10 27 70
B) 5 15 39 99
C) 13 10 47 70
D) 13 10 27 70
Question 14
What will be the output of the following pseudocode?
int main()
{
int a=15, b=25;
for(int i=0;i<5;i++)
{
if(i%2==0)
++a;
else
++b;
}
printf("%d %d",a,b);
Question 14
A) 15 25
B) 18 27
C) 27 18
D) 25 15
Question 14
A) 15 25
B) 18 27
C) 27 18
D) 25 15
Question 15
What will be the output of the following pseudocode?
int main()
{ int n = 1;
do
{
printf("%d", n);
n--;
if (n > 15)
continue;
}
while (0);
Question 15
A) 15
B) 1
C) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
D) Runtime Error
Question 15
A) 15
B) 1
C) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
D) Runtime Error
Question 16
What will be the output of the following pseudocode?
int main()
{
integer num;
for(num equals to 80; num!=0; num++)
Write num++
}
Question 16
A) Error
B) 140
C) Infinite loop
D) None of the above
Question 16
A) Error
B) 140
C) Infinite loop
D) None of the above
Question 17
What will be the output of the following pseudocode?
Declare a=0, I and b
for I =0 to 4
Increment a by 1
if I = 3 then
print hello
get out of the loop
End if
End for
print a
Question 17
A) Hello4
B) Hello
C) Hello3
D) Error
Question 17
A) Hello4
B) Hello
C) Hello3
D) Error
Question 18
What will be the output of the following pseudocode?
Input n = 1234
Integer q, r and rn
Set q=n and rn = 0
While (q > 0)
r = q mod 10
rn = rn + r^3
q= q / 10
End of loop
print rn
Question 18
A) 1000
B) 100
C) 101
D) 102
Question 18
A) 1000
B) 100
C) 101
D) 102
Question 19
What will be the output of the following pseudocode?
Integer a, b, c, d, e
Set a=50 , b=3, c=3 e=0
while(c>0)
d=a mod b
e= e + d + a
c= c – 1
End while
Print e
Question 19
A) 165
B) 156
C) 170
D) Error
Question 19
A) 165
B) 156
C) 170
D) Error
Question 20
What will be the output of the following pseudocode?
Integer n, rev, rem, orig; if(orig is Equal to rev)
Set n=63206; rev=0; Print rev
Set orig=n; else
Repeat while n Not Equals 0 Print (orig-rev)/6
rem=n%10; End if
rev=rev*10+rem;
n=n/10;
End while
Question 20
A) 492
B) 490
C) 496
D) 495
Question 20
A) 492
B) 490
C) 496
D) 495
Question 21
What will be the output of the following pseudocode?
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
Question 21
A) 12 2 48 4
B) 12 1 48 4
C) 12 1 48 5
D) 12 1 48 9
Question 21
A) 12 2 48 4
12 1 48 4
B)
C) 12 1 48 5
D) 12 1 48 9
Question 22
What will be the output of the following pseudocode?
Integer c, d
Set c = 15, d = 12
d=c–1
Print c //line
c = d + (c – 2)
if(c < 40)
Goto line
end if
Question 22
A) 14 26 38
B) 27 39
C) 15 27 39
D) None of above
Question 22
A) 14 26 38
B) 27 39
C) 15 27 39
D) None of above
Question 23
What will be the output of the following pseudocode?
for (i = 1; i <= 6; i++)
for (j = i; j < 6; j++)
Print blank space
for (k = 1; k < (i * 2); k++)
Print *
End for
Line break
End for
Question 23
A) * *** ***** ******* *********
B) * ** *** ***** ******* *********
C) * *** ***** ******* ********* ***********
D) None of above
Question 23
A) * *** ***** ******* *********
B) * ** *** ***** ******* *********
C) * *** ***** ******* ********* ***********
D) None of above
Question 24
What will be the output of the following pseudocode?
Set a=2; b=50;
while(b>0)
a = b%2 + a;
if( a MOD 2 Is Equal To 0)
Printf a
else
Print b-1
b = b/5
a=a+1
Question 24
A) 294
B) 492
C) 8 18 4
D) Error
Question 24
294
A)
B) 492
C) 8 18 4
D) Error
Question 25
What will be the output of the following pseudocode?
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
Question 25
A) 9 8 15
B) 6 33 9
C) 9 33 6
D) None of abovr
Question 25
A) 9 8 15
B) 6 33 9
C) 9 33 6
D) None of abovr
Question 26
What will be the output of the following pseudocode?
int main()
{
int i=1,j;
for(;;)
{
if(i)
j=--i;
if(j<5)
printf("Advance ",j++);
else
break;
}
return 0;
Question 26
A) No, Compile error but it will print Advance 4-times
B) No, Compile error but it will print Advance 5-times
C) No, Compile error but it will print Advance 6-times
D) Compile error
Question 26
A) No, Compile error but it will print Advance 4-times
B) No, Compile error but it will print Advance 5-times
C) No, Compile error but it will print Advance 6-times
D) Compile error
Question 27
What will be the output of the following pseudocode? Infosys 23-01-2022
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
Question 27
A) 9 33
B) 9 30
C) 9 36 9
D) 9 33 6
Question 27
A) 9 33
B) 9 30
C) 9 36 9
D) 9 33 6
Question 28
What will be the output of the following pseudocode?
int main()
{
for (int x = 10; x >= 0; x--)
{
int z = x & (x >> 1);
if (z)
printf("%d ", x);
}
}
Question 28
A) 127
B) 10 9 8
C) 763
D) 963
Question 28
A) 127
B) 10 9 8
C) 763
D) 963
Question 29
What will be the output of the following pseudocode?
int main()
{
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<i;j++)
{
printf("%d ",i+j);
}
Question 29
A) 1233454567
B) 1223334444
C) 1121231234
D) 123451234
Question 29
A) 1233454567
B) 1223334444
C) 1121231234
D) 123451234
Question 30
What will be the output of the following pseudocode?
int main ()
{
int a = 0, i = 0, b;
for (i = 0; i < 5; i++)
{
a++;
while(a+i<5)
printf ("Hello world\n");
}
printf ("%d", a);
}
Question 30
A) print hello world for 5 times, and then print 6
B) print hello world for 5 times, and then print 1
C) Code will stuck in infinite loop
D) 5
Question 30
A) print hello world for 5 times, and then print 6
B) print hello world for 5 times, and then print 1
C) Code will stuck in infinite loop
D) 5
Question 31
What will be the output of the following pseudocode?
void main ()
{
int k = 4;
while(k>10)
k=k*k;
k++;
printf ("%d", k);
}
Question 31
A) 4096
B) 256
C) 16
D) 5
Question 31
A) 4096
B) 256
C) 16
D) 5
Question 32
What will be the output of the following pseudocode?
Set x = 0 and y = 1
while(x<5)
print x
x=x+y
x++
End of loop
Question 32
A) 024
B) 023
C) 124
D) 038
Question 32
A) 024
B) 023
C) 124
D) 038
Question 33
What will be the output of the following pseudocode if n=2?
Code/Pseudo Code
1 Integer fun(Integer n)
2 if (n IS EQUAL TO 4)
3 return n
4 end if
5 else
6 return 2 *fun(n+1)
7 end function fun()
8
9
10
11
12
13
14
Question 33
A) 6
B) 16
C) 4
D) 2
Question 33
A) 6
B) 16
C) 4
D) 2
Question 34
What will be the output of the following pseudocode?
Code/Pseudo Code
1 Integer a,b,
2 set a=2, b=12
3 c=b<<a
4 print c
5
6
7
8
9
10
11
12
13
14
Question 34
A) 48
B) 16
C) 4
D) 6
Question 34
A) 48
B) 16
C) 4
D) 6
Question 35
What will be the output of the following pseudocode?
Code/Pseudo Code
1 integer a,b,c,d set n=456 , a=0, b=1
2 while (n>0)
3 d=n mod 10
4 a=a+d
5 b=b*d
6 n=n/10
7 end while
8 print a
9 print b
10
11
12
13
14
Question 35
A) 15 120
B) 64 120
C) 12 24
D) None of the above
Question 35
A) 15 120
B) 64 120
C) 12 24
D) None of the above
Question 36
What will be the output of the following pseudocode?
Code/Pseudo Code
1 Integer c,n
2 Set n=6
3 Set c=n
4 print c
5 c = c-2
6 if(c>0)
7 Go to the line number 4
8 end if
9
10
11
12
13
14
Question 36
A) 0246
B) 642
C) 024
D) 6420
Question 36
A) 0246
B) 642
C) 024
D) 6420
Question 37
What will be the output of the following pseudocode?
Code/Pseudo Code
1 Integer n,b
2 for(each i from 1 to n)
3 b= i MOD 9
4 if(b EQUALS 0)
5 print i
6 End if
7 End for
8
9
10
11
12
13
14
Question 37
A) to print all number from 1 to n which is divisible by 9 only
B) to print all number from 1 to n which is divisible by 3,6 and 9
C) to print all number from 1 to n which is divisible by 3 and 9
D) None of the above
Question 37
A) to print all number from 1 to n which is divisible by 9 only
B) to print all number from 1 to n which is divisible by 3,6 and 9
C) to print all number from 1 to n which is divisible by 3 and 9
D) None of the above
Question 38
What will be the output of the following pseudocode?
Code/Pseudo Code
1 Integer m,j,a[]
2 set a[]={2,3,5,7,1}
3 m=a[0]
4 for (j from 0 to 4)
5 if (m<a[j])
6 m=a[j]
7 end if
8 end for
9 print m
10
11
12
13
14
Question 38
A) 5
B) 2
C) 1
D) 7
Question 38
A) 5
B) 2
C) 1
D) 7
Question 39
What will be the output of the following pseudocode if n=99?
Code/Pseudo Code
1 Integer fun(Integer n)
2 if (n>100)
3 return n - 10
4 return fun (fun (n+11))
5 end function fun()
6
7
8
9
10
11
12
13
14
Question 39
A) 121
B) 91
C) 100
D) 110
Question 39
A) 121
B) 91
C) 100
D) 110
Question 40
What will be the output of the following pseudocode?
Code/Pseudo Code
1 Integer a,b,cout,cout1
2 set a=2 ,b=3
3 while(a<=5)
4 b=2
5 while(b<=4)
6 b=b+2
7 cout1 = cout1+1
8 end while
9 a=a+1
10 cout=cout+1
11 end while
12 print cout,cout1
13
14
Question 40
A) 84
B) 48
C) 16 8
D) 81
Question 40
A) 84
B) 48
C) 16 8
D) 81
Question 41
What will be the output of the following pseudocode if the input given is
“pqr”?
Code/Pseudo Code
1 fun(char *a)
2 If (*a EQUALS NULL)
3 return
4 end if
5 fun(a+1)
6 fun(a+1)
7 print *a
8 end function fun
9
10
11
12
13
14
Question 41
A) rrqrrqp
B) ppqqrr
C) rqppqr
D) none of the mentioned option
Question 41
A) rrqrrqp
B) ppqqrr
C) rqppqr
D) none of the mentioned option
Question 42
How many times A will be printed?
Code/Pseudo Code
1 Integer i,j,k,A
2 for(each i=0 to 4)
3 for(each j=0 to 2)
4 for(each k=0 to j-1)
5 print A
6 end for
7 end for
8 end for
9
10
11
12
13
14
Question 42
A) 15
B) 12
C) 16
D) 8
Question 42
A) 15
B) 12
C) 16
D) 8
Question 43
What will be the output of the following pseudocode if n=1?
Code/Pseudo Code
1 void reverse(int n)
2 if (n greater than 5)
3 exit
4 print n
5 return reverse(n++)
6 end function reverse()
7
8
9
10
11
12
13
14
Question 43
A) 12345
B) 12468
C) 12534
D) None of the above
Question 43
A) 12345
B) 12468
C) 12534
D) None of the above
Question 44
What will be the output of the following pseudocode ?
Code/Pseudo Code
1 Integer a,b,cout Set a=2,cout =0,b=1
2 while(b<121)
3 b=a*b
4 cout=cout+1
5 b=b+1
6 end while
7 print cout
8
9
10
11
12
13
14
Question 44
A) 6
B) 127
C) 120
D) 7
Question 44
A) 6
B) 124
C) 120
D) 7
Question 45
What will be the output of the following pseudocode?
Code/Pseudo Code
1 integer a,b,v,c
2 set a=7 ,b=12,v=70
3 while(v>5)
4 a=a-v
5 c=(a+b)mod 10
6 while(c>7)
7 b=b+c
8 end while
9 end while
10 print b,c
11
12
13
14
Question 45
A) Infinte loop
B) 12 4
C) 12 1
D) 12 7
Question 45
A) Infinite loop
B) 12 4
C) 12 1
D) 12 7
Question 46
What will be the output of the following pseudocode?
Code/Pseudo Code
1 Integer a, b = 10
2 Set n = 2
3 for (each a from 1 to 6)
4 a = a + 2
5 end for
6 Print b
7
8
9
10
11
12
13
14
Question 46
A) 18
B) 10
C) 11
D) 14
Question 46
A) 18
B) 10
C) 11
D) 14
Question 47
What will be the output of the following pseudocode?
Code/Pseudo Code
1 Integer a = 0
2 Set n = 2
3 for (each a from 1 to n)
4 a = a + 2
5 end for
6 Print a
7
8
9
10
11
12
13
14
Question 47
A) 4
B) 6
C) 2
D) 8
Question 47
A) 4
B) 6
C) 2
D) 8
Question 48
What will be the output of the following pseudocode?
Code/Pseudo Code
1 Integer a = 0
2 Set n = 2, i = 0
3 if ( n % i == 0)
4 a = a + 2
5 end if
6 Print a
7
8
9
10
11
12
13
14
Question 48
A) Error
B) 6
C) 2
D) 8
Question 48
A) Error
B) 6
C) 2
D) 8
Question 49
What will be the output of the following pseudocode?
Code/Pseudo Code
1 Integer a = 10, b = 20
2 a = a XOR b
3 b = a XOR b
4 a = a XOR b
5 Print a
6 Print b
7
8
9
10
11
12
13
14
Question 49
A) 10 20
B) 20 10
C) 15 15
D) 1010 10100
Question 49
A) 10 20
B) 20 10
C) 15 15
D) 1010 10100
THANK YOU