BÀI TẬP 8: TÌM SỐ LỚN NHÌ TRONG DÃY SỐ

so lon nhi, pascal

Nhập vào dãy số nguyên gồm N phần tử. Viết chương trình tìm số lớn nhì trong dãy số vừa nhập

CODE THAM KHẢO:

program So_lon_nhi;

uses crt;

var i,max,nhi,n: integer;

    A: array[1..100] of integer;

begin

    clrscr;

    write('Nhap so phan tu N = '); readln(n);

    for i:=1 to n do

        begin

            write('A[',i,'] = ');

            readln(A[i]);

        end;

    max:=A[1]; nhi:=A[1];

    for i:=2 to n do

        begin

            if (A[i] > nhi) and (A[i] < max) then nhi:=A[i];

            if A[i] > max then

                begin

                    nhi:=max;

                    max:=A[i];

                end;

        end;

    writeln('So lon nhi la: ', nhi);

    readln;

end.



Nhãn:

Đăng nhận xét

Emoticon
:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

Biểu mẫu liên hệ

Tên

Email *

Thông báo *

Được tạo bởi Blogger.
Javascript DisablePlease Enable Javascript To See All Widget