{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

compe160Exam1_S08

# compe160Exam1_S08 - CompE160 Introduction to Programming...

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

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

View Full Document

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.

Unformatted text preview: CompE160 Introduction to Programming Marino Spring 2008 a} r CompEl60 Exam 1 [/11 Closed book, closed notes, no calculators Name f 16%! 571/ ID to?! %/ 1. Information representation 1 a 6 a. What unsigned integer value is represented by the word 10110001 (Base 2 code)? 7 7 4! a . —_ I \ Inf 3 11" ‘ I it; b. What signed integer value is represented by the word llOllOOLl/QC code)? 4' Z Z I 1,1 41,; ’I‘3 3 u; c. Write the 8-bit word that represents the signed integer -67 (2C code)? I 0 l l r i 0 l t / ‘a d. What is the range of the 8-bit Two's Complement code, in decimal? ' [7— 9 <= x <= 4- 12 7 ’ 4/ 2. 0n the “screen ” below; show exactly what will be displayed when the following program / executes. . 2,, it . main() ‘ ingrﬁ ’24; 59179,, . i m. 1:"; '/|" 1nt i=3, 3:4, k=5, m, 2.0 ‘ ' float x =3_.0, y = 12.25, 2; J m=j+3%'l*k/2; .76 ‘1“?- printf("m = %d\n", m); .-——-—-'" m ="‘I* /(flo'at)k * 3; “45 prin f("m = %d\n", m); z = k / i * y * k; printf("z = %O.2f\n", z); printf("%—8.2ﬁ%{—8.2,f\n%.8.3f\n", x, y, z); CompE160 Introduction to Programming Marino Spring 2008 3. The following program is difﬁcult to read because of the poor use of whitespace (i.e., spaces, tabs and newlines). Rewrite the program using a readable style. main(){int i, j, n;i = 1; j = O;printf("Enter n: "); scanf("%d", &n);while (i < 10){if (n % i == 0) j += i;else j -= i;i++; }printf("j = %d\n", j);} J : 5’} n ‘ , , tar-1.034% Zairevﬂ' ‘3) mum», UM") CompE160 Introduction to Programming Marino Spring 2008 4. 4. Suppose a theater has 100 seats arranged in 10 rows of 1 0 seats each. Suppose the seats )/ are priced as follows: l—‘NNNNNNNNH I—INNNNNNNNl—I HNNLHU‘IU‘IU‘NNQ—J l—‘NNU’IU‘IUTCNNNI—I I-‘NNUIU‘IwUINNI—l v—INNNNNNNNH HNNNNNNNNH D-‘l—‘I—‘D—‘I—‘l—‘I—‘l—‘HH HHHl—‘I—ID—‘HI—‘l—‘H ‘HNNU‘IU'IU'ILHNNH Write a program that prompts the user to enter the row and column of a seat, and then prints the price of the seat. (The rows and columns are each numbered 1 through 1 0.) Make the program as simple as possible. A sample run might look as follows: Enter the row number: 3 Enter the column number: 2 price = 2 dollars I (2'19:ka ) 4/, {wt raw) at) Price; ""” pr? w‘ré‘( "Em‘tﬂr raw ww‘eer': a); )V/ £40m? L“ 5":ch ") army) PVth-QL“Ew-t&r caLmeberi I); 34% 907.41 “J Lime); {AC-(aw =2 rDm==lt> 1] L5,? :1 (0Q ::\b) g Klﬁca-g \; é!‘ FE €199. 3‘: (raw <4» \ 11:15:; = 3 \ way? u @214?“ (“2’”) alGLPC‘Tct 5 g ) . - CompEl60 Introduction to Programming Marino Spring 2008 l 4" 5. Write a program that will prompt the user to enter 10 integers and then print the sum of the / positive integers and the sum of the negative integers. A sample run might look as follows: Enter a list of 10 integers. 4 -6 -2 —7 The positive numbers add to 28 The negative numbers add to —16 l /m-4(’K ( 5 ‘V ' . K a {0‘6 nwm\ \$5.”,MEQ5 513-) jumiﬁfﬂgc—o )‘f b ) 1 print-{‘(“Zwtcc taintegecst \w / ¥0rég=o~ L4\o)‘1++> % ’) u It :> ‘ 4L— 2 5¢aWeL 7pc! )4”‘*W‘ / M (ww‘eézﬂ ) \&uMN£a/*=WWM) e‘éﬂ . 5wm?a‘r *5: V‘W’M ) u c: j ’ " / Prrwh’ ( myth“: “W” a / Prtkhaé’t'ﬂe “445% “Ma? MM 4» ZJ “on; 5 5 awe? J; ...
View Full Document

{[ snackBarMessage ]}

### Page1 / 4

compe160Exam1_S08 - CompE160 Introduction to Programming...

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

View Full Document
Ask a homework question - tutors are online