0% found this document useful (0 votes)
126 views17 pages

Day-1 Pseudo Code

Uploaded by

Kaushiki Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views17 pages

Day-1 Pseudo Code

Uploaded by

Kaushiki Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Day-1

1. What would be the output of the following 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

2. What would be the output of the following pseudo code?

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

4. What would be the output of the following pseudo code?


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

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

6.What will be the output of the following pseudo code?


Integer a, b, c
Set b = 5, a = 2, c = 2
if(b>a && a>c && c>b)
b=a+1
Else
a=b+1
End if
Print a + b + c

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. Both 1 and 2 are true


B. Both 1 and 2 are false
C. Only 2 is true
D. Only 1 is true

8. What will be the output of the following pseudo code?


Integer a, b, c
Set b = 2, a = 2
c=a^b
Print c

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

10. Find the output of the following pseudo-code:

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

11. What will be the output of the following pseudo code?

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

12.Select the most appropriate output of the following pseudo code:

integer a=10, b=3, c=2, d=4, result


result=a+a*-b/c%d+c*d
Print result
a. -42
b. 24
c. -34
d. 15
Ans:D
13. What will be the output?

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

17.What is the output of following pseudo code?


Integer x=10
If( 4islessthan 5 )
Print "Hurray"
If (x not equals 0)
Print "Yes"
else
printf("England");

A) Hurray
B) HurrayYes
C) England
D) None of the above
Ans:B

18. What is the output of C Program with switch statement or block?


#include<stdio.h>
int main()
{
int k=8;
switch(k)
{
case 1==8:
printf("ROSE ");
break;
case 1 && 2:
printf("JASMINE ");
break;
default:
printf("FLOWER ");
}
printf("GARDEN");
}
A) ROSE GARGEN
B) JASMINE GARDEN
C) FLOWER GARDEN
D) Compiler error
Ans:C

19. What will be the output of the following pseudo code?

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

20.What will be the output of the following pseudo code?

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

21. What will be the output of the following C code?

#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

22. Find output of the following.


int fun ( int n, int *fp )
{
int t, f;

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

24. Find output of the following code for fun1(8).


Integer fun1(Integer n)
IF(n == 1)
return 0
ELSE
return 1 + fun1(n/2)
end fun1

a)3
b)4
c)5
d)2
Ans:A

25.What is the output of this program?

#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

26. What would the program print?

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

28. What is the output of C program with functions.?


int show();
void main()
{
int a;
a=show();
printf("%d", a);
}

int show()
{
return 15.5;
return 35;
}
A) 15.5
B) 15
C) 0
D) Compiler error
Ans:B

29. What is the output of following pseudo code?

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

30. What will be the output of following pseudo code?

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

31. 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
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?

1. Read the value of N.


2. Set m = 1, T = 0
3. if m > n
4. Go to line no. 9
5. else
6. T=T+m
7. m=m+1
8. Go to line no. 3
9. Display the value of T
10. Stop

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) ?

1. int fun (int n)


2. if (n EQUALS 4)
3. return n
4. else
5. return 2 * fun (n + 1)

a) 2
b) 4
c) 8
d) 16
Ans:D

34. What will be the output of the following pseudocode ?

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

35. 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

A) 14 26 38
B) 27 39
C) 15 27 39
D) None of the above
Ans:C

36. How many times will the print statement be executed?

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

37. What will be the output of the following pseudocode ?

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=?

1. Integer func (Integer a, Integer b)


2. Integer temp
3. while (b)
4. temp = a MOD b
5. a=b
6. b = temp
7. end while
8. return a
9. End function func()

a) 1
b) 2
c) 3
d) 4
Ans:B

39. What will be the output of the following pseudocode?

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

43. What will be the output of the following pseudocode?

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

44. What will be the output of the following pseudocode?

Integer a, p
Set a = 8
p = a + 2/5 * 8
Print p * 6

a) 252
b) 48
c) 256
d) 50
Ans:B

45. What will be the output of the following pseudocode?

Integer a[3][3], k , j, sum


Set sum = 0
Set a[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}}
for each k from 0 to 2:
for each j from 0 to 2:
sum = sum + a[k][j]
end for
jump out of the loop
end for
print sum

a) 55
b) 45
c) 6
d) None of these
Ans:C

46. What will be the output of the following pseudocode?

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 ?

1. Print ( a > 45 OR b > 50 AND c > 10 )


2. Print ( ( a > 45 OR b > 50 ) AND c > 10 )

a) 0 and 0
b) 0 and 1
c) 1 and 0
d) 1 and 1
Ans:C

48. What will be the output of the following pseudocode?

1. Integer num = 8
2. Print num<<1, num>>1

a) 8 0
b) 0 0
c) 16 4
d) 16 0
Ans:C

49. What will be the output of the following pseudocode?

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

50. What will be the output of the following pseudocode?

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

51. What will be the output of the following pseudocode?


Character var=0x04
var = var | 0x04
Print var
var |= 0x01
Print var

a) 8, 9
b) 4, 5
c) 8, 8
d) 4, 4
Ans:B

52. What will be the output of the following pseudocode?


Character flag=0x0f
flag &= ~0x02
Print flag

a) 13
b) d
c) 22
d) 10
Ans:A

53. What will be the output of the following pseudocode?

Integer x = 10
x &= ~2
Print x

a) 10
b) 8
c) 12
d) 0
Ans:B

54. What will be the output of the following pseudocode?

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

55. What will be the output of the folowing code?


int main()
{
static int var[5];
int count=0;

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

56. What will be the output of the given code?

char X[10]={'A'},i;

for(i=0; i<10; 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

57. What will be the output of the following code?


int main()
{
int val=0;
char str[]="ABC";
val=strcmp(str,"ABC");
printf("%d",val);
return 0;
}
A) 0
B) 1
C) -1
D) None of these
Ans:A

58. What will be the output of the code?


main()
{
char str[]="value is =%d";
int a='7';
str[11]='c';

printf(str,a);
}

A) value is ='7'
B) value is = 54
C) Error
D) value is =7
Ans:D

59. What will be the output of the following code?

if (printf("Hello") == strlen("Hello"))
printf("...Friends");
else
printf("...Enemies");
return 0;
}

A) Hello...Friends
B) ...Friends
C) Hello...Enemies
D) Enemies
Ans:A

60. What will be the output of the following code?


void main()
{
int x=22;
if(x=10)
printf("TRUE");
else
printf("FALSE");
}

A) True
B) False
C) Nothing will be printed
D) None of these

Ans:A

You might also like