Lab%2004%20-%20Problems

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

Info icon This 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)
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern