VFP的问题谁懂哈?麻烦帮我解答下啊~~~~

来源:百度知道 编辑:UC知道 时间:2024/05/27 02:10:41
set talk off
clear
dine a(5 ,5)
a=0
for i=1 to 5
?space(10-i)
for j=1 to i
if i=j or j=1
a(i ,j )=1
else
a(i,j )=a(i-1,j-1 )+a(i-1,j)
endif
??str(a(i,j),2)
endif
endfor
set talk on
这是一个VFP的二级题目,麻烦有谁可以告诉我下结果是什么?如果得出那个结果的啊?谢谢了哈~~

你这段程序是不对的,少了一个endfor,多了一个endif,如果你把程序改成下面这样,可以运行出结果。
set talk off
clear
Dime a(5,5)
a=0
for i=1 to 5
?space(10-i)
for j=1 to i
if i=j or j=1
a(i,j )=1
else
a(i,j)=a(i-1,j-1 )+a(i-1,j)
endif
??str(a(i,j),2)
endfor
endfor
set talk on

结果是:(第一行的1前面9个空格,以后每行递减1个,中间每个数字间一个空格。没办法,百度会把空格全给删了,因此用点来代替)
.........1
........1.1
.......1.2.1
......1.3.3.1
.....1.4.6.4.1