exam3_f09 - Exam 3 ECS 102 Dr Baruch Fall 2009 Name problem...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Exam 3 ECS 102 Dr. Baruch Fall 2009 Name: problem points score 1 13 2 16 3 10 4 10 5 10 6 14 7 17 8 10 Total 100 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
1. Write a function void subString( char early[ ], char later[ ], int startIndex, int endIndex) that copies the piece of early from position startIndex to position endIndex to the variable later . It should then null terminate later to make it a string. If endIndex is beyond the string length of early (as determined by the \ 0), the function should copy only up to the null character of early . If startIndex is below 0, copying should start at 0. If startIndex is greater than endIndex , no copying should happen. Example: Before function call: early: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] p i n e a p p l e \ 0 x x x later: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] g r a p e f r u i t \ 0 x x after the call: subSting( early, later, 4, 8) early: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] p i n e a p p l e \ 0 x x x later: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] a p p l e \ 0 r u i t \ 0 x x 2
Image of page 2
2. For each of the following, what will be the output ? (a) char s[] = "dog"; char t[] = "deer"; if (strcmp(s,t) < 0) printf("wild\n"); else printf("tame\n"); (b) char x[] = "big"; char y[] = "far"; x[0]=y[0]; printf("%s %s\n",x, y); (c) char a[] = "north"; char b[] = "south"; strcpy(a,b); printf("%s\n",a); printf("%s\n",b); (d) char tall[] = "HEAVY"; char short[] = "heavy"; if (strcmp(tall,short) == 0) printf("same\n"); else printf("different\n"); (e) char op[] = "add"; printf("%d\n", strlen(op)); (f) char z[] = "table"; z[3]=’\0’; printf("%s\n",z); 3
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
3. Given the function int compute(int n) { int ans; if (n==0) ans = 1; else ans= 1 + n + compute(n-1); return ans; } (a) Circle all the line(s) of code that make up the base case for this recursion.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern