NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

CODEQUOTIENT
PAPER OF HP-20-PA-ST1-I EXAM

Q1. Choose the correct options

What is the output of the following code snippet
int x =0;

if(x<4);

x=x+1;

cout << x <<endl;

Q2. Choose the correct options

inti=1;
while(i < 5) {
if(i == 3) {
break;
}
cout <<i<<"",
i++;
}
O 1234
@ 12

O 124
O infinite loop

Ans:12

Q3. Choose the correct options
‘What will be the output ?
for(inti=0;i<5;i=i+1){
ifi=2)
continue;

cout <<j<<"";

}

O 01

® 0134
O 01234
O 012345

Ans:0134

Q4. Choose the correct options

‘What will be the output ?
for(inti=0;i<2;i=i+1) {

for(int j = 0; <23j=j + 1) {

break;

cout <<j<<"";

}
}

@ 00
Oo0101
Oo1
O10

Ans: 00

QS. Choose the correct options

What is the output of the following code snippet
int score = 70;
if (score = 0)

cout <<"A";
cout << "B";

Q6. Choose the correct options

What will be the output the following code?
for(inti=1;i<5;i=1i+1){
cout <<i<<"";

i=i-1;

Ans : infinite 1

Q7. Choose the correct option

The following code displays
#include <iostream>

using namespace std;

void max Value(int valuel, int value2, int max)

{

if (valuel > value2)
max = valuel;
else

max = value2;

int main()
{

int max = 0;

max Value(1, 2, max);
cout <<max;

return 0;

}

@0
O01
02
O garbage value

Ans: 0

Q8. Choose the correct option

Figure out the correct statement
class Car{

public :

int price;

}

int main() {
Car c;
//Figure out the correct statement to set the price of the car object referred to by c to “10000”

}

c->price=10000
car.price=10000
c.price=10000

car-price=10000

OXOXOXO)

Ans : c.price=10000

Q9. MCQ-3

‘Write output of code

class Test {
int x;
1;

int main()

Test tj
cout << t.x;
return 9;

3

Oo

@ Garbage Value
O Compiler Error
O Run time error

Ans : Garbage Value

Q10. CQ-One mark each
What will be the output of following program?

#include<stdio.h>
void print(int n)

if (n > 4000)
return;
printf("%d ™, n);
print(2*n);
printf("%d ", n);
}

int main()
print(1000);

return 0;

)

O 1000 2000 4000

@ 1000 2000 4000 4000 2000 1000
O 1000 2000 4000 2000 1000

O 1000 2000 2000 1000

Ans : 1000 2000 4000 4000 2000 1000

Q11. CQ-One mark each

‘What will happen if base condition is not defined in recursion?

O Stack underflow
@ Stack overflow

O Compile time error
O None of these

Ans : Stack overflow

Q12. CQ-One mark each
Considering the following code, what will be the output of fun(2,3)

int fun(int x, int y)
{
if(y=0)
return 1;

else if (y%2 = 0)
return fun(x, y/2)*fun(x, y/2);
else

return x*fun(x, y/2)*fun(x, y/2);

Q13. CQ-One mark each

In which type of recursion function, calling of a function can cause more than one recursive activations of the
same function

O Linear Recursion
O Head Recursion
@ Tree Recursion
O Tail Recursion

Ans : Tree Recursion

Q14. CQ-One mark each

How many times is the function recursivesum() called when the following code is executed?

#include<stdio.h>
int recursivesum(int n)

if(n == @)
return 9;
return n + recursivesum(n - 1);

int main()

int n = 5;
int ans = recursivesum(n);
printf("%d",ans);
return 0;

O 14
On
@ 15
O 54321

Ans: 15

Q15. CQ-One mark each

Which of the following statements is true?

O Recursion is always better than iteration

@ Recursion uses more memory compared to iteration
O Recursion uses less memory compared to iteration
O Tteration is always better and simpler than recursion

Ans : Recursion uses more memory compared to iteration

Q16. CQ-One mark each

‘Which type of the recursive function given in choices, could be optimized by the compiler?

@ Tail Recursive

O Direct Recursive
O Indirect Recursive
O Non-Tail Recursive

Ans : Tail Recursive

Q17. CQ-One mark each

Recursion is a method in which the solution of a problem depends on

O Larger instances of different problems
O Larger instances of the same problem
@ Smaller instances of the same problem
O Smaller instances of different problems

Ans : Smaller instances of the same problem

Q18. Operations on Arrays
Arrange the following operation on Arrays in increasing order of time taken to complete them.

1. Access an array element using its index

2. Inserting a data item in the middle of an array

3. Inserting a data item at the end of an array

4. Inserting a data item in the beginning of an array

0 1234
O 1,423
@® 1,3,2,4
© None of these

Ans: 1,3,2,4

Q19. Functions: Arrays - 2

‘When we pass the array to a function, what is actually being passed: -

O Copy of the whole array
@ Base address of the array
O Only the first element

O None of the above

Ans : Base address of the array

Q20. Arrays: Pointers - 6

What will be the output of below program?

#include<stdio.h>
int main()

int arr[3] = {11, 12, 13};
int *ptr = arr;

int **p = &ptr;
printf("%p %p", *r, arr);
return 0;

}

O Two Different addresses are printed
O12
@ Two same addresses are printed.

O11

Ans : Two same addresses are printed.

Q21. Arrays: Pointers - 5

What is the output of below program?
#include<stdio.h>
int main()

int a[3] = {11, 12, 13};
int *ptr = a;
int *r = &ptr;

printf("%d", (**r));
return 0;

On
O12

@ Syntax Error
O No output

Ans : Syntax Error

Q22. Arrays: Pointers - 3

‘What would be the output of the below program

#include<stdio.h>
int main( )

int a[5]={1,2,3,4,5};

int *p;
p=a;
int i=0;
while(i<5)
printf(™%d ", *(p+i));
i++;
}
return 0;
}
O Syntax Error
O 11111
O Garbage Values
@ 12345
Ans:12345

Q23. Arrays: Pointers - 2

‘What would be the output of the below program

#include<stdio.h>
int main( )

{
int a[5]={1,2,3,4,5};
int *p;
p=a;
printf(“"%d ", *p);
*pt;

printf ("%d", *p);
return 9;

O11

@® 12

O Garbage Values
O Syntax Error

Ans:12

Q24. Arrays: Pointers - 1
‘What would be the output of the below program

#include<stdio.h>
int main( )
{
int a[5]={0};
at+;
printf ("%d", a[@]);
return 6;

0
2
Garbage Value

0]
0]
0]
@ Syntax Error

Ans : Syntax Error

Q25. Arrays in DS

What is the time complexity of inserting at the end in dynamic arrays?

0 ol)

O om

O O(logn)

@ Either O(1) or O(n)

Ans : Either O(1) or O(n)

Q26. Arrays and Memory - 1

The elements in the array of the following code are:

int array[S] = {6};
O (garbage), (garbage), (garbage), (garbage), 6

Ans:6,0,0,0,0

Q27. Classes and Objects in C++

In C++, the declaration of functions and variables are collectively called .......

@ class members
O member variables
O function members
O object members

Ans : class members

Q28. Classes, objects and constructors

Find the output.

#include<iostream>
using namespace std;
class Test

{

int x;

public:

Test (int i) { x=++i;}

void fun() { cout << x<< " "; }

>
int main()
{
Test t1 (10);
Test t2 (t1);
t1.fun();
t2.fun();
return @;

3

O 1010
O 1110
O 1210
@ 111

Ans: 1111

Q29. Choose the correct options

Predict the output

class F

{
public:
int x; // data field

int y; // data field

FQ

{

x=10;
y=10;
}

void f{()
{

int x = 20;

cout <<x <<" "<< Y;

}
be

int main()
{

Ff

£10;

O 1020
O 2020
@® 2010
O error because function name f() is wrong

Ans :2010

Q30. Choose the correct option

#include <iostream>
using namespace std;

int main()
intx = 15;
inty = x++;
int z= ++x;

cout <<y << “<< zs

O 1516
O 1617
@® 1517
O 1616

Ans: 1517

Q31. Object Class

‘Which of the following is true?

O The Class class is the superclass of the Object class.

O The Object class is final.

@ The Class objects are constructed by the JVM as classes are loaded by an instance of java.lang.ClassLoader
O None of the above

Ans : The Class objects are constructed by the JVM as classes are loaded by an instance of java.lang.ClassLoader

Q32. MCQ 2 mark

Predict the output
#include <iostream>

using namespace std;

int main()
{
int a[]={10,20,30,40};

cout <<a[3]--;
Ans : 40

Q33. MCQ 2 mark

Predict the output
#include <iostream>
using namespace std;

int main()

{

int x[][4] = {{1, 2, 3, 14}, {5, 6,7, 8}};

int v =x[0][0];

for (intr=0; r <2; r++)
for (int c = 0; c <4; c++)
if (v <x[r][c])

v=x[r][c];

cout << v << endl;

Ans: 14

Q34. MCQ 2 mark

Predict the output
#include <iostream>
using namespace std;

int main()

{

int x[[4] = {{1, 2, 3, 14}, {5, 6,7, 8}};
int v = x[0][0];

for (intr=0;r <2; r++)
for (int c = 0; ¢ <4; c++)
if (v <x[r][c])

v=x[r][c];

cout << v << endl;

Q35. MCQ 2 mark

Predict the output
#include <iostream>
using namespace std;
int main()
{
int matrix[][4] =
{{1,2,3,43},
{1, 12,3, 4},
{1,2, 13,4},
{1,2,3,14}};

for (inti = 0; i <4; i++)

cout << matrix[i][i] <<" ";

return 0;
O 1234
O 11121314
O 12314
® 1121314

Ans:11213 14

Q36. MCQ 2 mark

Predict the output

#include <iostream>
using namespace std;
int main()
{

int a[5] = {5, 1, 15, 20, 25};

int i, j, m;

i ++a[1];
a[1]++;
afi++];
cout <<i<<™ "<<j<<

[W)
nnn

<<m ;

O 1315
® 3215
O 1312
O 3315

Ans:3215

Q37. MCQ 2 mark

Predict the output
#include <iostream>
using namespace std;
int main()
{
int matrix[][4] =
{{1,2,3,4},
{1, 12,3, 4},
{1,2, 13,4},
{1,2,3,14}};

for (inti=0;i<4; itt)

cout << matrix[i][0] <<" ";
return 0;

O 1234
O 11121314
O 12314
@ 1111

Ans:1111

Q38. Data Types - CPP

‘What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int main(){
float numl = 1.1;
double num2 = 1,1;
if (numl == num2)
cout << "code";
else cout << "quotient™;

return 9;
}
O code
@ quotient

O compile-time error
O runtime error

Ans : quotient

Q39. Choose the correct options

Choose the correct default return value of function.

O float
O char
O void
@ int

Ans : int

Q40. Choose the correct option

‘What will be the output the following code .Assume appropriate header file and main included?
for(inti=0;i<5;i=i+1) {
ifi=2)
continue;

cout <<j<<"";

}

O01

® 0134
O 1234
O 12345

Ans:0134

Q41. MCQ-1

Output of following program?
#include<iostream>
using namespace std;
class Point {
Point() { cout << "Constructor called"; }

};
int main()

Point t1;

return 0;

)j

@ Compiler Error

O Runtime Error

O Constructor called
O None of the above

Ans : Compiler Error

Q42. MCQ 2 mark

Predict the output
#include <iostream>
using namespace std;
int main()
{
int array1[] = {1, 2, 3, 4, 5};
int array2[] = {2, 3, 4, 5, 6};

int i, result = 0;

for i=0;i<5;it++)
{

result += array1[i];
}
for (i—; i <= 4; i++)
{

result += array2[i];
}
cout << result;

return 0;

O 15
O 16
@ 21
O 25

Ans: 21

Q43. CQ -2 Marks

‘What does the following function do?

int fun(unsigned int n)

if (n==0 || n==1)
return n;

if (n%3 1= 8)
return @;

return fun(n/3);

O Ttreturns 1 when n is a multiple of 3, otherwise returns 0
@ It returns 1 when n is a power of 3, otherwise returns 0
O It returns 0 when n is a multiple of 3, otherwise returns 1
O Tt returns 0 when n is a power of 3, otherwise returns 1

Ans : It returns 1 when n is a power of 3, otherwise returns 0

Q44. CQ-2 Marks
Considering the following code, what will be the output of print(12)

void print(int n)
{
if (n==0)

return;

printf("%d", n%2);

print(n/2);

@ 0011
O 1000
O 1100
O 1001

Ans: 0011

Q45. MCQ-2Marks

Consider the function defined below:

int func1(int a)
{
if (a<0)
return( -func1(-a));
else
if(a< 10)
return (a+1) % 10;
else

{
return (100 * funcl(a/ 10));
What will be output of func1(-367) ?

60000
-40000
-60000
40000

CO®O

Ans : -40000

Q46. CQ-2 Marks

Consider the following recursive code

int fun(int n)

{

if(n==0)
return 3;

else

return (2*fun(n-1) + (n-1)*(n-1));

‘What will be the return value of fun(3)?

@® 30
O 69
O 54
O 32

Ans: 30

Q47. CQ-2 Marks

Consider the following recursive code

void funcl(int a)

if (a >= 20)
printf ("%d=", a);
else

funci(a * 4);
printf ("%d=", a);
What will func1(1) return?

O 1=4=16=64=
@ 64=16=4=1=
O 32=16=4=1=
O 1=4=16=32=

Ans : 64=16=4=1=

Q48. CQ-2 Marks

What is the following function do?

int func1(int a, int b)
{
if (b=0) return 0;
if (b=1) return a;

return a + func1(a, b-1);

atb where a and b are integers
a+b where a and b are non negative integers
a*b where a and b are integers
a*b where a and b are non negative integers

@0O0O0

Ans : a*b where a and b are non negative integers

Q49. CQ-2 Marks

Consider the function defined below:

int func1(int a)
{
if (a < 10)
return a;
else

return func1((a/ 10) + (a % 10));
What will be return value of func1(6457)?

O 652
O 67
O 13
@® 4

Ans: 4

Q50. CQ-2 Marks
Consider the following code for recursive implementation to find the sum of digits of number:

#include<stdio.h>
int rsod(int n)
{
ifln==10)
return 0;

return 5

}

int main()

{
intn= 1201;
int ans = rsod(n);
printf("%d",ans);

return 0;

‘Which line of code should be inserted in blank space to make the code complete out of given choices?

O (n/10)+rsod(n % 10)
O(n) + rsod(n % 10)

O (n% 10) + rsod(n % 10)
@ (n% 10) + rsod(n/ 10)

Ans: (n % 10) + rsod(n/ 10)

Q51. CQ-2 Marks
Predict the output of the following program.

#include <stdio.h>
int fun(int n)

if (n == 4)
return n;
else return 2*fun(n+l);

)j

int main()

printf("%d ", fun(2));
return 0;

3

4
8
16

Error

C®@0OO0

Ans: 16

Q52. CQ-2 Marks

The Fibonacci numbers are the numbers in the following integer sequence.

0,1,1,2,3,5,8,13,21, 34, 55, 89, 144, ........

Where 0 and 1 are seed values.

‘Which of the recurrence relations given in choices can be used to find the nth Fibonacci number?

O F@m)=Fm)+Fn-1)

O Fm)=Fm)+Fn+1)

O Fm)=Fn-1)

@ F(n)=F(n-1)+Fn-2)

Ans :F(n)=F(n—-1)+F(n-2)

Q53. Reach a single digit

Given a positive integer N, determine the number of times you must add the digits in it to reach a single digit.
For example, if N = 347, then the answer is 2 because 3 +4 + 7= 14 and 1 +4 = 5, i.e. we reached a single digit
in 2 steps.

Input Format:

The first line of input contains an integer T, denoting the number of test cases.
Then T lines follow, each line contains an integer N.
NNNNNNWNNNDNNP,NDNN = —

Q54. Make a group for competition

There are N students in a class, and their teacher wants to send a group of students for a competition. Assume
there is no limit on the number of students that can be part of a group.

Now, given an array of size N denoting their roll no's, determine in how many ways the teacher can create a
group out of those N students. For example, If N = 3 and rollNo[ ] = {1, 2, 3}, then in 7 of the following ways,
the teacher can create a group:

1
121
131
[1,2]
[1,3]

12,3]
[1,2,3]

Input Format

First line will contain an integer T, denoting the number of test cases.
For each test case:
First line will contain an integer N, denoting the number of students.
Second line will contain N space separated integers, denoting their roll numbers.

Output Format
For each test case, print the total number of ways in which the teacher can create a group, in new lines.
Constraints

1<=T<=10

1 <=N <= 50

1 <= rollNo[i] <= 1875
Sample Input

1 // Test Cases
3 // N (test case 1)
123 // rollNo[]

Sample Output

7

ANSWER:

Test case 1:

Input:

1

3

123
Output:
7

Test case 2 :

Input:

10

1

1

2

12

3

123

4

1234

6

123456

5

12345

8
12345678
7
1234567
9
123456789
10
12345678910
Test case 3 :

Input:

3

14

1234567891011121314

23

1234567891011121314151617 181920212223
29

1234567891011121314151617 1819202122 23 24 2526 27 28 29
Output:

16383

8388607

536870911

Test case 4 :

Input:

3

17

1234567891011121314151617

20

1234567891011121314151617 181920
25
12345678910111213141516171819202122232425
Output:

131071

1048575

33554431

Test case 5 :

Input:

3

33

1234567891011121314151617 18 19202122 2324252627282930313233

37

1234567891011121314151617 18 19202122232425262728293031323334353637
40

1234567891011121314151617 18 1920212223 242526272829 3031323334353637383940
Output:

8589934591

137438953471

1099511627775

Test case 6 :

Input:

3

42

1234567891011121314151617 181920212223 242526272829303132333435363738394041
42

45

12345678910111213141516 17 18 1920212223 24252627 28 2930 31 32 33 34 3536 3738 3940 41
4243 44 45

50

12345678910111213141516 17 18 1920212223 242526272829303132333435363738394041
42 43 44 45 46 47 48 49 50

Output:

4398046511103

35184372088831

1125899906842623

Q55. Make pairs in the party

There is a party going on, in which n boys and girls are invited. In that party, each boy and girl is assigned a
number which is denoted by the two given arrays. Now you have to make n pairs <boy, girl> out of them, such
that the sum of product of the numbers assigned to them should be minimum.

In other words you have to minimize SUM_OF( boys]i] * girls[j] ) where 0 <=i,j <n;

For example, if boys =[3, 1, 1] and girls = [12, 11, 13] then we can pair them in the following way: <boys[0],
girls[1]>, <boys[1], girls[0]>, <boys[2], girls[2]>. This combination will give us the minimum result i.e. (3 * 11)
+(1*12)+(1*13)=33+12+13=58.

Input Format:

The first line contains an integer n, denoting the number of boys and girls in the party.
The second line contains n integers separated by space, representing the elements in boys[].
The third line contains n integers separated by space, representing the elements in girls[].

Output Format:
Print the minimum possible result that can be obtained.
Constraints:

n <= 1075
boys[i], girls[i] <= 100

Sample Input

3 // N
311 // boys[]
12 11 13 // girls[]

Sample Output

58

ANSWER:

Test case 1:

Input:

3

311
121113
Output:
58

Test case 2 :

Input:

5

32141
1211121313
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.