{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

exam2-2009spring

exam2-2009spring - CSE 1311 Exam#2 Name If you show your...

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

CSE 1311 Name: Exam #2 March 30, 2009 If you show your work, you should CLEARLY indicate what your answer is. Problems 1–14 are worth 5 points each. ASCII values of alphanumeric characters 32 space 51 3 70 F 89 Y 108 l 33 ! 52 4 71 G 90 Z 109 m 34 " 53 5 72 H 91 [ 110 n 35 # 54 6 73 I 92 \ 111 o 36 \$ 55 7 74 J 93 ] 112 p 37 % 56 8 75 K 94 ^ 113 q 38 & 57 9 76 L 95 _ 114 r 39 ’ 58 : 77 M 96 ‘ 115 s 40 ( 59 ; 78 N 97 a 116 t 41 ) 60 < 79 O 98 b 117 u 42 * 61 = 80 P 99 c 118 v 43 + 62 > 81 Q 100 d 119 w 44 , 63 ? 82 R 101 e 120 x 45 - 64 @ 83 S 102 f 121 y 46 . 65 A 84 T 103 g 122 z 47 / 66 B 85 U 104 h 123 { 48 0 67 C 86 V 105 i 124 | 49 1 68 D 87 W 106 j 125 } 50 2 69 E 88 X 107 k 126 ~ strlen() returns the length of a string, minus the terminating null. For example, strlen("book") has a value of 4. It is in the library string.h

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

View Full Document
1. What does the following program print? #include <stdio.h> int fc(int [], int); int main(void) { int data[4] = {4, 3, 0, 2}; printf("The sum is %d\n", fc(data, 4) ); } int fc(int a[], int cols) { int i = 0; int sum = 0; while(i < cols) { if(a[i] || sum) { sum += a[i]; printf("%d\n", sum); } i++; } return sum; }
2. What does the following program print? #include <stdio.h> void fc(int [][3]); void printArray(int [][3]); int main(void) { int data[3][3] = {{ 7, 11, 15}, {23, 25, 29}, {35, 42, 46}}; fc(data); printArray(data); } void fc(int data[][3]) { int i, k; for(i = 0; i < 3; i++) for(k = 0; k < 3; k++) if(data[i][k] % 5 != 0) data[i][k] = 0; } void printArray(int data[][3]) { int i, k; for(i = 0; i < 3; i++) { for(k = 0; k < 3; k++) printf("%3d", data[i][k]); printf("\n"); } }

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

View Full Document
3. What does the following program print? #include <stdio.h> #include <string.h> void fc(char []); int main(void) { /* 01234567890 */ char text[] = "gwippans"; fc(text); printf("%s\n", text); } void fc(char str[]) { int i = 0; char temp; int len = (int) strlen(str); while(i < len/2) { if(str[i] < ’k’) { temp = str[i]; str[i] = str[len - i - 1]; str[len - i - 1] = temp; } i++; } }
4. What does the following program print? #include <stdio.h> void fc(double [], double [], int); int main(void) { double data[] = { 1.5, 2.5, 3.0, 4.5}; double values[] = { 1.5, 2.0, 1.5, 1.5}; int len = 4; fc(data, values, len); } void fc(double a[], double b[], int len) { int i; for(i = 0; i < len; i ++) { b[i] = b[i] + a[len - i - 1]; printf("%3.1f ", b[i]); } } 5. What does the following program print?

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 / 16

exam2-2009spring - CSE 1311 Exam#2 Name If you show your...

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

View Full Document
Ask a homework question - tutors are online