九连环算法(pascal)递归实现

类别:软件工程 点击:0 评论:0 推荐:
program jlh(input,output);
  VAR
    k,s,i,j,total:integer;

  PROCEDURE move(n:integer;VAR s:integer);
    VAR
      j,i:integer;
   BEGIN
    IF (n=1) OR (n=2)
      THEN s:=s+1
      ELSE BEGIN
             FOR i:=1 TO n-2 DO
               move(i,s);
               s:=s+1;
             FOR j:=1 TO n-2 DO
               move(j,s)
           END
   END;

  BEGIN
    k:=0;
    write('input total=');
    read(total);
    move(total,k);
    writeln;
    writeln('s=',k)
  END.

本文地址:http://com.8s8s.com/it/it35606.htm