Capgemini Pseudo Code

Questions 1: What will be the value of s if n = 127 ?

Read n
i=0,s=0
Function Sample(int n)
while(n>0)
r=n%l0
p=8^i
s=s+p*r
i++
n=n/10
End While
Return s;
End Function

  • Options
  • a : 27
  • b : 187
  • c : 87
  • d : 120
  • Answer: c

    Questions 2: What will be the output of the following pseudo code?

    Integer n
    for (n = 3; n != 0; n–)
    Print n
    n = n-1
    end for

  • Options
  • a : 3 1
  • b : 3 2 1
  • c : 3
  • d : Infinite Loop
  • Answer: d

    Questions 3: What will be the output of the following pseudo code?

    For input a = 8 & b = 9
    Function(input a, input b)
    If(a < b)
    return function(b, a)
    elseif(b != 0)
    return (a + function(a,b-1))
    else
    return 0

  • Options
  • a : 56
  • b : 78
  • c : 72
  • d : 68
  • Answer: c

    Questions 4: What will be the value of even counter if number = 2630?

    Read number
    Function divisible(number)
    even_counter = 0, num_remainder = number;
    while (num_remainder)
    digit = num_remainder % 10;
    If digit != 0 AND number % digit == 0
    even_counter= even_counter+1
    End If
    num_remainder= num_remainder / 10
    End While
    return even_counter

  • Options
  • a : 3
  • b : 4
  • c : 2
  • d : 1
  • Answer: d

    Questions 5: What will be the value of t if a = 56 , b = 876?

    Read a,b
    Function mul(a, b)
    t = 0
    while (b != 0)
    t = t + a
    b=b-1
    End While
    return t
    End Function

  • Options
  • a : 490563
  • b : 49056
  • c : 490561
  • d : None of the mentioned
  • Answer: b

    Questions 6: Consider the following piece of code. What will be the space required for this code?

    int sum(int A[], int n)
    {
    int sum = 0, i;
    for(i = 0; i < n; i++)
    sum = sum + A[i];
    return sum;
    }
    // sizeof(int) = 2 bytes

  • Options
  • a : 2n + 8
  • b : 2n + 4
  • c : 2n + 2
  • d : 2n
  • Answer: a

    Questions 7: How many times the following loop be executed?

    {

    ch = ‘b’
    while(ch >= ‘a’ && ch <= ‘z’)
    ch++
    }

  • Options
  • a : 0
  • b : 25
  • c : 26
  • d : 1
  • Answer: b

    Questions 8: What will be the output of the following pseudo code?

    Input m=9,n=6
    m=m+1
    n=n-1
    m=m+n
    if(m>n)
    print m
    else
    print n

  • Options
  • a : 6
  • b : 5
  • c : 10
  • d : 15
  • Answer: d

    Questions 9: What will be the output of the following pseudo code?

    Input f=6,g=9 and set sum=0
    Integer n
    if(g>f)
    for(n=f; n < g; n=n+1)
    sum=sum+n
    End for loop
    else
    print error message
    print sum

  • Options
  • a : 21
  • b : 15
  • c : 9
  • d : 6
  • Answer: a

    Questions 10: What will be the output of the following pseudo code?

    Integer a, b
    Set a = 1, b = 20
    If ( ( a + b ) < ( b >> 1 ) )
    a = a >> 1
    End if
    a = a + b
    Print a + b

  • Options
  • a : 20
  • b : 21
  • c : 41
  • d : 40
  • Answer: c