## Capgemini Pseudocode for Practice

What is pseudocode?

Contents

Pseudocode is an informal way of programming description that does not require any strict programming language syntax or underlying technology considerations. It is used for creating an outline or a rough draft of a program.

Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a “text-based” detail (algorithmic) design tool.

The rules of Pseudocode are reasonably straightforward. All statements showing “dependency” are to be indented. These include while, do, for, if, switch. Examples below will illustrate this notion.

Question 1 :

What is output of following code if a=5,b=10,c=15

Start
Number, a, b, result
Input: a , b
result = ++a + b++ + –c
print a,b,c,result

a) 6 11 14 30
b) 5 10 15 0
c) 6 11 14 31
d) None

`Answers : a) 6 11 14 30`

Question 2 :

What is output of following code

Integer a,b,c
Set a=10 , c=5
b=a++
c+=b++
print a,b,c

a) 11 11 15
b) 11 11 10
c) 11 10 11
d) 10 10 10

`Answers : a) 11 11 15`

Question 3 :

What is output of following code

Integer x, y Set x=5
for i ( 1 to 10 ) x = x + 1
y = x + 1
END for
if (++x % 2 = = 0)
print(x)
END IF
print(y)
print(x)

a) 16 15 15
b) 16 16 15
c) 15 16 17
d) 16 16 16

`Answers : d) 16 16 16`

Question 4 :

What is output of following code

Integer x,y
Set x=25 , y=5
print(x)
LABEL : x = x + ++y
if(x<50)
print(x)
goto label
END if
print(y)

a) 25 31 36 46 54
b) 25 31 38 46 9
c) 25 30 35 45 9
d) None

`Answer :b) 25 31 38 46 9`

Question 5 :

What is output of following code if a=10,b=12.

FUNCTION temp(int x , int y)
if(x>1)
temp (x-3 ,y-2)
else
print(y)
END if-else
temp(a,b)

a) 5
b) 10
c) 6
d) 12

`Answers : c) 6`

Question 6 :

What is output of following code if a=10,
b=12.

FUNCTION temp(int x, int y)
if(x>1)
temp (x-1 ,y-1)
else
print(y)
END if-else
temp(a,b)

a) 5
b) 3
c) 6
d) 12

`Answers : b) 3`

Question 7 :

What is output of following code if m=8,n=2

n = –n
m=++m
if(m >= n)
if(m == 0)
print(m+n)
END if
else if(m >= n)
if(m != 0)
print(m-n)

a) 8
b) 10
c) 6
d) No Output

`Answers : d) No Output`

Question 8 :

What is output of following code

FUNCTION fun(n)
if(n==0)
return 1
else
return n*fun(n-1)
res=fun(5)
print(res)

a) 5
b) 3
c) 120
d) 24

`Answers : c) 120`

Question 9 :

What is output of following code

#include <stdio.h>
int main() {
int n = 1;
{
int n = 2;
printf(“%d\t”, n);
}
{
int n=5;
n++;
printf(“%d\t”, n++);
printf(“%d\t”, n);
}
}

a) 2 6 7
b) 2 1 1
c) 2 6 6
d) 2 5 5

`Answers : a) 2 6 7`

Question 10 :

What is output of this code

#include<stdio.h> int main()
{
int a=0;
if(a==5);
{
printf(“Hello World\t”);
}
printf(“Good Morning”);
}

a) Good Morning
b) Hello World Good Morning
c) Hello World
d) None

`Answers : b) Hello World Good Morning`

Question 11 :

What is output of following code a=10, b=20,c=30

Integer fun(int a,int b,int c) int n
if(a>0)
n= a % 10
ruturn fun(a/10, b+10,b+c) else
return b+c END fun( )

a) 10
b) 110
c) 120
d) 30

`Answers : c) 120`

Question 12 :

What is output of this code

Declare an integer variable called n Declare an integer variable f1 Declare an integer variable f2 Declare an integer variable f3

set f3 to 0.
set f1 and f2 to 1 set n to 5
repeat 1 to n times f3 = f1 + f2
f1 = f2 f2 = f3 end loop print f3

a) 14
b) 11
c) 12
d) 13

`Answers : d) 13`

Question 13 :

How many print statements will be executed in this code

Integer x,y,z
SET x=5,y=6,z=7

If x>y AND y * z >41
PRINT STATEMENT 1
END IF

If x>z AND x * y >25
PRINT STATEMENT 2
ELSE
PRINT STATEMENT 3

a) 1
b) 2
c) 3
d) None

`Answers : a) 1`

Question 14 :

Which print statements will be executed in this code

Integer x,y,z
SET x=5,y=6,z=7

If x<y OR y * z >41
PRINT STATEMENT 1
END IF

If x<z OR x * y >25
PRINT STATEMENT 2
ELSE
PRINT STATEMENT 3

a) PRINT STATEMENT 1 & STATEMENT 2
b) PRINT STATEMENT 1 & STATEMENT 3
c) PRINT STATEMENT 2 & STATEMENT 3
d) PRINT STATEMENT 1 & STATEMENT 2 & STATEMENT 3

`Answers : a) PRINT STATEMENT 1 & STATEMENT 2`

Question 15 :

What is output of this code

Integer n
for(n = 5 ; n!=0; n–)
print n
n=n-2
END FOR

a) 5 4 3 2 1
b) 5 5 5 5 5
c) Error
d) Infinite Loop

`Answers : d) Infinite Loop`

Question 16 :

What is output of this code

Integer x=5 , y=6
IF (y!=0)
return (x+Fun(x,y-1))
else
return 0

a) 25
b) 30
c) 35
d) None

`Answers : b) 30`

Question 17 :

What will be the output of given code

Counter=0,i
For i (0 to 7 << 2)
Counter = Counter + 2
END For
Print Counter

a) 28
b) 56
c) 58
d) None

`Answers : c) 58`

Question 18 :

What will be the output of given code

Counter=0,i
For i (0 to -7 >> 5)
Counter = Counter + 5
END For
Print Counter

a) 165
b) 0
c) 160
d) None

`Answers : b) 0`

Question 19 :

What will be the output of given code

Counter=1,i
For i (1 to 10)
if (i mod 2 = = 0 )
if (i mod 4 = = 0 )
Counter = Counter << 1
END For
Print Counter

a) 4
b) 0
c) 1
d) Error

`Answers : a) 4`

Question 20 :

What will be the output of given code if a=10

#include<stdio.h>
int main()
{
int a,*p1,**p2,***p3,****p4,*****p5;
p1=&a;
p2=&p1;
p3=&p2;
p4=&p3;
p5=&p4;
printf(“%d\t”,*p1);
printf(“%d\t”,**p2);
printf(“%d\t”,***p3);
printf(“%d\t”,****p4);
printf(“%d\t”,*****p5);
}

a) 10 11 12 13 14
b) 10 10 10 10 10
c) Error
d) Garbage value

`Answers : b) 10 10 10 10 10`

Question 21 :

What will be the output of given code if a=10

#include<stdio.h> int main()
{
int a=10,*p1,**p2,***p3,****p4,*****p5; p1=&a;
p2=&p1; p3=&p2; p4=&p3; p5=&p4;

printf(“%d\t”,++(*p1));
printf(“%d\t”,(**p2)++);
printf(“%d\t”,++(***p3));
printf(“%d\t”,(****p4)++); printf(“%d\t”,++(*****p5));
}

a) 11 11 13 13 15
b) 10 10 10 10 10
c) 10 11 12 13 14
d) 14 13 12 11 10

`Answers : a) 11 11 13 13 15`

Question 22 :

What will be the output of given code if x=97 and architecture is 64Bit.

#include<stdio.h>
void main()
{
int x =97;
int y =sizeof(x++);
float z = y;
printf(“%d\t”,x);
printf(“%d\t”,sizeof(x));
printf(“%d\t”,sizeof(y));
printf(“%f\t”,z);
}

a) 97 4 4 4
b) 4 4 4 4
c) 4 4 4 4.0
d) 97 4 4 4.00000

`Answers : d) 97 4 4 4.00000`

Question 23 :

What will be the output of given code if x=97 and architecture is 64Bit.

#include<stdio.h>
void main()
{
int a =5,b =-7,c =0,d;
d =++a && ++b ||++c;
c–;
printf(“\n%d\t%d\t%d\t%d”,a,b,c,d);
}

a) 6 -8 0 0
b) 6 -6 0 1
c) 6 -6 -1 1
d) 6 6 1 1

`Answers : c) 6 -6 -1 1`

Question 24 :

What will be the output of given code

a=45, b =720
Function mul(a, b)
t = 0
while (b >= 0)
t = t + a
b=b-2
End While
return t;
End Function

a) 16200
b) Infinite Loop
c) 16245
d) 16290

`Answers : c) 16245`

Question 25 :

What will be the output of given code

#include<stdio.h>
#include<string.h>
void main()
{
char ch=’a’;
int i=0;
while(ch>=’a’ && ch<=’e’)
{
i++;
ch++;
}
printf(“%d\t”,i);
printf(“%d\t”,ch);
printf(“%c”,ch);
}

a) 5 102 102
b) 5 102 f
c) 5 102 e
d) Error

`Answers : b) 5 102 f`