Question 11
A program P reads in 500 integers in the range [0..100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?
Question 12
What will the output of the below code, be if the base address of the array is 1200?
#include <iostream>
using namespace std;
int main()
{
int arr[] = { 1, 2, 3, 4, 5 };
cout << arr << ", " << &arr << ", " << &arr[0] << endl;
return 0;
}
Question 13
What is the correct way to call the function (fun) in the below program?
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
void fun(char* arr)
{
int i;
unsigned int n = strlen(arr);
for (i = 0; i < n; i++)
cout << " " << arr[i];
}
// Driver program
int main()
{
char arr[]
= { 'g', 'e', 'e', 'k', 's', 'q', 'u', 'i', 'z' };
// How to call the above function here to print the char
// elements?
return 0;
}
Question 14
Let A be a matrix of size n x n. Consider the following program. What is the expected output?
void fun(int A[][N])
{
for (int i = 0; i < N; i++)
for (int j = i + 1; j < N; j++)
swap(A[i][j], A[j][i]);
}
Question 15
What will do the following code?
void fun(int arr[], int n)
{
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
for (int k = i; k <= j; k++)
cout << arr[k] << " ";
cout << endl;
}
}
}
Question 17
Consider the below program, and what is doing this program basically?
#include <bits/stdc++.h>
using namespace std;
void print(char a[], int n, int ind)
{
for (int i = ind; i < n + ind; i++)
cout << a[(i % n)] << " ";
}
int main()
{
char a[] = { 'A', 'B', 'C', 'D', 'E', 'F' };
int n = sizeof(a) / sizeof(a[0]);
print(a, n, 3);
return 0;
}
Question 18
Fill in the blanks for completing the program to rotate an array by d elements.
/*Function to left rotate arr[] of size n by d*/
void Rotate(int arr[], int d, int n)
{
int p = 1;
while (_______) {
int last = arr[0];
for (int i = 0; ______ i++) {
arr[i] = arr[i + 1];
}
__________
p++;
}
}
Question 19
Refer the below diagram and identify the problem.
[caption width="800"] [/caption]Question 20
Consider the below program. What is the expected output?
void fun(int arr[], int start, int end)
{
while (start < end) {
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
There are 20 questions to complete.