Spring 09 WS 10

# Spring 09 WS 10 - ENG EK 127 Worksheet 10 Name_Julian Hart...

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

ENG EK 127 Worksheet 10 Name: _______Julian Hart___________________________________________ The minimum set is Problems 1-8. 1. Write a for loop that will print the column of real numbers from1.1 to 2.9 in steps of 0.1. >> for i = 1.1:.1:2.9 fprintf('%f\n',i) end 1.100000 1.200000 1.300000 1.400000 1.500000 1.600000 1.700000 1.800000 1.900000 2.000000 2.100000 2.200000 2.300000 2.400000 2.500000 2.600000 2.700000 2.800000 2.900000 >> 2. Write a function “sumsteps2” that calculates and returns the sum of 1 to n in steps of 2, where n is an argument passed to the function. For example, if 11 is passed, it will return 1 + 3 + 5 + 7 + 9 + 11. Do this using a for loop. Calling the function will look like this: >> sumsteps2(11) ans = 36 function out = sumstep2(x) sum = 0; for i = 1:2:x sum = sum + i; end out = sum; 3. Prompt the user for an integer n and print “I love this stuff!” n times. >> for1

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

View Full Document
Enter an interger:5 I love this stuff! I love this stuff! I love this stuff! I love this stuff! I love this stuff!
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 07/19/2010 for the course EK 211 taught by Professor Attaway during the Spring '10 term at BU.

### Page1 / 5

Spring 09 WS 10 - ENG EK 127 Worksheet 10 Name_Julian Hart...

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

View Full Document
Ask a homework question - tutors are online