{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L3post

# L3post - Previous Lecture(and lab Variables assignment...

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

Previous Lecture (and lab): Variables & assignment Built-in functions Input & output Good programming style (meaningful variable names; use comments) Today’s Lecture: Branching (conditional statements)

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

View Full Document
September 3 Lecture 3 4 Quick review Variable A named memory space to store a value Assignment operator: = Let x be a variable that has a value. To give variable y the same value as x, which statement below should you write? x = y or y = x Script (program) A sequence of statements saved in an m-file ; (semi-colon) Suppresses printing of the result of assignment statement
September 3 Lecture 3 5 Script execution (A script is a sequence of statements, an “m-file”) % Quad1 % Solves x^2 + 5x + 6 = 0 a = 1; b = 5; c = 6; d = sqrt(b^2 - 4*a*c); r1 = (-b - d)/(2*a) r2 = (-b + d)/(2*a) Memory space

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

View Full Document
September 3 Lecture 3 7 Statements in a program are executed in sequence % A program fragment ... x= 2*3.14 y= 1+x x= 5 % What is y now? A: 6 B: 7.28 C: some other value, or error
September 3 Lecture 3 8 % Example 1: Surface area of a sphere % A: surface area of the sphere % r: radius of the sphere r= input('Enter the radius: '); A= 4*3.14159*r*r; fprintf('Surface area is %f.\n', A);

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

View Full Document
September 3 Lecture 3 10 Input & output variable = input (‘ prompt ’) r= input (‘Enter the angle: ’)
September 3 Lecture 3 11 Input & output variable = input (‘ prompt ’) r= input (‘Enter radius: ’) fprintf (‘ message to print ’) fprintf (‘Increase ’) fprintf (‘is %f inches\n’, x) fprintf (‘Position ( %d , %d )\n’, x,y)

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

View Full Document
September 3 Lecture 3 12 Substitution sequences (conversion specifications) %f f ixed point (or floating point) %d d
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern