Looping
at last!
Due date: 07.11
1. Objectives
This homework consists of only three problems. Completing the problems will give you
practice with simple loops.
First skim, and then read the entire assignment before starting.
2. Printing roots
Write a
program called printRoots.m that prints the square root
of every integer between 1 and 100 (inclusive of both).
3. Printing the primes
Write a
program called printPrimes.m that prints the prime
numbers between 1 and a value entered by the user. Hint:
Try typing lookfor
prime at the Command window for some helpful
functions.
4. Finding the average
Write a program called findAvg.m that finds the average
of all the numbers input by the user.
Your program will need a stopping value: -1 should serve nicely. The value -1 signifies the end of the sequence,
but is not a part of the sequence itself.
What does your program do if the first number the user enters is –1? Be sure your program handles this case
appropriately.
5. Submitting your work
Type your name, student ID, and the date at the top
of each M-file. Print and sign each file. Hand the signed documents to the teaching
assistant at the beginning of lab on Thursday 11 July 2002.