Coding MCQs Capgemini Pseudo Code MCQs | infosys Pseudo Code MCQs WITH Answer

Coding MCQs Capgemini Pseudo Code MCQs | infosys  Pseudo Code MCQs WITH Answer| TCS coding questions for placement

Coding MCQs Capgemini Pseudo Code MCQs | infosys  Pseudo Code MCQs WITH Answer| TCS coding questions for placement



1 )   Capgemini Pseudo Code | infosys  Pseudo Code MCQs Predict the output of the given pseudo code if the value of n is 35 :



Predict the output of the given pseudo code if the value of n is 35 :

Read n
i=0
While n%10!=0
n=n+3
i++
end while
n=n+i
write n


answer : 55
code in c for output

include <stdio.h>
int main()
{
   int n=35;
   int i=0;
   while (n%10!=0){
     n=n+3;
     i++;
    }
   n=n+i;
   printf("%d",n);
   return 0; 

}  =55

code in python

n=35
i=0
while(n%10!=0):
    n=n+3
    i+=1
n=n+i
print(n)
=55

2 )   Capgemini Pseudo Code infosys Pseudo Code | What will be the output of the given pseudo code if n = 10 ?




Read n
Initialize i to 5
while i < n do
increase sum by i
increment i
end while
Write sum



Options
  • a : 25.0
  • b : 35.0
  • c : 55.0
  • d : 45.0


  • python code for output :

    i=5
    n=10
    sum=0
    while i<n:
        sum=sum+i
        i+=1
    print(sum)

    == 35



    3)  Capgemini Pseudo Code | infosys  Pseudo Code  |Predict the output of the given pseudo code if the value of number is 6:


    Read number
    k = 2
    i = 2
    while i<=number
    k = k * i
    i = i +1
    end while
    write k


  • a : 1700.0
  • b : 1560.0
  • c : 1440.0
  • d : 1340.0
  • Answer: c) 1440.0  : below code for output in python


    k=2
    i=2
    number=6
    while i<=number:
     k=k*i
     i+=1
    print(k)

    =1440

    4) 

    TCS Coding Question - Even Sum and Odd Sum Difference | Given a maximum of 100 digit numbers as input, find the difference between the sum of odd and even position digits.

    Case 1

    Input: 5 9 10 11

    Expected Output: 

    Explanation : Odd positions are pos: 1 and pos: 3 which has digits 5 and 10  respectively, and both have sum 15. Similarly, even positions pos: 2 and pos: 4  with digits 9 and 11 respectively and sum 20. Thus, difference is 20 – 15 = 5


    #include<stdio.h>
    #include<string.h>
    #include <stdlib.h>
    int main()
    {
        int oddSum = 0,evenSum = 0,i = 0, n,diff;
        long long num;
        //int num;
        scanf("%lld",&num);  
        
        while(num != 0){
            if(i%2==0){
            evenSum = evenSum + num%10;
                num = num/10;
                

                i++;
            }
            else{
                oddSum = oddSum +num%10;
                num = num/10;
                i++;
            }
        }
        printf("%d",abs(oddSum - evenSum));
        return 0;
    }

    5 9 10 11
    =5


    5) Which of the following is the correct post-order traversal of the given rooted tree ?

  • Options
  • a : F-D-G-B-H-E-I-C-A
  • b : F-G-D-B-H-I-E-C-A
  • c : F-G-D-B-A-H-I-E-C
  • d : F-G-D-H-I-E-B-C-A     


  • Post a Comment (0)
    Previous Post Next Post