100% found this document useful (1 vote)
1K views10 pages

PseudoCodes HCL

The document contains a series of technical pseudo multiple-choice questions (MCQs) related to programming concepts and algorithms. It covers topics such as function definitions, loops, conditionals, data types, and array manipulations. Each question is presented in a pseudo-code format, requiring the reader to analyze and determine the output or behavior of the code snippets.

Uploaded by

arjunarjun17383
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views10 pages

PseudoCodes HCL

The document contains a series of technical pseudo multiple-choice questions (MCQs) related to programming concepts and algorithms. It covers topics such as function definitions, loops, conditionals, data types, and array manipulations. Each question is presented in a pseudo-code format, requiring the reader to analyze and determine the output or behavior of the code snippets.

Uploaded by

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

HCL Technical Pseudo MCQs !

0)Int fun(Integer X) x=5

if(x>0)

fun(x-3)

print x

fun(x-2)

end if

End fun

1)Double a
Set a=5*4-6/5; //precedence &associative
Print a;

2)Int q
Set q=0
For(each q from 0 to 8)->for(q=0;q<8;q++)

q=q+1

if(q equals 6)

print yes

Jump out of loop


endif
end for
print q

3) x=49

Int fun(Integer x)

if((x mod 10) equals (x/10))

return x/7

else

return fun(fun(x/7))

4)Integer m,k,a[]

Set a[]={3,6,8,1,4,9}

m=a[0]

for(each k from 1 to 6)

if(m greater than a[k])


m=a[k]

end if

end for

print m

6)Set x = 2147483647
Set y = x + 1
Print y

//Explain Data Type range model Questions !

7)Set x = 10
While x > 0
Set x = x - 1
If x == 5 Then
Break
End If
End While
Print x

8)Set a = 4
Set b = 5
a = a ^ b
b = a ^ b
a = a ^ b
Print a, b

9)Set a = 9 //
Set b = 7 //
Set c = a & b
Set d = a | b
Set e = a ^ b
Print c, d, e

10)Function fun(x, n)
If n == 0 Then
Return 1
End If
If n % 2 == 0 Then
Set half = fun(x, n / 2)
Return half * half
Else
Return x * Power(x, n - 1)
End If
End Function
Print fun(2, 5)

11)Function fun(arr, target, low, high)


If low > high Then
Return -1
End If
Set mid = (low + high) / 2
If arr[mid] == target Then
Return mid
Else If arr[mid] > target Then
Return fun(arr, target, low, mid - 1)
Else
Return fun(arr, target, mid + 1, high)
End If
End Function
Set arr = [1, 3, 5, 7, 9, 11]
Print fun(arr, 7, 0, Length(arr) - 1)

12)Set arr = [5, 6, 1, 2, 3, 4,5] last=6


Set k = 2
Set n = Length(arr)
For i = 0 to k - 1
Set last = arr[n - 1]
For j = n - 1 down to 1
arr[j] = arr[j - 1]
End For
arr[0] = last
End For
Print arr

13)Set arr1 = [1, 2, 3, 4, 5] //iota


Set arr2 = [4, 5, 6, 7]
Set result = []
For i = 0 to Length(arr1) - 1
For j = 0 to Length(arr2) - 1
If arr1[i] == arr2[j] Then
Append arr1[i] to result
End If
End For
End For
Print result

14)Function fun(head) //dacial


Set slow = head
Set fast = head
While fast != null AND fast.next != null
slow = slow.next
fast = fast.next.next
If slow == fast Then
Return True
End If
End While
Return False
End Function

15)Set arr = [1, 2, 4, 5, 6]


Set n = Length(arr) + 1
Set sum = n * (n + 1) / 2
Set arraySum = 0
For i = 0 to Length(arr) - 1
arraySum = arraySum + arr[i]
End For
Print sum - arraySum

16)Function fun(head) //fm


Set slow = head
Set fast = head

While fast != null AND fast.next != null


slow = slow.next // Move slow pointer one step
fast = fast.next.next // Move fast pointer two steps

Return slow
End Function

17)initialize char c
set c= 'a'
print "%d",c

18)#include<stdio.h>
int main ()
{
char c,a,b;
c='f';
a='s';
b='x';
int sum= c+a+b;
printf ("%d", sum);
}

19)initialize i,n [1,6,7,0,5]


intialize an array of size n
accept the values for the array
for i= 0 to n-1
arr[i] = arr[i]+arr[i+1]
end for
print the array elements

20)Declare an array of string type variable called word //strre


Declare a loopcounter
Store a string in the array word->"hello"
for loopcounter = (length of the word) – 1 to 0

print arrayword[loopcounter]

loopcounter = loopcounter – 1
endfor
Algorithm end
21)
int val=5;
do{
val++;
++val;
}while(val++>7);
printf("%d",val);
return 0;

22)
int main()
{
int m=0;
if(m==0)
{
m=((5,(m=3)),m=1);
printf("%d",m);
}
else
printf("Test");
return 0;
}

23)

i=0;
while(+(+i--)!=0)
i=i+5;
print i

24) Function fun(root) //lot


If root is null Then
Return
End If
Set queue = []
Enqueue queue, root
While queue is not empty
Set node = Dequeue queue
Print node.value
If node.left != null Then
Enqueue queue, node.left
End If
If node.right != null Then
Enqueue queue, node.right
End If
End While
End Function

25)Function fun(arr)
Set max_so_far = arr[0]
Set max_ending_here = arr[0]
For i = 1 to Length(arr) - 1
max_ending_here = max(arr[i], max_ending_here + arr[i])
max_so_far = max(max_so_far, max_ending_here)
End For
Return max_so_far
End Function

26)Function isBalanced(expression)
Set stack = new Stack()
For each character c in expression
If c is an opening parenthesis '(', '[' or '{' Then
Push stack, c
Else If c is a closing parenthesis ')', ']' or '}' Then
If stack is empty or top of stack does not match the corresponding
opening Then
Return False
Else
Pop stack
End If
End If
End For
Return stack is empty
End Function

What would the pseudocode output for a string with only opening parentheses and no
closing ones?

27)Function fun(matrix)
Set n = Length(matrix)

For i = 0 to n / 2
For j = i to n - i - 1
Set temp = matrix[i][j]
Set matrix[i][j] = matrix[n - j - 1][i]
Set matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]
Set matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]
Set matrix[j][n - i - 1] = temp
End For
End For
End Function

Function evaluateExpression()
Set result = 3 + 5 * 2 - 8 / 4
Print result
End Function

28)Function evaluateExpression()
Set result = (10 + 5 > 7) && (15 - 3 < 10) || (20 / 4 == 5)
Print result
End Function

29)integer fun(int i) i=140

if((i%2)!=0)
return i;

else

return fun(fun(i=1));

End function fun()

30)

int x=2,y=0,z=3;

x>y ?( printf("%d", z)):( return z);

31)Integer a, b, c, d, e //160

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

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

33)#include<stdio.h> //18 20 16 error

int

f (int n)
{

static int a = 0;

if (n <= 0)

return 1;

if (n > 3)

a = n;

return f (n - 2) + 2;

return f (n - 1) + a;

int main ()

printf ("Result: %d", f (5));

return 0;

34)integer a

if((a mod 10) IS EQUAL TO 0)

a=a*2

else if((a mod 5 ) IS EQUAL TO 0)

a=a/5

else

a=a-1

end if

35)a=[4,1,2,4,2,3,3]

sum=0
for each k from 0 to 7

sum=sum^a[k]

end for

print sum

36)

a=[5,1,4,2,3]

max=a[0]
getMaximum(a[],i)

if(i<len(a)

if(a[i]>max)

max=a[i]
end if
getMaximum(a,i+1)
return max
end if

return max

a='0'

c=a+9

printf("%d",c);

printf("%c",c);

Ascii Values Based Model

You might also like