Nhập vào một mảng A in ra màn hình theo thứ tự tăng dần và giảm dần

Nhập vào một mảng A in ra màn hình theo thứ tự tăng dần và giảm dần

0 bình luận về “Nhập vào một mảng A in ra màn hình theo thứ tự tăng dần và giảm dần”

  1. program sx;

    uses crt;

    var a: array[1..100] of integer;

          n,i,j,tam: integer;

    begin

    clrscr;

    readln(n);

    for i:=1 to n do readln(a[i]);

    for i:=1 to n-1 do

     for j:=i+1 to n do

      if(a[i]<a[j]) then

       begin

       tam=a[i];

       a[i]=a[j];

       a[j]=tam;

       end;

     write(a[i],’ ‘);

    for i:=1 to n-1 do

     for j:=i+1 to n do

      if(a[i]>a[j]) then

       begin

       tam=a[i];

       a[i]=a[j];

       a[j]=tam;

       end;

     write(a[i],’ ‘);

    readln

    end.

             

         

    Bình luận
  2. program ct;

    ues crt;

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

          i,j,l,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(‘Mang sap xep theo thu tu tang dan la: ‘);

       for i:=1 to n do

         write(A[i]:3);

       for i:=1 to n-1 do

       for l:=i+1 to n do

         if A[i]<A[l] then

            begin

               tg:=A[i];

               A[i]:=A[l];

               A[l]:=tg;

            end;

       writeln(‘Mang sap xep theo thu tu giam dan la: ‘);

       for i:=1 to n do

         write(A[i]:3);

    readln;

    end.

    Học tốt!

    Bình luận

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