160Exam2_F07 - Fall 2007 CompE160 Introduction to...

Info iconThis preview shows pages 1–4. 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

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

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

Unformatted text preview: Fall 2007 CompE160 Introduction to Programming Marino CompE160 Exam 2 Closed book 9 ,_ Name ‘ [W \ ' ID 1. Consider the following. program. a A 2 13' #include <stdio.h> :2 %: I€3 fl“ . int mystery(int x, int y); ‘ , 3 'main () { int a =_2, b = 4; b = mystery(a+l, b) + 5; printf("a = %d, b = %d\n", a, b); } int mystery(int x, int y) { int temp-= y - x; x =,2 * y; temp += 2; return temp; } , ‘ 1.a. During the execution of the program above, what variables exist in memory just before / the statement "return temp; " executes, and what are their values? ) w; 7¢=3>C¥‘t%m€’3 ~— 'Z_ (3% 514., M57471M7 pr” 5:, >< Z“ 1’ 2;“. 41‘2- é 1.b. During the execution of the program above, what variables exist in memory just before the statement "printf ("a = %d, b = %d\n" ,‘ a, b) ; " executes, and what are their values? a ’ 2 £404., 1 V” 04" ea. .»’ a‘z 5’3" If 1.c Show exactly what will be displayed when the program above executes. a” I a: 2) 5:8 7. CompElGil introduction to Programming Marino Fall 2007 ?- 2. Write the definition of a function //, int randInt(int min, int max); that will return an integer value between min and max. Forexample, the statement n = randInt(25, 50); will assign a value between 25 and 50 tothe variable n. (/3214 Fwdfni'(r”£’ mm) ['Mkmx) Z /"” 2 \(gT 7 ,2er yet/tail); (mxvmi’n) + MM; 3. Shaw exactly what will be displayed when the following program ace-ates. / #include <stdio.h> . Ag void mystery(int x, int* y); a” main() 0‘; b ("7’ { 10 int a = 3, b = 5; mystery(a, &b); ‘ printf("a = %d, b = %d\n", a, b); } void mystery(int x, int* y) { *y = *y * 2; x = *y + 5; Cmmfiflfl)hmmmaMnumgmmmmg' thm ; nmzmn I7 4. Write the definition of a function - float maxAbs(float x, int size); / that will return the largest absolute value of the numbers in the array x. For example, when the following code executes, the value assigned to y will be 4 4 . 4. float a = {-22.2, 33.3, ~44.4, 11.1}; float y; y = maxAbs(a, 4); Do not use any library functions. 1 f/Dwg maw4b9 “Cindi” 11/53,. 7“£7é2£> lfl J’ Y r ' l f {V fir W ; WMELIIL’ VNl a \ } \ ' E 0"“) W'iw‘m : ‘ 1 £0 W \ v ’ 0) y) _ ' 2+?) ,’_/‘ (4,153 7 W) MK =: @[L'] 3 a 61% 1? (wan > Mo Mml max 5 ‘4'“;3 Zr * l / rgwfi/L MK} I CompEl60 Introduction to Programming Marino Fall 2007 5. Write a complete program that will accept a list of integers from the keyboard, and then display the list backwards. The program stops accepting integers when the user types q‘. You may assume that fewer than 10 integers will be entered. A sample run of the program might look as follows: Enter a list of integers, q to quit. ll 33 22 44 66 q list in reverse order: 66 44 22 33 11 , MACKL 3 {a ‘ I’M“. ,1 7, “‘ ’ ‘ FHQW inf, Qua?) L ) - . Clam. I / Frmha (an inter Andra-P mil-gem) g 157; fatty“); ...
View Full Document

This note was uploaded on 05/12/2008 for the course COMPE 160 taught by Professor Marino during the Fall '08 term at San Diego State.

Page1 / 4

160Exam2_F07 - Fall 2007 CompE160 Introduction to...

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

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