{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

exam3_s09

# exam3_s09 - Exam 3 ECS 102 Dr Baruch Spring 2009 Name...

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

Exam 3 ECS 102 Dr. Baruch Spring 2009 Name: problem points score 1 10 2 8 3 8 4 10 5 10 6 11 7 7 8 9 9 9 10 4 11 14 Total 100 1

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

View Full Document
1. For each of the following, what will be the output ? (a) char mom[] = "Martha"; char dad[] = "George"; mom[1] = dad[0]; printf("%s %s\n",mom, dad); (b) char mom[] = "Martha"; char dad[] = "George"; strcpy(dad,mom); printf("%s\n",mom); printf("%s\n",dad); (c) char mom[] = "MARTHA"; char dad[] = "GEORGE"; if (strcmp(mom,dad) < 0) printf("cheer\n"); else printf("jump\n"); (d) char Bigmama[] = "MARTHA"; char Littlemama[] = "Martha"; if (strcmp(Bigmama,Littlemama) == 0) printf("does not matter\n"); else printf("matters\n"); (e) char dad[] = "GEORGE"; printf("%d\n", strlen(dad)); 2
2. Given the function int doIt(int n) {int ans; if (n==0) ans=0; else ans = n + doIt(n-1); return ans; } (a) Circle the line(s) of code that make up the base case for this recursion. (b) What will be the value of doIt(6) ? (c) What makes this a recursive function? 3. Write a function void copyArr( int sink[ ], int source[ ], int n) that copies the first n elements of source into sink . Anything beyond the n th element of sink is unchanged. This is similar to what strcpy does for strings, but this is for arrays of ints . You may assume that both arrays have at least n elements. Example: Before function call: sink: [0] [1] [2] [3] [4] [5] [6] [7] 11 22 33 44 55 66 77 88 source: [0] [1] [2] [3] [4] [5] [6] [7] 5 10 15 20 25 30 35 40 after the call: copyArr( sink, source, 4) sink: [0] [1] [2] [3] [4] [5] [6] [7] 5 10 15 20 55 66 77 88 source: [0] [1] [2] [3] [4] [5] [6] [7] 5 10 15 20 25 30 35 40 3

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

View Full Document
4. a) What is the output? #include <stdio.h> void display(char sb[ ][7]); int main() { char sb[5][7] = {" ..... \n", " ..... \n"," ..... \n", " ..... \n"," ..... \n"}; int i; for(i=0;i<5; i++) sb[i][i]=’+’; for(i=0; i<5; i++) sb[i][4-i]=’-’; display(sb); return 0; } void display(char sb[ ][7]) { int k; for ( k=0; k<5; k++) printf("%s",sb[k]); } b) With the same function display as in the
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern