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

 
Hướng dẫn Customizing Views với Context

Hướng dẫn Customizing Views với Context

At certain scales, the ability of views to provide multiple block or page displays can become a hindrance to the performance of the UI. I recently tackled a problem with a view that contained 45 nearly identical displays and was growing

Thảo luận về Search API và Apache Solr operating trong Drupal 7

Thảo luận về Search API và Apache Solr operating trong Drupal 7

In this article we will duscuss how  to configure the module Search API and Search API Solr search quickly, and how to display the data from Solr server with the help of the module Views.

How to batch assign taxonomy terms to nodes using Views Bulk Operations

Hướng dẫn gắn taxonomy terms to nodes sử dụng Views Bulk Operations

First off, make sure you have the 2 modules installed. Drush will quickly take care of that for you if you don't have them yet:

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

 

Diet con trung