Day-1 Pseudo Code
Day-1 Pseudo Code
Integer a
String str1
Set str1 = “goose”
a = stringLength(str1)
Print (a ^ 1)
A) 0
B) 4
C) 5
D) 3
Ans: B
Integer a, b, c
Set a = 8, b = 51, c = 2
c = (a ^ c)^ (a)
b = b mod 4
Print a + b + c
A. 13
B. 17
C. 26
D. 16
Ans: A
3. Consider an array A = {1, 2, 4, 5, 6, 11, 12} and a key which is equal to 10.
How many comparisons would be done to find the key element in the array using the binary search?
A. 5
B. 1
C. 2
D. 3
Ans: D
A. 2
B. 9
C. 7
D. 8
Ans: B
5.What will be the output of the following pseudo code?
Integer a, b
Set a = 15, b = 7
a = a mod (a - 3)
b = b mod (b – 3)
a = a mod 1
b = b mod 1
Print a + b
A) 15
B) 7
C) 2
D) 0
Ans: D
A) 2
B) 13
C) 26
D) 5
Ans: B
7. If you are using Depth-first search (DFS) for traversing an unweighted graph, then which of the following will
happen?
1. It produces the minimum spanning tree
2. It produces all pair shortest path tree
Choose the correct answer from the options given below.
A) 6
B) 4
C) 0
D) 2
Ans: C
9. Which of the following series will be printed by the given pseudo code?
Integer i, j, k, n
Set j=1, k=1
for(each i from 1 to 5)
print k
j=j+1
k=k+j
end for
A) 1 3 6 10 15
B) 1 2 3 4 5
C) 2 4 6 8 10
D) 1 1 2 3 5
Ans:A
Integer value, n
Set value = 1, n = 45
While (value less than equal to n)
value = value << 1
end loop
Print value
A) 64
B) 32
C) 45
D) None of the above
Ans:A
Integer i
Set i = 3
do
print i + 3
i=i-1
while(i not equals 0)
end while
A) 6 6 6
B) 6 5 6
C) 5 5 5
D) 6 5 4
Ans:D
integer x
x= 5>7+3 && 8
Print x
a. 0
b. 1
c. 9
d. Compilation error
Ans:A
14. Select the most appropriate output for the following pseodo code:
Integer x=-7810
Integer d,e
d=!x
e=~x
Print d,e
a. 0 7811
b. 0 7809
c. 1 7809
d. 1 0
Ans:B
15. Select the most appropriate output for the following pseudo code:
Integer r = -5
Integer s = 1
s = r &= s && 100
Print r,s
a. -100 1
b. 1 0
c. 1 1
d. Error
Ans:C
16. Select the most appropriate output for the following pseudo code:
Integer z=4
Print (2<<z-2<<2)
a. 128
b. 32
c. 24
d. None
Ans:B
A) Hurray
B) HurrayYes
C) England
D) None of the above
Ans:B
print("1")
goto line1
print("2")
goto line2 //line1
printf("%d ", 3);
line2:printf("%d ", 4);
return 0;
a) 1 4
b) Compilation error
c) 1 2 4
d) 1 3 4
Ans:A
integer i = 0, j = 0
repeat while (i < 2)
i=i+1//line-1
repeat while (j < 3)
print "Loop"
goto line-1
end loop
end loop
a) Loop Loop
b) Compilation error
c) Loop LoopLoopLoop
d) Infinite Loop
Ans:D
#include <stdio.h>
int main()
{
int i = 0, k;
if (i == 0)
goto label;
for (k = 0;k< 3; k++)
{
printf("hi\n");
label: k = printf("%03d", i);
}
return 0;
}
a) 0
b) hi hihi 0 0 0
c) 0 hi hihi 0 0 0
d) 0 0 0
Ans:D
if ( n<= 1 )
{
*fp = 1;
return 1;
}
t = fun ( n-1, fp );
f = t + *fp;
*fp = t;
return f;
}
int main()
{
int x = 15;
printf("%d\n",fun(5, &x));
return 0;
}
a) 8
b) 7
c) 6
d) 5
Ans:A
23. Find output of the following pseudo code for fun(4, 3).
Integer fun(Integer a, Integer b)
IF (b == 0)
return 0
IF (b MOD 2 EQUALS 0)
return fun(a+a, b/2)
return fun(a+a, b/2) + a
end fun
a)12
b)11
c)10
d)13
Ans:A
a)3
b)4
c)5
d)2
Ans:A
#include<stdio.h>
void test(int * , int *);
main()
{
int a = 5 , b = 6;
test(&a,&b);
printf("%d %d",a,b);
}
void test(int *p, int *q)
{
*p = *p * *q;
*q = *p / *q;
*p = *p / *q;
}
A. 30 5
B. 6 5
C. 5 6
D. None of the above
Ans:B
Double pi = 3.141
Integer a = 1
Integer i
for each i 0 to 2:
If a = cos(pi * i/2)
Print "1"
Else
Print "0"
A)000
B)010
C)101
D)111
Ans:C
27. What does the above program print foo (2048, 0)?
void foo(Integer n, Integer sum)
Integer k = 0, j = 0
IF (n EQUALS 0)
return
k = n MOD 10
j = n / 10;
sum = sum + k
foo (j, sum)
Print (k)
end foo
A)2, 0, 4, 8
B)8, 4, 0, 2
C)2, 1, 4, 8
D)none of these
Ans:A
int show()
{
return 15.5;
return 35;
}
A) 15.5
B) 15
C) 0
D) Compiler error
Ans:B
Integer a=5
Repeate while a >= 3:
Print "HELLO"
Go out from loop
end loop
Print "HI"
A) HI
B) HELLO HI
C) HELLO is printed infinite times
D) None of the above
Ans:B
Integer i, j
for(each i from 0 to 2)
for(each j from i to 3)
Print (j)
Go out from loop
end loop
end loop
(A)0
(B)0 1 2
(C)0 1 2 3
(D)0 1 2 1 2 3 2 3 3
Ans:B
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
Print a b c
a) 5 3 9
b) 6 4 14
c) 6 4 16
d) 6 14 17
Ans:C
32. what will be the output of the following pseudocode for input 7?
a) 32
b) 76
c) 56
d) 28
Ans:D
33. What will be the output of the following pseudocode if we call fun(2) ?
a) 2
b) 4
c) 8
d) 16
Ans:D
1. Integer x, y , z, a
2. Set x = 2, y = 1, z = 5
3. z = (x AND y) OR (z + 1)
4. Print z
a) 2
b) 5
c) 1
d) 3
Ans:C
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
A) 14 26 38
B) 27 39
C) 15 27 39
D) None of the above
Ans:C
1. Integer a, b, c
2. Set a = 8, b = 10, c = 6
3. if(a > c AND (b + c) > a)
4. Print a
5. end if
6. if(c > b OR (a + c) > b)
7. Print b
8. end if
9. if ((b + c) MOD a EQUALS 0)
10. Print c
11. end if
a) 0
b) 1
c) 2
d) 3
Ans:D
1. Integer x, y, z
2. Set x = 24, y = 8
3. x = x / y
4. z = y << x
5. Print z
a) 1
b) 8
c) 32
d) 64
Ans:D
38. What will be the output of the following pseudocode if a = 10 and b = 6, c=?
a) 1
b) 2
c) 3
d) 4
Ans:B
void reverse(int n)
{
if (n > 5)
exit(0);
printf("%d\n", n);
return reverse(n++);
}
int main()
{
reverse(1);
}
a) Segmenation fault
b) Compilation error
c) Print 1 Infinite time
d) Both a & c
Ans:D
40. What will be the output of the following pseudocode for fun("pqr") ?
fun(char *a)
if (*a EQUALS NULL)
return
end if
fun(a+1)
fun(a+1)
print *a
a) ppqqrr
b) rrqrqqp
c) rrqrrqp
d) rqppqr
Ans:C
41. What will be the output of the following pseudocode for fun(99)?
1. Integer fun(Integr n)
2. if (n > 100)
3. return n - 10
4. return fun(fun(n+11))
5. end function fun()
a) 91
b) 100
c) 110
d) 121
Ans:A
42. What will be the output of the following pseudocode?
1. Integer a = 10
2. Integer b = 2
3. Integer c
4. c=(a & b)
5. Print c
a) 0
b) 2
c) 10
d) 12
Ans:B
Integer a, b, c
Set b = 2, c = 4
for (each a from 1 to 4)
b = b >> 1
c = c << b
end for
Print b+c
a) 2
b) 4
c) 1
d) 8
Ans:D
Integer a, p
Set a = 8
p = a + 2/5 * 8
Print p * 6
a) 252
b) 48
c) 256
d) 50
Ans:B
a) 55
b) 45
c) 6
d) None of these
Ans:C
1. Integer a = 0 , b = 1 , c = 2
2. b=( ( a+1==1) ? a&b : c&a) ? b : c;
3. Print a , b, c
a) 0 1 2
b) 0 2 0
c) 0 2 2
d) 0 0 2
Ans:C
47. What will be the output of the following pseudocode if a=10, b=60 ,c=20 ?
a) 0 and 0
b) 0 and 1
c) 1 and 0
d) 1 and 1
Ans:C
1. Integer num = 8
2. Print num<<1, num>>1
a) 8 0
b) 0 0
c) 16 4
d) 16 0
Ans:C
1. Integer i = 16
2. i = !i > 15
3. Print i
a) i = -1
b) i = 0
c) i = 1
d) i = 2
Ans:B
1. Integer i = 5, j = 4
2. if(!print(“”))
3. Print i, j
4. else
5. Print i++, ++j
a) 5 5
b) 5 4
c) 5 6
d) 6 6
Ans:B
a) 8, 9
b) 4, 5
c) 8, 8
d) 4, 4
Ans:B
a) 13
b) d
c) 22
d) 10
Ans:A
Integer x = 10
x &= ~2
Print x
a) 10
b) 8
c) 12
d) 0
Ans:B
Integer a[6], p, j, q
Set p = 3
Set a[6] = {3,6,10,12,23,33}
for (each j from 0 to 5)
if((a[j] MOD p) EQUALS 0)
p =a[j] - (p*3)
end if
q = p + a[j] - 3
end for
print q
a) 51
b) 52
c) 53
d) 54
Ans:D
var[++count]=++count;
for(count=0;count<5;count++)
printf("%d ",var[count]);
return 0;
}
A) 0 1 2 0 0
B)1 2 0 0 0
C) 0 0 2 0 0
D) None of these
Ans:C
char X[10]={'A'},i;
printf("%d ",X[i]);
A) 65 0 0 0 0 0 0 0 0 0 0
B) A \0 \0 \0 \0 \0 \0 \0 \0 \0
C) 65 Garbage ( nine times)
D) None of these
Ans:C
printf(str,a);
}
A) value is ='7'
B) value is = 54
C) Error
D) value is =7
Ans:D
if (printf("Hello") == strlen("Hello"))
printf("...Friends");
else
printf("...Enemies");
return 0;
}
A) Hello...Friends
B) ...Friends
C) Hello...Enemies
D) Enemies
Ans:A
A) True
B) False
C) Nothing will be printed
D) None of these
Ans:A