aaasdasda

download aaasdasda

of 3

description

f

Transcript of aaasdasda

  • 7/18/2019 aaasdasda

    1/3

    2014 abc

    2014 Exam Solutions

    Question 0Ans: A

    Question 1Ans: C

    Question 2 int aTemp = a; int bTemp = b; int cTemp = c; a = bTemp; b = cTemp; c = aTemp;

    Question 3

    The value of z will be 6

    Question 4Ans: C

    Question 5The value of result will be 2

    Question 6Ans: B

    Question 7Notes: count becomes num + 1

    loop runs num timesnum | count | result0 | 1 | 01 | 2 | 12 | 3 | 33 | 4 | 64 | 5 | 105 | 6 | 15Answer: sums numbers between 0 and num (inclusive)

    Question 8 int oldLeft = values[0];

    j = 0; while (j < LENGTH) { values[j] = values[j + 1]; j++; } values[LENGTH - 1] = oldLeft;

    Question 9 double calcMean (int *array, int length) { long sum = 0;

    int i = 0; while (i < length) {

    sum += array[i]; i++; }

  • 7/18/2019 aaasdasda

    2/3

    return (double)sum/length;

    }

    Question 10*

    **** ****

    ****** ** ** ******

    First Bug: col was not reset for subsequent rows -

    should set col to 0 when row is incremented.Second Bug: The print of a new line only occured at the very end -

    should occur in while loop.

    Question 11NB: '%x' means print in hexadecimal format

    'printf ("%x\n",nines);'This will print 999 as hexadecimal i.e. 3e7

    'printf ("%x\n",nines * 0x10);'

    This will print 999*16 as hexadecimal i.e. 3e70

    byte * ptr = (byte *) &nines;This converts nines into a 'byte'That is, a char.

    'printf ("%d\n",ptr[0]);'This will print the first byte (i.e. the last part of 999 as hexadecimal) as a decimal number i.e. 231

    'printf ("%d\n",ptr[1]);'The next byte i.e. 3

    'printf ("%d\n",ptr[2]);'The next byte i.e. 0

    'printf ("%d\n",ptr[3]);'The last byte i.e. 0

    Question 12

    Answer: If you get down to 366 days and the year is a leap year, you will get into the while loop, but since you only have 366 days left you will not get into the subsequent loop and will still have 366 days left, so will get stuck in an en

  • 7/18/2019 aaasdasda

    3/3

    dless loop.This will occur, for example, if days is 1872.

    Question 13Turtle (2,1)|gamera | achilles|| 2 | 1 |

    | Turtle (2,0)| |gamera | achilles|| | 2 | 0 || | 1 | 1 || | Turtle (1,0)| | |gamera | achilles|| | | 1 | 0 || | | 0 | 1 || | returns 2| | 0 | 2 || returns 3| 1 | 3 |

    | Turtle (1,2)| |gamera | achilles|| | 1 | 2 || | Turtle (1,1)| | |gamera | achilles|| | | 1 | 1 || | | Turtle (1,0)| | | |gamera | achilles|| | | | 1 | 0 || | | | 0 | 1 || | | returns 2| | | 0 | 2 || | returns 3

    | | 0 | 3 || returns 4| 0 | 4 |returns 5

    call (2,1)call (2,0)call (1,0)call (1,2)call (1,1)call (1,0)The value returned is 5.

    Question 14

    Question 15

    Question 16

    Question 17