Pesudocode 1
Pesudocode 1
Integer N=1
Integer M=10
Integer I Ans:
Sum=0 i) 10
ii) Error
For I in range of N to M iii)11
Sum=sum+I iv) 55
Print sum.
2. Find the output for the following pseudocode
Integer N=5
Ans:
Integer M=10 1. 10 5
N=N XOR M 2. 5 10
3. 5 5
M=N XOR M 4. 10 10
N=N XOR M
Print N , M
3. Find the output for the following pseudocode
Integer i
Ans:
Set i = 3
1. 5 4 6
do
2. 6 5 4
print i + 3
3. 6 4 5
i=i–1
4. 4 6 5
while(i not equals 0)
end while
4. How many times the print statement will be executed
Integer a, b, c
Set a = 8, b = 10, c = 6
If(a > c AND (b + c) > a)
Print a
Ans:
end if
1. 1
if(c > b OR (a + c) > b)
2. 3
Print b
3. 0
end if
4. 4
if((b+c) MOD a EQUALS 0)
Print c
end if
Integer a, b, c
Ans:
Set a = 8, b = 51, c = 2
1. 15
c = (a ^ c)^ (a)
2. 17
b = b mod 4
3. 14
Print a + b + c
4. 13
Integer i, j, k Ans:
Set k = 8for(each i from 1 to 1) 1. 9
for(each j from the value of i to 1) 2. 4
print k+1 3. 2
end for 4. 7
end for
Integer a, b
Set a = 15, b = 7 Ans:
a = a mod (a - 3) 1. 4
b = b mod (b – 3) 2. 0
a = a mod 1 3. 6
b = b mod 1 4. 9
Print a + b
Integer a, b, c
Ans:
Set b = 5, a = 2, c = 2
1. 2
if(b>a && a>c && c>b)
2. 13
b=a+1
3. 5
Else
4. 7
a=b+1
End if
Print a + b + c
Consider an array of float. Calculate the Ans:
difference between the address of the 1st and 1. 16
4th element, assuming float occupies 4 bytes 2. 4
of memory. 3. 12
4. 5
What is the second part of a node in a linked Ans:
list that contains the address of the next node 1. Pointer
called? 2. Data
3. Link
4. Element
With the given information provided find out
the address of Arr[17] in a 1-D array Arr[30]. Ans:
1. 1070
- lower bound = 1 2. 1132
3. 1128
- starting base address = 1100 4. 1068
Read n
i=0 Ans:
While n%10!=0 1. 50
n=n+3 2. 55
i++ 3. 45
end while 4. 53
n=n+i
write n
What will be the output of the given pseudo code if n = 10
Read n
Initialize i to 5 Ans:
Initialize sum to 0 1. 25
while i < n 2. 35
increase sum by i 3. 45
increment i 4. 55
end while
Write sum
Predict the output of the given pseudo code if the value of number is 6
Read number
k=2 Ans:
i=2 1. 1700
while i<=number 2. 1440
k=k*i 3. 1560
i = i +1 4. 1340
end while
write k
What will be the number of " * " printed by the given pseudo code when input is 25
Ans:
1. Else if x is greater than the
mid element, then x can only
lie in left half subarray after
the mid element. So we recur
1.Compare x with the middle element. for left
2.If x matches with the middle element, we 2. Else if x is less than the mid
element, then x can only lie in
return the mid index. right half subarray after the
3.A mid element. So we recur for
right
4.Else ( x is smaller ) recur for the left half 3. Else if x is greater than the
mid element, then x can only
lie in right half subarray after
the mid element. So we recur
for right
4. None of the given options
Set Integer Emp_no=101 Ans:
Set Integer salary=0 1. Code executes successfully and
while (Emp_no=501) value of salary is displayed once.
salary=salary+100 2. Code executes successfully and
display salary nothing is displayed.
end while 3. Code executes successfully and
value of salary is displayed
infinite number of times.
4. Compile time error.
Ans:
Set Integer res=0 1. The program will not enter
do the loop.
--res 2. Code will run infinite number
display res of times.
res++ 3. Code will execute and value
while(res>=0) of res will be displayed twice.
end do-while 4. Code will execute and value
of res will be displayed once.
How many times will ‘#’ be displayed
for m = 0 to 4 step 1
Do Ans:
for n=0 to 4 step 1 1. 1
Do 2. 15
display '#'end-for 3. 8
if(m==2) then break 4. 2
end-if
end-for
for i=0 to 4 step 1 do
If i==i++ + --i then do Ans:
display i 1. 3 2 1 0
end-if 2. 1 2 3 4
end-for 3. 0
4. 2 0
Set Character c='7'
Ans:
switch(c)
1. Onehello
case '1': display "One"
2. Seventwohello
case '7': display "Seven"
3. Seventwo
case '2': display "Two"
4. seven
default: display "Hello"
break
end-switch
Integer a, p = 0 Ans:
Set a = 5 1. 0
a=a+1 2. 7
a=a*2 3. 1
a=a/2 4. 2
p=a/5+6
print p
Integer a, b, с Ans:
Set b = 8, a = 2 1. 3
c=a^b 2. 0
if (( c ^ b)) 3. 5
b=0 4. 7
End if
Print b
Integer a, b, c
Ans:
Set b = 40, a = 20, c = 20
1. 40
a=a+c
2. 100
c=c+a
3. 300
a=a+c
4. None of these
c=c+a
Print a + b + c
Integer a, b Ans:
Set a = 1, b = 1 1. 1
a = (a ^ 1) & (1) + (b ^ 1) & (1) 2. 2
Print a + b 3. 0
4. None of the above
int x=222
Ans:
while(x<225)
1. 0
{
2. 221 222
print x
3. 222 223
x=x++
4. None of the above
}
for i=0 to n-1
j=1
while j>0 and A[j]< A[j-1]
swap(A[j],A[j-1])
j=j+1
Ans:
1. Bubble sort is being implemented to sort an array
2. Merge sort is being implemented to sort an array
3. Insertion sort is being implemented to sort an array
4. The code doesn’t sort an array
int x Ans:
set x = 888 1. 1
if(x == 0) 2. 3
print "1" 3. 9
else if(x mod 9==0) 4. 6
print "9"
else print (x mod 9)
end if
Ans:
Integer x, y, z, a 1. 5
Set x=2, y=1, z=5 2. 2
a=(x AND y) OR (z+1) 3. 5
Print z 4. 0
int i Ans:
set i=6 do 1. 4 3 2 1 5 0
print i-1 2. 5 4 3 2 1 0
i=i-1 3. 0 1 2 3 4 5
while(i not equals 0) 4. 6 5 4 3 2 1
while loop ended
Set a=6, b=3, c=2 Ans:
if(b>a && a>c && c>b) 1. 11
b = a+1 2. 9
else 3. 5
a = b+1 4. Run time error
print a+b+c
main() Ans:
{ 1. Hai
while(!!7) 2. Haihai
printf("Hai"); 3. Infinite loop
return 0; 4. None of these
}
integer x =4, y = 0 Ans:
integer z 1. 1
z = (y++, y) 2. 0
print(z) 3. Undefined Behavior due to order of evaluation can be different.
4. Compilation error
Set j=1, k=1 Ans:
for each i from 1 to 5 : 1. 1 2 3 4 5
print(k) 2. 4 6 8 10
j+=1 3. 1 1 2 3 5
k+=j 4. 1 3 6 10 15
end-for
integer a = 40, b = 35, c = 20, d = 10 Ans:
Comment about the output of the following 1. Differ by 80
two statements: 2. Same
3. Differ by 50
print a * b / c – d 4. Differ by 160
print a * b / (c – d)
integer num = 8; Ans:
print( num << 1, num >> 1) 1. 8 0
2. 0 0
3. 16 4
4. error
integer a = 4, b = 2; Ans:
print(a^b) 1. 4
2. 1
3. 0
4. 6
int j=41, k= 37
Ans:
j=j+1
1. 42 36
k=k-1
2. 36 1
j=j/k
3. 1 1
k=k/j
4. 1 36
print(k,j)
integer a = 60, b = 35, c = -30 Ans:
What will be the output of the following two 1. 0 and 1
statements: 2. 0 and 0
3. 1 and 1
print ( a > 45 OR b > 50 AND c > 10 ) 4. 1 and 0
print ( ( a > 45 OR b > 50 ) AND c > 10 )
integer a = 984, b=10
float c Ans:
c=a/b 1. 984
print c 2. 98.4
3. 98.0
4. error
Ans:
Create integer Array ; 1. 82
Array elements ={ 2, 4, 5,78,9}; 2. 13
Sum Array even index elements ; 3. 14
4. 16
Print sum;
Create char c =’A’, b=’s’; Ans:
Integer n; 1. 180
Add c and b store n; 2. 148
Print n; 3. 150
4. 212
Create integer a, b, c ; Ans:
a=13; 1. 3
b=3; 2. 2
a Right shift of b store c; 3. 1
print c; 4. 0
Integer a=5;
Ans:
Print a pre increment , a post increment ;
1. 6 6 12
Integer b=5; 2. 7 6 13
Print b pre increment + b post increment; 3. 7 7 14
4. 7 5 13
Integer a , b , c;
Set the value of a=5 , b=11 , c=0; Ans:
1. 1 3 6
a= ++a + a++ - b++;
2. 0 3 5
b= ++b - --b + --a;
3. 1 4 6
c= ++b + ++b - a--; 4. 7 12 8
print a,b and c;
Integer n, k; Ans:
1. -44
Set n value 43;
2. -43
k = ~ n;
3. 44
print n 4. 45
Ans:
Integer n, k; 1. -14
Set n value -13; 2. -13
k = ~ n; 3. 12
print n; 4. 11
Integer n; Ans:
Set value of n =5; 1. 6
If(n=0) 2. 0
3. 2
Its true print n value ; 4. 1
Else
Print ++n;
Integer n; Ans:
Set value of n=10; 1. 10
Check the if Condition n equal to 10; 2. 11
Its true print n++; 3. 12
4. Compile time error
else
print n=n+2;