Fall 2007 Prelim 1 Sol - Solutions-CS100M Spring 2007...

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

View Full Document Right Arrow Icon
Solutions--CS100M Spring 2007 Sample Prelim 1 Question 1 ( 20 points; 4 each ) What do the following Matlab program fragments print? Don't worry about the print format. a = 10; b = 20; c = 3 0 ; 30 50 60 a = a + b; b = b + c; c = c + a; fprintf(' %d %d %d ', a, b, c); k = 9 ; while (k > 0) 7 5 3 1 -1 k = k - 2; fprintf(' %d ', k); end for k = 9:-2:0 k = k - 2; 7 5 3 1 -1 fprintf(' %d ', k); end a = 7; b = 5; if ((a < b) || (mod(b, 2) == 1)) a = b ; 5 10 else b = a; end fprintf(' %d %d ', a, a+b); y = 2; for k = 1:3 y = y * y 256 end fprintf(' %d ', y) 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
Solutions--CS100M Spring 2007 Sample Prelim 1 Question 2 ( 30 points; 15 each ) A certain flower shop is having a sale. Roses are $3.50 each, daffodils are $1.50 each, and this week only, a daffodil is free with each rose purchase. Write the code necessary to determine the minimum price that should be charged to a customer who receives r roses and d daffodils. You should solve this problem without using loops, but if you do use one or more loops, you'll receive partial credit. r = input('Number of roses: ');
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/28/2008 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell University (Engineering School).

Page1 / 5

Fall 2007 Prelim 1 Sol - Solutions-CS100M Spring 2007...

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