Nhập vào 1 mảng số nguyên gồm n phần tử, sắp xếp mảng đó theo thứ tự tăng dần.

Nhập vào 1 mảng số nguyên gồm n phần tử, sắp xếp mảng đó theo thứ tự tăng dần.

0 bình luận về “Nhập vào 1 mảng số nguyên gồm n phần tử, sắp xếp mảng đó theo thứ tự tăng dần.”

  1. program ct;

    ues crt;

    var A:array [1..1000] of integer;

          i,j,n,tg:integer;

    begin clrscr;

       write(‘Nhap so phan tu n: ‘); readln(n);

       for i:=1 to n do

         begin

            writeln(‘Nhap so thu ‘,i,’: ‘); readln(A[i]);

         end;

       for i:=1 to n-1 do

       for j:=i+1 to n do

         if A[i]>A[j] then

            begin

               tg:=A[i];

               A[i]:=A[j];

               A[j]:=tg;

            end;

       writeln(‘Day so sap xep theo thu tu tang dan la: ‘);

       for i:=1 to n do

         write(A[i]:3);

    readln;

    end.

    Học tốt!

    Bình luận
  2. program ct;

    uses crt;

    var i,n,j,tam:integer;

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

    begin

    clrscr;

    write(‘nhap n:=’);readln(n);

    for i:=1 to n do

    begin

    write(‘nhap mang A[‘,i,’]:=’);readln(A[i]);

    end;

    for i:=1 to n-1 do

    for j:=i+1 to n do

       A[i]>A[j] then

    begin

    tam:=A[i];

    A[i]:=A[j];

    A[j]:=tam;

    end;

    writeln;

    write(‘day so sau khi sap xep la:’);

    for i:=1 to n do

    write(A[i]:4);

    readln

    end.

    Bình luận

Viết một bình luận