Tin học Viết chương trình nhập vào 1 mảng: a) Sau đó sắp xếp theo thứ tự tăng dần b) Chèn số vào mảng nhưng vẫn đảm bảo theo thứ tự tặng dần 23/07/2021 By Everleigh Viết chương trình nhập vào 1 mảng: a) Sau đó sắp xếp theo thứ tự tăng dần b) Chèn số vào mảng nhưng vẫn đảm bảo theo thứ tự tặng dần
uses crt;var i,j,t,n,k:longint; a:array[0..100000]of longint;beginclrscr; writeln(‘Nhap vao mang:’); write(‘n=’);readln(n); for i:=1 to n do begin write(‘a[‘,i,’]=’);readln(A[i]); end; for i:=1 to n do for j:=1 to i do if a[i]<a[j] then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; end; write(‘a) Mang theo thu tu tang dan: ‘); for i:=1 to n do write(a[i],’ ‘); writeln; write(‘b) Nhap so de chen: ‘);readln(k); a[n+1]:=k; for i:=1 to n+1 do for j:=1 to i do if a[i]<a[j] then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; end; for i:=1 to n+1 do write(a[i],’ ‘);readlnend. Trả lời
program tangdan; uses crt; var A:array[1..101] of integer; n,i,j,tg,m:integer; begin clrscr; write(‘Nhap so luong phan tu : ‘); readln(n); for i:=1 to n do begin write(‘Phan tu 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; write(‘Mang tang dan la: ‘); for i:=1 to n do write(A[i],’ ‘); writeln; write(‘Nhap gia tri can chen: ‘); readln(m); i:=1; while A[i]<m do i:=i+1; for j:=n+1 downto i+1 do A[j]:=A[j-1]; A[i]:=m write(‘Day sau khi chen la: ‘); for i:=1 to n+1 do write(A[i],’ ‘); readln; end. Trả lời