1、鸡兔同笼(顺序结构)
题目描述

“鸡兔同笼”是我国古代著名趣题之一。大约在1500年前,《孙子算经》中就记载了这个有趣的问题。书中是这样叙述的:“今有雉兔同笼,上有三十五头,下有九十四足,问雉兔各几何?这四句话的意思是:有若干只鸡兔同在一个笼子里,从上面数,有35个头;从下面数,有94只脚。求笼中各有几只鸡和兔?
现有n个头和m个脚,请你写出伪代码,并用raptor软件绘制流程图,计算到底有多少只鸡和兔。
样例输入
2 6
样例输出
1 1
----------------------------------------------------------------------------------------------
分析:
设x、y分别为鸡和兔的个数,则
x+y=n ①
2x+4y=m ②
②-2①,y=1/2(m-2n)
题解:
(1)伪代码
input n,m
y=1/2*(m-2*n)
x=n-y
output x,y
(2)流程图(raptor)

-----------------------------------------------------------------------------------------------
2、闰年判断(选择结构)
题目描述
输入年year,判断该年是否为闰年。判断闰年的条件是:能被4整除但不能被100整除,或者能被400整除。请你写出伪代码,并用raptor软件绘制流程图,进行闰年判断。
样例输入1:2010
样例输出1:2010 is an even year.
样例输入2:2008
样例输出2:2008 is a leap year.
------------------------------------------------------------------------------------------------
分析:
判断闰年的条件是:能被4整除但不能被100整除,或者能被400整除。
方法1:可以直接使用逻辑表达式与双分支语句结构
方法2:可以使用多分支语句
题解:
(1)伪代码
方法1:
input year
if year mod 4=0 and year mod 100 !=0 or year mod 400=0 then
output year is a leap year.
else
output year is an even year.
endif
方法2:
input year
if year mod 4 !=0 then
output year is an even year.
else if year mod 100 !=0 then
output year is a leap year.
else if year mod 400 =0 then
output year is a leap year.
else
output year is an even year.
endif
方法3:
input year
if year mod 4 = 0 then
if year mod 100 =0 then
if year mod 400 =0 then
output year is a leap year.
else
output year is an even year.
endif
else
output year is a leap year.
endif
else
output year is an even year.
endif
(2)流程图(raptor)



------------------------------------------------------------------------------------------
3、乘法九九表(循环结构)
题目描述:请你写出打印乘法九九表的伪代码,并用raptor软件绘制流程图。
样例:
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
--------------------------------------------------------------------------------------------
分析:
双循环,外循环跑行,内循环跑列。
题解:
(1)伪代码
方法1:
for i=1 to 9
for j=1 to 9
if i>=j then
output j+"*"+i+"="+i*j+" "
endif
endfor
output
endfor
方法2:
for i=1 to 9
for j=1 to 9
output j+"*"+i+"="+i*j+""
endfor
output
endfor
(2)流程图(raptor)

方法1 方法2
----------------------------------------------------------------------------------------------
4、体操评分(数组)
题目描述
体操比赛,现有10名评委评分,评分原则是去掉最高分与最低分,然后求平均。请你写出伪代码,并用raptor软件绘制流程图。
------------------------------------------------------------------------------------------------
分析:
双循环,外循环跑行,内循环跑列。
题解:
(1)伪代码
s=0
for i=1 to 10
input a[i]
s=s+a[i]
endfor
imax=a[1]
imin=a[1]
for i=0 to 10
if a[i]>imax
imax=a[i]
endif
if a[i]<imin then
imin=a[i]
endif
endfor
avg=(s-imax-imin)/8
output avg
(2)流程图(raptor)

--------------------------------------------------------------------------------------------------
5、组合数(函数)
题目描述:计算。请你写出伪代码,绘制流程图。
--------------------------------------------------------------------------------------------------------------------
分析:根据上述公式可以看出,实际上就是求解多次阶乘问题。
题解:
(1)伪代码:
主调函数
input m,n
output fact(m)/(fact(n)*fact(m-n))
被调函数
fact(x)
f=1
for i=1 to x
f=f*i
endfor
endfact
(2)流程图(raptor)

主调函数 被调函数

