0% found this document useful (0 votes)
47 views8 pages

Accenture OLT-5

Uploaded by

nilesh.k0901
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views8 pages

Accenture OLT-5

Uploaded by

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

Accenture Pseudo-code

OLT-5
=========================================================

Q1 Find the output of following pseudo code.


fun()
{
integer i = 0, j = 5
while( (i < 3) && (j++ < 10) )
{
print( i j );
i++
}
print(i j )
}
A. 0 6 1 7 2 8 3 8
B. 0 6 1 7 2 8 3 9
C. 0 6 1 5 2 5 3 5
D. None
Answer: A

Q. 2 What will be the output of the program?


fun()
begin:
integer i=3, *j, k
j = &i;
print( i * *j * i + *j );
fun end
a) 30
b) 27
c) 9
d) 3

Ans: a

Q.3 What is the output of the C Program?


#include <stdio.h>
int main() {
int a=0;
a = 5>2 ? printf("4"): 3;
printf("%d",a);
return 0;
}
A) compiler error
B) 14
C) 41
D) 0
Answer C

Q.4 What will be the output of the following C code?

#include <stdio.h>
int main()
{
int i = 0, j = 0;
l1: while (i < 2)
{
i++;
while (j < 3)
{
printf("loop\n");
goto l1;
}
}
return 0;
}
a) loop loop
b) compilation error
c) loop loop loop loop
d) infinite loop
Answer A

Q.5Find the output of following code?


fun():
integer i, j=1
for each i=1 to 2:
for each i=1 to 3:
if(i==2) jump out from loop

Print( i , j )
end loop
end loop
A)1 1
B)1 1 1 2 1 3
c)1 1 infinite times
D)compilation error
Ans:A

Q6. Consider the code given below, which runs insertion sort:

void insertionSort(int arr[], int array_size)


{
int i, j, value;
for (i = 1; i < array_size; i++)
{
value = arr[i];
j = i;
while (________ )
{
arr[j] = arr[j - 1];
j = j - 1;
}
arr[j] = value;
}

Which condition will correctly implement the while loop?


a) (j > 0) || (arr[j - 1] > value)
b) (j > 0) && (arr[j - 1] > value)
c) (j > 0) && (arr[j + 1] > value)
d) (j > 0) && (arr[j + 1] < value)

Answer: b

Q.7 Find the ouput of following code?


foo(){
int k=1;

for(printf("FLOWER "); printf("YELLOW "); printf("FRUITS "))


{
break;
printf("%d",k);
}

return 0;
}
A) Compiler error
B) FLOWER FRUITS
C) FLOWER YELLOW
D) FLOWER YELLOW 1 FRUITS
Ans: C

Q.8 How many times "Hello" is get printed?


#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("hello");
}
return 0;
}
A) Infinite times
B) 11 times
C) 0 times
D) 10 times
Ans: C

Q.9 What does the above program print foo (1234, 0)?
void foo(Integer n, Integer sum)
Integer k = 0, j = 0
IF (n EQUALS 0)
return
k = n MOD 10
sum = sum + k
Print (k)
foo (n/10, sum)

end foo

A) 4, 3, 2, 1
B) 1, 2, 3, 4
C) 1, 3 , 6, 10
D) 0, 1, 2, 3
Ans: A

Q.10 Consider the following C function:


int f(int n)
{
static int i = 1;
if(n >= 5) return n;
n = n+i;
i++;
return f(n);
}
The value returned by f(1) is
A)5
B)6
C)7
D)8
Ans:C

Q.11 What is the output of this program?

#include<stdio.h>
void test(int * , int *);
main()
{
int a = 5 , b = 6;
test(&a,&b);
printf("%d %d",a,b);
}
void test(int *p, int *q)
{
*p = *p ^ *q;
*q = *p ^ *q;
*p = *p ^ *q;
}
A. 30 5
B. 6 5
C. 5 6
D. None of the above
Ans:B

Q.12 Find output of the following.


int fun(int a, int b)
{
if (b == 0)
return 0;
if (b % 2 == 0)
return fun(a+a, b/2);

return fun(a+a, b/2) + a;


}

int main()
{
printf("%d", fun(4, 3));
getchar();
return 0;
}
a)12
b)11
c)10
d)13
Ans:A

Q. 13 Find output of the following.


void fun(int x)
{
if(x > 0)
{
fun(--x);
printf("%d ", x);
fun(--x);
}
}

int main()
{
int a = 4;
fun(a);
getchar();
return 0;
}
a)1 0 2 3 0 0 1
b)0 1 2 0 3 0 1
c)1 0 2 3 0 0 3
d)1 1 2 3 0 0 1
Ans:b
Q. 14 Consider an array of length 5, arr[5] = {9,7,4,2,1}. What are the steps of insertions done
while running insertion sort on the array?
a) 7 9 4 2 1 4 7 9 2 1 2 4 7 9 1 1 2 4 7 9
b) 9 7 4 1 2 9 7 1 2 4 9 1 2 4 7 1 2 4 7 9
c) 7 4 2 1 9 4 2 1 9 7 2 1 9 7 4 1 9 7 4 2
d) 7 9 4 2 1 2 4 7 9 1 4 7 9 2 1 1 2 4 7 9

Answer: a

Q15. Select the most appropriate output for the following C code:
int main()
{ int i = 90;
int j = (i++, --i, i++);
printf("%d %d", i, j);
}
a. 91 91
b. 90 90
c. 91 90
d. Compiler Dependent
Answer: c

Q16. Select the most appropriate output for the following C code:
main()
{ int x=-28,d,e;
d=!x;
e=~x;
printf("%d %d",d,e);
}

a. 0 29
b. 0 -27
c. 1 28
d. 1 0
Answer:B

Q17. Select the most appropriate output for the following C code:
int main()
{ int a1 = 51;
int b1 = 0;
int c2 = a1 || --b1;
int d3 = a1-- && --b1;
printf("a1 = %d, b1 = %d, c2 = %d, d3 = %d", a1, b1, c2, d3);
}
a. a1 = 50, b1 = -1, c2 = 1, d3 = 1
b. a1 = 50, b1 = -2, c2 = 1, d3 = 1
c. a1 = 51, b1 = -1, c2 = 1, d3 = 1
d. None
Answer: a

Q18. Assuming, integer is 2 byte, What will be the output of this code for fun(2)?
fun(int n):
Integer X=-2
Print(X<<n)

A. ffff
B. 0
C. fff8
D. Error

Ans: C

You might also like