Download Presentation
§ 1.2.2 　条件语句

Loading in 2 Seconds...

1 / 10

§ 1.2.2 　条件语句 - PowerPoint PPT Presentation

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about '§ 1.2.2 　条件语句' - gypsy

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

§1.2.2　条件语句

1、输入语句、输出语句和赋值语句对应于算法中的哪种结构？这三种语句的一般格式是什么？

INPUT“提示内容”;变量

PRINT“提示内容”;表达式

1、条件结构用怎样的程序语句来描述？这种语句的一般格式是怎样的？

IF条件 THEN

ELSE

END IF

IF条件 THEN

END IF

Δ=b2－4ac

p= －b/2a

q=SQR(ABS (Δ))/(2a)

Δ≥0?

x1=p+q

x2=p-q

x1=x2?

QBASIC程序：

INPUT “Please input a，b，c＝：”；a，b，c

d = b * b –4 * a * c

p = – b / (2 * a)

q = SQR(ABS(d)) / (2 * a)

IF d >= 0 THEN

x1 = p + q

x2 = p – q

IF x1 = x2 THEN

PRINT “One real root：”；x1

ELSE

PRINT “Two real roots：xl”；x1，”and x2”; x2

END IF

ELSE

PRINT “No real rool.”

END IF

END

INPUT “a，b，c=”；a，b，c

IF b > a THEN

t = a

a = b

b = t

END IF

IF c > a THEN

t = a

a = c

c = t

END IF

IF c > b THEN

t = b

b = c

c = t

END IF

PRINT a，b，c

END

b＞a?

t=a,a=b,b=t

c＞a?

t=a,a=c,c=t

c＞b?

t=b,b=c,c=t

1、条件结构的程序表示

IF条件 THEN

ELSE

END IF

IF条件 THEN

END IF

2、注意书写的规范性

{

0.25×m

y=

0.25×50+0.25×(m－50)

0.25×50+0.35×50+0.45×(m－100)

INPUT “m=”;m

IF m<=50 THEN

y=m﹡0.25

m≤50?

ELSE

IF m<=100 THEN

m≤100?

y=0.25﹡50+0.35﹡ (m－50)

ELSE

y=0.25×50+0.35×

50+0.45×(m－100)

y=0.25×50+

0.35×(m－50)

y=m×0.25

y=0.25﹡50+0.35﹡50+

0.45﹡ (m－100)

END IF

END IF

PRINT “y=”;y

END