CPSC 206 507 Final Exam

CPSC 206 507 Final Exam

<p> CPSC 206 – 507 Final Exam Spring 2006</p><p>SID/SSN:</p><p>Score Possible Points</p><p>Part One 30 pts</p><p>Part Two 40 pts</p><p>Part Three 20 pts</p><p>Part Four 20 pts</p><p>Total 110 pts</p><p>1 PART ONE (30 points)</p><p>1. What is the output of the following code?</p><p>#include <stdio.h> #include <string.h></p><p>#define MAXSTRING 100</p><p> main() { char c=’a’, *p, s[MAXSTRING];</p><p>P=&c; printf(“%c%c%c “,*p, *p+1, *p+2); strcpy(s, “ABC”); printf(“%s %c%c%s\n”,s *s+6, *s+7,s+1); strcpy(s,”she sells sea shells by the seashore”); p=s+14; for ( ; *p !=’\0’; ++p) { if (*p == ‘e’) *p=’E’; if (*p == ‘ ‘) *p=’\n’; } printf(“%s\n”, s); }</p><p> int f(int a) { return (a + a); }</p><p> int g(int *x) { return (*x + *x++); }</p><p> int main(void) { int i = 5, j = 6;</p><p> printf(" f = %d\n", f(i + j)); printf(" g = %d\n", g(&i));</p><p> i = i + 2;</p><p> printf(" g = %d\n", g(&i)); printf(" g = %d\n", g(&j)); printf(" i = %d j = %d\n", i, j); return 0; } 2 3 2. What is the output of the following code?</p><p>#include <stdio.h></p><p> int go_on (int x) { return (x++ < 5); }</p><p> int tap(int y) { int i;</p><p> for ( i = y; i--;) printf ("tap "); printf ("\n"); }</p><p> int main(void) { int x, i = 0;</p><p> while (go_on(x)) tap (++x); return 0; }</p><p>4 3. What is the output of the following code?</p><p>#include <stdio.h> </p><p> void swap (int *m, int *n) { int temp = *m;</p><p>*m = *n; *n = temp; } </p><p> int main (void) { int a[4] = {2,7,4,8}; int i, j;</p><p> for (i = 3; i > 0; --i) { for (j = 0; j < i; ++j) if (a[j] < a[j+1]) swap (&a[j], &a[j+1]); for (j = 0; j < 4; ++j) printf ("%d ",a[j]); printf ("\n"); } return 0; }</p><p>5 PART TWO (40 points). Each question is worth 5 points. Short Answers. </p><p>4. Where does C code begin execution?</p><p>5. Given a 5 × 3 × 4 array A, in C, what is the linear sequential element number of A[3, 2,3] ?</p><p>6. Define: A. Enumerators</p><p>B. Typedef</p><p>7. Fill in the table below with the correct values for each of the statements. (Assume the variables are initialized with the given statements and that the statements in the table are executed in the order given.) </p><p>If an expression is not valid, indicate this in the value column.</p><p> int i = 2, j = 3, *p = &i, *q = &j, *r; double x;</p><p>Expression Value p == & i</p><p> p = i + 9 * * & p</p><p> r = & x</p><p>9 * * p / * q + 5</p><p>6 8. What is wrong with the following line of code?</p><p> int *p = &i, i = 3;</p><p>9. Simplify the following statement:</p><p> q = *&v;</p><p>10. Explain the difference between call-by-value and call-by-reference.</p><p>11. Tell me what you know about char, int, float and double.</p><p>7 PART THREE (20 points). </p><p>12. Write a function to compute the average of the values of an array, given that the header for the function is as follows:</p><p> int arr_avg(int *A[], int n); /* where n is the size of the array */</p><p>8 PART FOUR (20 points). </p><p>13. Write a C function to calculate the first 10 terms of the infinite series below. Use another function subprogram to calculate the factorial. Print each individual term and the summation of the terms. Also print the sin(z) as calculated by the library function.</p><p> sin(z) = z – z3/3! + z5/5! – z7/7!...</p><p>9</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    9 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us