CS1371_13a_Conditionals

CS1371_13a_Conditionals - CS1371 Introduction to Computing...

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

View Full Document Right Arrow Icon
1 CS1371 Introduction to Computing for Engineers Control Statements 9/4/2003
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Control Flow Statements Topics IF Statement and Logical Operators SWITCH-CASE TRY-CATCH DISP() vs FPRINTF() Statement display formats Special values Some useful Matlab built-in functions Summary Learning Objectives Learn about how to control the sequence of expressions that are evaluated in a program.
Background image of page 2
3 Problem 1: Introducing the IF Structure Step 1: Describe Problem: Write a MatLab program to: enter the radius as an input variable calculate the area and the circumference of a circle output radius, area and circumference IF the area is greater than 20 square units. Step 2: Describe input and output Radius R Radius R Area Circumference INPUT CALCULATE OUTPUT Step 3: Define test cases R=0 Area=0 and Circumference=0 R=1 Area= π and Circumference=2 π
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Problem 1 … contd. Step 4: Develop the Solution Describe the algorithm: Develop the process: Calculate the area Calculate the circumference If the area is big enough, Display radius, area and circumference otherwise, display nothing r Area = π r 2 Circumference = 2 π r START INPUT R AREA = π R 2 CIRC=2 π R AREA > 20 ? OUTPUT R, AREA, CIRC STOP NO YES
Background image of page 4
Problem 1 … contd. % calculate the area and circumference of a circle % print it out if the area is greater than 20 radius = input('please enter a radius: '); area = pi * radius^2; circumference = 2 * pi * radius; if area > 20 fprintf('\n Radius = %f units', radius); fprintf('\n Area = %f units squared', area); fprintf('\n Circumference = %f units', circumference); end % calculate the area and circumference of a circle % print it out if the area is greater than 20 radius = input( 'please enter a radius: ' ); area = pi * radius^2; circumference = 2 * pi * radius; if area > 20 fprintf( '\n Radius = %f units' , radius); fprintf( '\n Area = %f units squared' , area); fprintf( '\n Circumference = %f units' , circumference); end Step 4: Develop the Solution (cont’d) Write Matlab code START INPUT R AREA = π R 2 CIRC=2 π R AREA > 20 ? OUTPUT
Background image of page 5

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

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

This note was uploaded on 01/23/2012 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Tech.

Page1 / 24

CS1371_13a_Conditionals - CS1371 Introduction to Computing...

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

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