Pascal - Tìm số lớn thứ nhì trong n số được nhập từ bàn phím

Pascal - Tìm số lớn thứ nhì trong n số được nhập từ bàn phím

Tìm số lớn thứ nhì trong n số được nhập từ bàn phím.

Ví dụ: Nhập các sô 10; 10; 9; 9; 8 thì được số lớn nhì là 9.

Giải thuật:

  • Nhập 2 số, Xác định giá trị cho hai biến Max, Nhi.
  • Lần lượt nhâp các số. Với mỗi số được nhập xét:
    • Nếu So > Max thì gán Nhi = Max, Max = So.
    • Nếu Nhi < So < Max thì gán Nhi = So.

Cài đặt

Program So_lon_nhi;

Var n,i,so, nhi,max,tam:integer;

Procedure swap(var x,y:real);

var tam:real;

begin

tam:=x;

x:=y;

y:=tam;

end;

Begin

    Write('Nhap n: ');Readln(n);

    Write('nhap so:');Readln(max);

    Write('nhap so: ');Readln(nhi);

    if nhi > Max then swap(Max,nhi)

    For i:= 3 to n do

    Begin

         Write('Nhap so: ');Readln(so);

         if (so>nhi) and (so<max) then nhi:=so;

         if so>max then

         Begin

            nhi:=max;

            Max:=so;

         End;

    End;

    Write('So thu nhi la: ',nhi);

    Readln

End.
Bạn thấy bài viết này như thế nào?: 
Average: 9 (60 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Những checklist cần thiết để Going live Drupal

Những checklist Drupal cần thiết để Going live

So you're launching a new website or replacing an old one and want to make sure everything goes smoothly? This guide will give you a run-down of everything you can check to avoid common pitfalls!

Disappointing iPhone: Android Device Set to Gain

Disappointing iPhone: Android Device Set to Gain

Asian smartphone makers have a chance to exploit a rare letdown from pacesetter Apple Inc. after the new iPhone 4S failed to wow fans and investors, leaving Android rivals better placed to grab market share.

Sự khác nhau Route, Path, URL, URI, Link, Menu item trong Drupal 8

Sự khác nhau Route, Path, URL, URI, Link, Menu item trong Drupal 8

A nice article from KatteKrab (Donna Benjamin) covering terms in the Drupal context. These kinds of post are very handy indeed.

Công ty diệt chuột T&C

 

Diet con trung