exam3_s09

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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]=’-’;
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/05/2011 for the course ECS 102 taught by Professor Baruch during the Spring '06 term at Syracuse.

Page1 / 11

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

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online