compe112mid22004-key

# compe112mid22004-key - ATILIM UNIVERSITY Department of...

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

ATILIM UNIVERSITY Department of Computer Engineering COMPE 112 Computer Programming in C Midterm II Date: April 15, 2004 Duration: 110 min. Q1 (20 pts) Q2 (15 pts) Q3 (15 pts) Total(110 pts) Q4 (30 pts) Q5 (30 pts) Q1a (5 pts.) Consider the following: char s[ ] = “COOKIE”; char *t = &s[2]; What do the following statements print? 1. printf("%s\n", s); 2. printf("%s\n", t); 3. printf("%d\n", strlen(s)); 4. printf("%d\n", strlen(t)); 5. printf("%c %c\n", s[2], t[2]); 1/7 Name Surname Id Signature C O O K I E O K I E 6 4 O I

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

View Full Document
Q1b (8 pts.) Consider the following: int a[ ] = {1, 2, 3, 4, 5, 6}; int j; Write the contents of the array a[ ] after each iteration of this loop: for (j=0; a[j] <= 2* a[j+1]; ++j) a[j+1] += a[j]; 1 3 3 4 5 6 1 3 6 4 5 6 1 3 6 10 5 6 1 3 6 10 15 6 Q1c (7 pts.) Find the output of the following program. #include <stdio.h> int abc(int x, int *y); int main(void) { int x = 5, y = 12, k = 6; y = abc(x, &k); printf(“%3d %3d %3d”, x, y, k); return(0); } int abc(int x, int *y) { x = *y*6; *y = *y + x; printf(“%3d %3d\n”, x, *y); return(x); } 3 6 4 2 5 3 6 4 2 2/7
Q2(15 pts) Write a function that calculates the harmonic series: n 1 4 1 3 1 2 1 1 + + + + + This function will receive the positive integer

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

compe112mid22004-key - ATILIM UNIVERSITY Department of...

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

View Full Document
Ask a homework question - tutors are online