Question 1
Question 2
What is the output printed by the following C code?
# include <stdio.h>
int main ()
{
char a [6] = "world";
int i, j;
for (i = 0, j = 5; i < j; a [i++] = a [j--]);
printf ("%s\\n", a);
}
/* Add code here. Remove these lines if not writing code */
dlrow
Null String
dlrld
worow
Question 3
#include "stdio.h"
int size = 4;
int arr[size];
int main()
{
if(arr[0])
printf("Initialized to ZERO");
else
printf("Not initialized to ZERO");
return 0;
}
Question 4
Let a be an array containing n integers in increasing order. The following algorithm determines whether there are two distinct numbers in the array whose difference is a specified number S > 0.
i = 0;
j = 1;
while (j < n )
{
if (E) j++;
else if (a[j] - a[i] == S) break;
else i++;
}
if (j < n)
printf("yes")
else
printf ("no");
Choose the correct expression for E.
a[j] - a[i] > S
a[j] - a[i] < S
a[i] - a[j] < S
a[i] - a[j] > S
Question 5
Which of the following is TRUE?
only I and II
only I and IV
only II and III
only III and IV
Question 6
Consider the C program given below :
#include <stdio.h>
int main () {
int sum = 0, maxsum = 0, i, n = 6;
int a [] = {2, -2, -1, 3, 4, 2};
for (i = 0; i < n; i++) {
if (i == 0 || a [i] < 0 || a [i] < a [i - 1]) {
if (sum > maxsum) maxsum = sum;
sum = (a [i] > 0) ? a [i] : 0;
}
else sum += a [i];
}
if (sum > maxsum) maxsum = sum ;
printf ("%d\\n", maxsum);
}
What is the value printed out when this program is executed?
9
8
7
6
Question 7
Question 8
A: array [1 ... 10] [1 ... 15] of integer;Assuming that each integer takes one memory location, the array is stored in row-major order and the first element of the array is stored at location 100, what is the address of the element a[i][j] ?
Question 9
An array A contains n≥1 positive integers in the locations A[1], A[2],... A[n]. The following program fragment prints the length of a shortest sequence of consecutive elements of A, A[i], A[i+1],...A[j] such that the sum of their values is ≥M, a given positive number. It prints ‘n+1’ if no such sequence exists. Complete the program by filling in the boxes. In each case use the simplest possible expression. Write only the line number and the contents of the box.
Question 10
Let A(1:8, -5:5, -10:5) be a three dimensional array. How many elements are there in the array A?
1200
1408
33
1050
There are 37 questions to complete.