55. | What will be the output of the program in Turb C (under DOS)? #include
int main()
{
int arr[5], i=0;
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++)
printf("%d, ", arr[i]);
return 0;
}
|
|||||||
|
56. | The following code fragment is intended to find the smallest value in arr [0] ... arr [n-1]. //Precondition: arr [0] ... arr [n-1] initialized with integers.
// arr is an array, arr.length = n
//Postcondition: min = smallest value in arr [0] ...arr [n-1]
int min = arr [0];
int i = 1;
while (i < n)
{
i++;
if (arr [i] < min)
min = arr [i] ;
}
This code is incorrect. For the segment to work as intended, which of the following modifications could be made?
I Change the line
int i = 1 ;
to
int i = 0 ;
Make no other changes
II Change the body of the while loop to
{
if (arr [i] < min)
min = arr [i] ;
i++;
}
Make no other changes.
III Change the test for the while loop as follows:
div>while (i <= n)
Make no other changes.
|
|||||||
|
57. | You may asume that array arr1 contains elements that arr1 [0], arr1 [1],..., arr1 [N-1] , where N = arr1. length. int count = 0 ;
for (int i =0; i< N; i++)
if (arr1 [i] != 0)
{
arr1[count] = arr1[i] ;
count ++;
}
int [] arr2 = new int [count] ;
for (int i=0 ; i arr2[i] = arr1[i];
If array arr1 initially contains the elements 0, 6, 0, 4, 0, 0, 2 in this order, what will arr2 contain refer execution of the code segement?
|
|||||||
|
58. | What will be the output of the program ? #include
int main()
{
int arr[1]={10};
printf("%d\n", 0[arr]);
return 0;
}
|
|||||||
|
59. | You may asume that array arr1 contains elements that arr1 [0], arr1 [1],..., arr1 [N-1] , where N = arr1. length. int count = 0 ;
for (int i =0; i< N; i++)
if (arr1 [i] != 0)
{
arr1[count] = arr1[i] ;
count ++;
}
int [] arr2 = new int [count] ;
for (int i=0 ; i arr2[i] = arr1[i];
The algorithm has run time
|
|||||||
|
60. | Consider this program segment for (int i =2; i<=k; i++)
if (arr [i] System. out. print ("SMALL");
What is the maximum numbere of times that SMALL can be printed?
|
|||||||
|
« previous
10
11
next »