Lab%2004%20-%20Problems - UNIVERSITY OF CALIFORNIA,...

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

View Full Document Right Arrow Icon
UNIVERSITY OF CALIFORNIA, BERKELEY Engineering 7 – Spring 2009 Department of Civil and Environmental Engineering Instructor: Professor Rector 1 Lab 04 – Problems [20 pts total] Topics : Conditional, Loops, More Functions! Assigned : Monday, 02/23/2009 Due : Monday, 03/02/2009 at 12:00 pm (noon) Type : Take-home Remember to use the help command if you are not familiar with a command. It will be much faster than waiting for a GSI to answer your question. Moreover, a list of useful commands is provided at the end of this document. For this lab, you may submit your report as one Word document or one PDF file. If you submit a Word document, please do not use headers/footers. Remember to submit the report on Bspace as well as a hard copy in the drop boxes. Thanks! 1. for loops versus while loops (2 pts total) Name 3 similarities between for loops and while loops, as well as 3 differences. In what situations would you use a for loop versus a while loop? Think about when you use a for loop versus a while loop, the number of times you want pieces of code to run, etc. Be as concise as possible, please! For example, for loops and while loops both have a constructor clause, and both must be terminated with an end statement. You may use this example in your lab report. 2. Getting Comfortable with for , while , and if statements (5 pts total) For the following problems, write a script / m-file (NOT a function) that accomplishes the following tasks. Copy your code and output into your lab report only. Your solution must include one or more for , if , or while statements. You may not use sum, min, max, or any rounding function in this problem! If you can creatively accomplish the answer without violating any of the restrictions, you will receive full credit for being ingenious. (a) Using a for loop, create the first 16 Fibonacci numbers, given that the first two Fibonacci number entries are 0 and 1: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 (b) Create the same array in (a) using a while loop (c) Find the largest divisor for the integer 194621 (excluding the number itself) (d) Find all positive prime numbers under 50:
Background image of page 1

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

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

This note was uploaded on 02/12/2011 for the course E 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Page1 / 4

Lab%2004%20-%20Problems - UNIVERSITY OF CALIFORNIA,...

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

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