160Exam1_F07 - V”; CompE160 Introduction to Programming...

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: V”; CompE160 Introduction to Programming Marino Fall 2007 CompEl60 Exam 1 Closed book, closed notes, no calculators Name ID i. 1. Information representation 10$ ,1, g '- - - ‘ ’ /‘ ’ / 53 [.1 8 a. What un51gned integer value 15 represented by the weird 1001(001 (Base 2 code)? L 44. l: w 4» 1 3 27 \ l I I / I //i5’ b. What signed integer value is represented by the word 11010011 (2C code)? " 7L; '1». ’ ’ c. Write the 8-bit word that represents the signed integer -75 (2C code)? / a / I 0 / 0 / 2“ d. What is the range of the 6-bit Two's Complement code, in decimal? " 3 2 <= x <= 5 l / . 2. T he following program is difficult 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; EWOJKC) j = O;printf("Enter n: "); . ‘ > , scanf("%d", &n);while "WE 4) J > V) > (i<10){if(n%'==0) 4—1/3 j += i;else j —= i;i++; :: o; I I" ‘ u I }printf(nj = %d\nvv, {oriniué' (tm’ter 'V\ . >) ’ scam0 C“ 70d?) 3(0)} V3141 la (I:<ID) / J+=L5 5156‘ .‘ J" J L++)' CompE160 Introduction to Programming Marino Fall 2007 / . 9 3. Show exactly what will be displayed when the following program executes. main ( ) k=5, m; 12.345, Z; In: i+13 / j*3 / k; n , m = i + 19 % +j; S;z_{’ printf("m 76%d\n", m); 2:6 . ' = %O.2f\n", z); printf("%8.2f\n%-8.2\n", x, y); I b 4. Write a program that prompts the user to enter a test score between 0 and 100, and then / prints the letter grade corresponding to that score using the following key: 90-100 =A; 80-89 = B; 0- 79 = C. A sample run might look as follows: Enter test score: 85 Letter grade is B rtufif/se ) ’L ?Z,flt«5cora* ’ I) “Prth ( “Enter it# “Me” / )4 (more F70) r v .. e What; (llzéefi’er—jrace 1’6 A\M >J 61% W ( fie“ 7" 95”) frat! (“letter 3740/6 75 5W" )J flee __ ,, ‘ a [9,»;va ("l’efier’gwa :2 CW DJ \ 3 3. CompE160 Introduction to Programming Marina Fall 2007 $4” 5. Write a program that will prompt the user to enter a list of positive real numbers. The user will terminate the list by entering -1. The program will print the average of the numbers entered. int Cam/1 e; ’ . r ‘ - {'10 Z " Zia-fer [33'3" Cffipfi‘ffi/g VLWLberf)—I iwf’ v \E‘ 3 4/ p? (“fl/67¢ } ("average = Z afiw‘) 5”” flow”); ...
View Full Document

Page1 / 3

160Exam1_F07 - V”; CompE160 Introduction to Programming...

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

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