# loops - לולאות

Post on 15-Nov-2014

122 views

Category:

## Documents

Embed Size (px)

DESCRIPTION

מצגות מקורס מבוא לתכנות בעזרת MATLAB במכללת אורט בראודה

TRANSCRIPT

04/1.3

: . For While " Break .

MatLab 00122))

04/2.3

. For While " Break .

MatLab 00122))

04/3.3

( ). : : , , .. , ... , , . MATLAB %01 . . MatLab 00122))

04/4.3

: ( ) . : . 01 , 01 , '. : for " ' . while ' MatLab 00122))

04/5.3

. For While " Break .

MatLab 00122))

04/6.3

FORfor 01:1=jdone

: 01:1=for j ;% computations end : 01:2:1=for j ;% computations end

computations

' ( 01). . . " BREAK MatLab 00122))

04/7.3

' 1: : . 01 . . . . , -02 . . 02.

MatLab 00122))

04/8.3

: Smalls 02 N

S P

MatLab 00122))

3.9/40

: 1 - % calculate the area and circumference of 10 circles . %print out if the area is greater than 20 and counts the others

Smalls = 0; for N = 1:10 fprintf(\nplease enter radius number %d ', N); R = input( '); S = pi * R^2; P = 2 * pi * R; if S > 20 fprintf('\n Radius = %f units', R); fprintf('\n Area = %f units squared', S); fprintf('\n Circumference = %f units', P); else Smalls = Smalls + 1; end %end if end %end for fprintf('\n the number of circles with area less or equal 20 is: %d ,Smalls);

MatLab ))22100

3.10/40

FOR :

0.5 0.7

0.1 5

please enter radius number 10 0.01 the number of circles with area less or equal 20 is: 5 >>

04/11.3

1.1 1, 02

00122) ) MatLab

3.12/40

1.1 -

Smalls = []; for N = 1:10 fprintf)'\n please enter radius number %d ', N(; R = input)' '(; S = pi * R^2; P = 2 * pi * R; if S > 20 fprintf)'\n Radius = %.2f units', R(; fprintf)'\n Area = %.2f units squared', S(; fprintf)'\n Circumference = %.2f units', P(; else Smalls = [Smalls,R]; end %end if end %end for fprintf)'\n the number of circles with area less or equal 20 is: %d ',length)Smalls((;'

04/31.3

2

51 , 0 1.

00122) ) MatLab

04/41.3

2 -

51:1=for I 0==(2,if rem)I ;0=(V)I else ;1=(V)I end end ;(disp)V

:

00122) ) MatLab

04/51.3

. For While " Break .

MatLab 00122))

04/61.3

While : ;0=k 0155 | ptor ;% computations end

next

WHILE . ( k) , ( grade ptor). MatLab 00122))

04/71.3

' 3: : . . . . . , -02 . . 02. . .

MatLab 00122))

04/81.3

3 - :

-

WHILE loop

MatLab 00122))

3.19/40% calculate the area and circumference of unknown circles . %print out if the area is greater than 20 and counts the others % the program terminates if radius < = 0 Smalls=0; R=input(please enter first radius:); While R > 0 S= pi * R^2; P = 2 * pi * R; if S> 20 fprintf('\n Radius = %f units', R); fprintf('\n Area = %f units squared', S); fprintf('\n Circumference = %f units', P); else Smalls = Smalls + 1; end %end if R= input(please enter the next radius: end %end while fprintf('\nthe number of circles with area less or equal 20 is: %d, Smalls); ');

: 3 -

MatLab ))22100

3.20/40

:

the number of circles with area less or equal 20 is: 2>>

MatLab ))22100

04/12.3

4

00122) ) MatLab

04/22.3

4

:

00122) ) MatLab

3.23/40

4.0 10- a=input)'Enter a new vector:'(; i=1; while i

Recommended