CS1371_13a_Conditionals

CS1371_13a_Conditionals - CS1371 Introduction to Computing...

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

1 CS1371 Introduction to Computing for Engineers Control Statements 9/4/2003

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

View Full Document
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.
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 π

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

View Full Document
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
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

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

View Full Document
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
Ask a homework question - tutors are online