我是一个学生 求一道题的答案
1 2 3  4  5 
1 2 6 24 120
这道题怎么做? 我是真不会。
用过程不用函数
pascal语言做

解决方案 »

  1.   


    procedure Test(n: Integer);
    var
      i: integer;
      preValue: integer;
      strReslut: string;
      strIndex: string;
    begin
      if n < 1 then Exit;
      strIndex :='1';
      strReslut :='1';
      preValue := 1;
      for i := 2 to n do
      begin
        strIndex := strIndex + ';' + IntToStr(i);
        strReslut := strReslut+';'+IntToStr(preValue*i);
        preValue:=preValue*i;
      end;
      ShowMessage(strIndex+#13+strReslut);
    end;没仔细测试。
      

  2.   

      TIntArray = array of Integer;  TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}//例程
    procedure Calculate(var IntArray: TIntArray; N: Integer);
    var
      Index: Integer;
    begin
      SetLength(IntArray, Succ(N));
      if N < 1 then Exit;
      IntArray[Low(IntArray)] := 1;
      for Index := Succ(Low(IntArray)) to High(IntArray) do
      begin
        IntArray[Index] := IntArray[Pred(Index)]*Index;
      end;
    end;//测试
    procedure TForm1.Button1Click(Sender: TObject);
    var
      IntArray: TIntArray;
    begin
      Calculate(IntArray, 5);
      ShowMessage(IntToStr(IntArray[3]));
    end;
      

  3.   

    或者用控制台来显示更清晰program Project3;{$APPTYPE CONSOLE}uses
      SysUtils;type
      TIntArray = array of Integer;procedure Calculate(var IntArray: TIntArray; N: Integer);
    var
      Index: Integer;
    begin
      SetLength(IntArray, Succ(N));
      if N < 1 then Exit;
      IntArray[Low(IntArray)] := 1;
      for Index := Succ(Low(IntArray)) to High(IntArray) do
      begin
        IntArray[Index] := IntArray[Pred(Index)]*Index;
      end;
    end;var
      IntArray: TIntArray;
      MyInt: Integer;
      Index: Integer;
    begin
      Index := 0;
      Calculate( IntArray, 10);
      for MyInt in IntArray do
      begin
        if Index > 0 then
         WriteLn(Format('%8d = %8d', [Index, MyInt]));
        Inc(Index);
      end;
      ReadLn;
    end.
      

  4.   


    type
      TIntArray = array of Integer;procedure Calculate(var IntArray: TIntArray; N: Integer);
    var
      Index: Integer;
    begin
      SetLength(IntArray, Succ(N));
      if N < 1 then Exit;
      IntArray[Low(IntArray)] := 1;
      for Index := Succ(Low(IntArray)) to High(IntArray) do
      begin
      IntArray[Index] := IntArray[Pred(Index)]*Index;
      end;
    end;
      

  5.   

    数学规律,跟编程本身没有什么关系的1  2  3  4   5    6      7      8
    1  2  6  24  120  120x6  720x7  5040x8