Results 1 to 4 of 4

Thread: ช่วยหน่อครับกับภาษาPascal

  1. #1
    Junior Member
    Join Date
    Aug 2007
    Posts
    8


    มีโจทย์มาดังนี้ครับ

    สร้าง Array แบบ 1 มิติ 20 ช่อง รับข้อมูลตัวเลข เสร็จแล้วให้หาว่า

    1. มีเลขคู่กี่จำนวน และเลขคี่กี่จำนวน

    2. ผลรวมของเลขคู่ และผลรวมของเลขคี่

    3. เลขคู่คิดเป็นกี่เปอร์เซนต์ของเลขคี่

    ยังไงก็ช่วยแนะนำหน่อยนะครับ :P

  2. #2
    Junior Member
    Join Date
    Oct 2006
    Posts
    13


    **Hidden Content: To see this hidden content your post count must be 5 or greater.**

  3. #3
    Junior Member
    Join Date
    Jun 2008
    Posts
    0


    เวนกำ ถามเพื่อนในห้องเรียนดีกว่าม่ะครับ

  4. #4
    Junior Member
    Join Date
    Aug 2008
    Posts
    4


    type
    TForm2 = class(TForm)
    edtCalc: TButton;
    Edit1: TEdit;
    procedure edtCalcClick(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    function FindPct( A , B :WORD):single;
    end;

    var
    Form2: TForm2;

    implementation

    {$R *.dfm}

    var
    Ary:Array[0..20-1] of Integer;
    A,B:WORD; // A = คู่ B = คี่
    A_zum,B_zum:integer;
    procedure TForm2.edtCalcClick(Sender: TObject);
    var
    I: Integer;
    begin
    A := 0; B := 0; A_zum := 0; B_zum := 0;
    for I := 0 to length(Ary) - 1 do
    begin
    if odd(Ary[I]) then
    begin
    //คี่
    B_zum := B_zum + Ary[I];
    inc( B );
    end
    else
    begin
    //คู่
    A_zum := A_zum + Ary[I];
    inc( A );
    end;
    end;
    Edit1.Text := FormatFloat(',##0.00',FindPct( A , B ));
    end;

    function TForm2.FindPct(A: Word; B: Word):single;
    begin
    result := (100* A )/( A + B );
    end;

    อันนี้เลยครับส่วนค่าใน Array ไปใส่เอาเองนะครับ

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •