1. Trang chủ
  2. » Luận Văn - Báo Cáo

Bai tap hayphan mang

4 3 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 4
Dung lượng 42 KB

Nội dung

[r]

(1)

************chèn them pt vào mảng**************** program chenso;

uses crt;

var n,i,vtri,so:integer; A:array[1 50]of integer; begin

write('nhap so pt mang:');readln(n); for i:=1 to n

begin

write('nhap a[',i,']='); readln(a[i]); end;

write('mang chua chen la: '); for i:=1 to n write(a[i]:6); writeln;

write('nhap vitri va so can chen');readln(vtri,so); for i:=n+1 downto vtri+1

a[i]:=a[i-1]; a[vtri]:=so;

write('mang sau chen: '); for i:=1 to n+1

write(a[i]:6); readln end

****************xoá pt mảng************* uses crt;

var a,b,c:array[1 100]of integer; x,k,n,i,j:integer;

begin clrscr;

writeln('nhap so pt:');readln(n); for i:=1 to n

begin

write('a[',i,']=');readln(a[i]); end;

for i:=1 to n write(a[i]:5); writeln;

{them pt vao mang}

write('nhap vi tri can them');readln(j); write('nhap gia tri can them');readln(x); for i:=1 to n+1

(2)

begin

for k:=j+1 to n+1 b[k]:=a[k-1]; b[j]:=x;

i:=n+1; end;

for i:=1 to n+1 write(b[i]:5);writeln; readln

end

hoặc:

program xoaso; uses crt;

var i,n,vtri:integer;

a:array[1 20]of integer; begin

write('nhap so pt mang');readln(n); for i:=1 to n

begin

write('nhap a[',i,']=');readln(a[i]); end;

write('mang chua xoa: '); for i:=1 to n write(a[i]:6);

write('vi tri muon xoa:');readln(vtri); for i:=vtri to n-1

a[i]:=a[i+1];

write('mang sau xoa: '); for i:= to n-1 write(a[i]:6); readln

end

**************sap xep*************** program sapxep;

uses crt;

var n,i,j,tam:integer; a:array[1 2]of integer; begin

write('nhap so pt:');readln(n); for i:=1 to n

begin

write('nhap A[',i,']=');readln(a[i]); end;

(3)

for i:=1 to n-1

for j:=i+1 to n if a[i]>a[j] then

begin

tam:=a[i]; a[i]:=a[j]; a[j]:=tam; end;

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

end hoặc

program sapxep; uses crt;

var n,i,j,tam:integer; a:array[1 2]of integer; begin

write('nhap so pt:');readln(n); for i:=1 to n

begin

write('nhap A[',i,']=');readln(a[i]); end;

writeln;

for j:=n downto for i:=1 to j-1 if a[i]>a[i+1] then begin

tam:=a[i]; a[i]:=a[i+1]; a[i+1]:=tam; end;

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

end

******************tim ky tự*************** program kitu;

uses crt;

var n,i,dem:integer;y:char; a:array[1 50]of char; begin

(4)

for i:=1 to n begin

write('[a',i,']=');readln(a[i]); end;

dem:=0;

write('ki tu muon tim: ');readln(y); for i:=1 to n

if a[i]=y then dem:=dem+1;

if dem=0 then write('ko co pt ',y,' nao') else write('so pt tu ',y,' la:',dem); readln

end

***************tbc sai so***************** rogram tbcsaiso;

uses crt;

var n,i:integer;tbc,tong:real; a:array[1 20]of real; begin

write('nhap so pt mang:');readln(n); tong:=0;

for i:=1 to n begin

write('nhap a[',i,']=');readln(a[i]);tong:=tong+a[i]; end;

tbc:=tong/n; write('tbc=',tbc:5); writeln;

write('nhung pt sai so la:'); for i:=1 to n

if abs(tbc-a[i])<1 then write(a[i]:6) ; readln

Ngày đăng: 02/05/2021, 05:50

w