Contents

## Writing in pseudocode – Practise pseudocode

Pseudocode is a form of writing that uses the basic syntax of a programming language while omitting certain details. Here are some examples of writing in pseudocode that will help you in placements.

It helps you to think through your code before actually writing it. Pseudocode is also sometimes referred to as “programming in English”, or “English-like programming”.

## What is pseudocode?

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. The examples below will illustrate this notion.

## How to write in pseudocode?

Pseudocode is a programming language that is not used to produce a program but rather to give written descriptions of algorithms and programs.

The pseudocode algorithm description is easier to write than the actual code in a programming language and it can be read more easily by people who are not familiar with programming.

A pseudocode algorithm can also be translated into many computer programming languages.

#### Latest: Capgemini data structures mcqs questions and answers

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

Options :

a. 6 11 14 30

b. 5 10 15 0

c. 6 11 14 31

d. None

```Answers : a) 6 11 14 30Solution Code:#include<stdio.h> void main() { int a =5,b=10,c=15,result; result=++a + b++ + --c;printf("%d\n",a);printf("%d\n",b);printf("%d\n",result);}
```

Question 2: What is the output of the following code

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

Options :

a. 11 11 15

b. 11 11 10

c. 11 10 11

d. 11 10 11

`Answers : a. 11 11 15Code : #include<stdio.h> void main(){int a =10,b,c=5; b = a++;c+= b++;printf("%d\t",a);printf("%d\t",b);printf("%d\t",c);}`

Question 3: What is the output of the 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)

Options :

a. 16 15 15

b. 16 16 15

c. 15 16 17

d. 16 16 16

`Answers : d. 16 16 16Code :#include void main(){int x=5,y; int i;for(i=1; i<=10; i++){  x = x+1;   y = x+1;} if(++x % 2 == 0){  printf("%d\n",x);}printf("%d\n",y);printf("%d\n",x);}`

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)

Options :

a. 25 31 36 46 54

b. 25 31 38 46 9

c. 25 30 35 45 9

d. None

`Answers: b) 25 31 38 46 9  Code:#include void main(){int x=25,y=5; printf("%d\t",x); LABEL1: x = x + ++y;if(x < 50){   printf("%d\t",x); goto LABEL1;}printf("%d\t",y);}`

Question 5: What is the output of the 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)

Options :

a. 5

b. 10

c. 6

d. 12

`Answers : c) 6Code:#includevoid temp(int x,int y){   if(x>1)   {   temp(x-3,y-2);   }   else   {   printf("%d\n",y);   }}void main(){   int a=10,b=12;   temp(a,b);}`

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)

Options :

a. 5

b. 3

c. 6

d. 12

`Answers : b) 3Code:#include<stdio.h>void temp(int x,int y){    if(x>1)    {       temp(x-1,y-1);    }    else    {       printf("%d\n",y);    }}void main(){   int a=10,b=12;   temp(a,b);}`

Question 7: What is output of following code if m=8,n=2?

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

Options :

a. 8

b. 10

c. 6

d. No Output

`Answers : d. No Outputcode:#include<stdio.h>void fun(int m,int n){n=--n; m=++m; if(m>=n){if(m==0){printf("%d",m+n);}}`

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)

Options :

a. 5

b. 3

c. 120

d. 24

`Answers : C) 120code:#includeint fun(int n){  if (n == 0)  {  return 1;  }  else  {   return n * fun(n - 1);  }}void main(){  int res=fun(5);  printf("%d",res);}`

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);
}
}

Options :

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
int main()
{
int a=0;
if(a==5);
{
printf(“Hello World\t”);
}
printf(“Good Morning”);
}

Options :

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

Options :

a. 10

b. 110

c. 120

d. 30

`Answers : c). 120Code:#include<stdio.h>int fun(int a ,int b,int c){   int n; if(a>0)   {     n=a%10;     return fun(a/10,b+10,b+c);   }   else   {      return b+c;   }}int main(){   int temp=fun(10,20,30); printf("%d",temp);}`

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

Options :

a. 14

b. 11

c. 12

d. 13

`Answers : Code: #include<stdio.h>void main(){   int n=5, k, f1=1, f2=1, sum=0;   for(k=1;k<=n;k++)   {   sum = f1 + f2; f1 = f2;   f2 = sum;   }   printf("%d",sum);}`

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

Options :

a. 1

b. 2

c. 3

d. None

`Answers : a) 1Code:#include<stdio.h>void main(){   int x=5,y=6,z=7;   if(x>y && y*z>41)   {      printf("PRINT STATEMENT 1\n");   }   if(x>z && x*y>25)   {      printf("PRINT STATEMENT 2\n");   }   else   {      printf("PRINT STATEMENT 3\n");   }}`

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

Options :

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 Code :#include<stdio.h>void main(){    int x=5,y=6,z=7;    if(x<y || y*z>41)    {       printf("PRINT STATEMENT 1\n");    }    if(x<z || x*y>25)    {       printf("PRINT STATEMENT 2\n");    else    {       printf("PRINT STATEMENT 3\n");    }}`

Question 15: What is output of this code?

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

Options :

a. 5 4 3 2 1

b. 5 5 5 5 5

c. Error

d. Infinite Loop

`Answers : d) Infinite Loop#include<stdio.h> void main(){int n;for(n=5;n!=0;n--){   printf("%d",n);   n=n-2;}}`

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

Options :

a. 25

b. 30

c. 35

d. None

`Answers: b) 30Code:#includeint Fun(int x ,int y){    if(y!=0)    {       return (x+Fun(x,y-1));    }    else    {       return 0;    }}void main(){  int temp=Fun(5,6);   printf("%d",temp);}`

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

Options :

a. 28

b. 56

c. 58

d. None

`Answers : c) 58Code: #include<stdio.h>void main(){int Counter=0,i; for(i=0;i<=7<<2;i++){Counter=Counter+2;}printf("%d",Counter);}`

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

Options :

a. 165

b. 0

c. 160

d. None

`Answers : b) 0Code:#include<stdio.h>void main(){int Counter=0,i;for(i=0;i<=-7>>5;i++){Counter=Counter+5;}printf("%d",Counter);}`

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

Options :

a. 4

b. 0

c. 1

d. Error

`Answers: a) 4Code:#include<stdio.h>void main(){int Counter=1,i; for(i=1;i<=10;i++){   if(i % 2 == 0)   {      if(i % 4 == 0)      {         Counter = Counter << 1;      }   }}printf("%d",Counter);}`

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

Options :

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));
}

Options :

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);
}

Options :

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);
}

Options :

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

Options :

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);
}

Options :

a. 5 102 102

b. 5 102 f

c. 5 102 e

d. Error

`Answers : b) 5 102 f`