Hexaware Pseudo Code Quiz 1

Question 1

Time: 00:00:00
How many iteration are done to find 7 using binary search in pseudocode?
#include<iostream>
using namespace std;
int main()
{
arr[5] = {2, 6, 7, 9, 10};
return 0;
}

2

2

3

3

1

1

4

4

Question 2

Time: 00:00:00
Find the output of the following code?
#include<iostream>
using namespace std;
int main(){
int arr[6]= {2,4,6,8,10,12};
for(int i=0;i<6;i+=3){
cout<<arr[i]<<" ";
}
return 0;
}

2 6 10

2 6 10

4 8 12

4 8 12

2 8

2 8

2 10

2 10

Question 3

Time: 00:00:00
What is the value of sum in the following code for n =5?
#include<iostream>
using namespace std;
int main(){
int n, sum =0;
int i=0;
while(i<=n){
sum = i+n;
i+=2;
}
cout<<sum;
return 0;
}

5,8,10

5,8,10

5,7,9

5,7,9

6,8,10

6,8,10

5,7,8

5,7,8

Question 4

Time: 00:00:00
What will be the output of the following code ?
#include<iostream>
using namespace std;
int main(){
string str = "Prepinsta";
string s;
for(int i=0;i<str.length(); i+=2){
s += str[i];
}
s.pop_back();
cout<<s;
return 0;
}

Peis

Peis

Peisa

Peisa

eisa

eisa

Pisa

Pisa

Question 5

Time: 00:00:00
What will be the output of the code?
#include<iostream>
using namespace std;
int main(){
string str = "*";
string s;
for(int i=0;i<10; i+=3){
s += str[0];
if(i%2!=0) s+= "#";
}
cout<<s;
return 0;
}

**#**#

**#**#

#**#**

#**#**

***#***#

***#***#

#***#*

#***#*

Question 6

Time: 00:00:00
what is the output of the following code?
#include
using namespace std;
int main(){
int ans = ' ' * 10;
cout<<ans;
return 0;
}

320

320

10

10

20

20

340

340

Question 7

Time: 00:00:00
What is the output of the code ?

using namespace std;
int main(){
int arr[5] = {2,4,3,5,6,};
for(int i=0 ; i<3; i++){
arr[i] = arr[i+1] + arr[i+2];
}
for(int i=0;i<5;i++){
cout<<arr[i]<<" ";
}
return 0;
}

7 8 11 8 9

7 8 11 8 9

7 8 11 5 6

7 8 11 5 6

1 3 4 5 6

1 3 4 5 6

8 5 3 2 10

8 5 3 2 10

Question 8

Time: 00:00:00
What will following code do?
#include<iostream>
using namespace std;
int main(){
string s = "prepinsta";
int i=0;
for(int j=s.length()-1; j>=0; j--){
cout<<s[i];
i++;
}
return 0;
}

Reverse the string

Reverse the string

Don’t change the string

Don’t change the string

Remove the characters from string

Remove the characters from string

Print half characters from string

Print half characters from string

Question 9

Time: 00:00:00
What will be the output of the following code?

using namespace std;
int main(){
string s = "prepinsta";
int i=0;
for(int j=s.length()-1; j>=4; j--){
cout<<s[i];
i+=2;
}
return 0;
}

peni

peni

ppnta

ppnta

pepsa

pepsa

peita

peita

Question 10

Time: 00:00:00
What will code do the ?
#include<iostream>
using namespace std;
int main(){
string str = "prepinsta";
int i=0, j=str.length()-1;
while(i<=j){
swap(str[i],str[j]);
i++;
j--;
}
return 0;
}

Don’t change the string

Don’t change the string

Reverse the string

Reverse the string

Swap the last character

Swap the last character

Delete the middle character

Delete the middle character

null
null