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

tiểu luận ma trận

13 453 0

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 13
Dung lượng 49,5 KB

Nội dung

program ma_tran; uses crt; type km=array[1 10,1 10] of integer; kcs=1 10; var a:km; n:kcs; procedure nhapmt(ten:char; var a:km;n:kcs); var i,j:kcs; begin for i:=1 to n for j:=1 to n begin write(ten,'[',i,j,']= '); readln(a[i,j]); end; end; procedure inmt(a:km;n:kcs); var i,j:kcs; begin for i:=1 to n begin for j:=1 to n write(a[i,j]:4); writeln; end; end; procedure luumt(a:km;n:kcs); var i,j:kcs; s:string; f:text; begin write('Nhap ten File de luu: ');readln(s); assign(f,s); rewrite(f); for i:=1 to n begin for j:=1 to n write(f,a[i,j]:4); writeln(f); end; close(f); write('Ma tran vua duoc luu voi ten la: ',s); end; procedure chonmt(var a:km;n:kcs); var nhap,dau:1 3; chon:1 10; i,j:kcs; f:text; begin writeln('Hay chon cach nhap ma tran'); writeln('1 Nhap tu ban phim'); writeln('2 Nhap tu File text'); writeln('3 Nhap ngau nhien'); write('Chon: '); readln(nhap); case nhap of 1: nhapmt('A',a,n); 2: begin write('Hay lua chon File ma tran 10'); readln(chon); case chon of 1: begin assign(f,'mt1'); reset(f); for i:=1 to n for j:=1 to n read(f,a[i,j]); close(f); end; 2: begin assign(f,'mt2'); reset(f); for i:=1 to n for j:=1 to n read(f,a[i,j]); close(f); end; 3: begin assign(f,'mt3'); reset(f); for i:=1 to n for j:=1 to n read(f,a[i,j]); close(f); end; 4: begin assign(f,'mt4'); reset(f); for i:=1 to n for j:=1 to n read(f,a[i,j]); close(f); end; 5: begin assign(f,'mt5'); reset(f); for i:=1 to n for j:=1 to n read(f,a[i,j]); close(f); end; 6: begin assign(f,'mt6'); reset(f); for i:=1 to n for j:=1 to n read(f,a[i,j]); close(f); end; 7: begin assign(f,'mt7'); reset(f); for i:=1 to n for j:=1 to n read(f,a[i,j]); close(f); end; 8: begin assign(f,'mt8'); reset(f); for i:=1 to n for j:=1 to n read(f,a[i,j]); close(f); end; 9: begin assign(f,'mt9'); reset(f); for i:=1 to n for j:=1 to n read(f,a[i,j]); close(f); end; 10: begin assign(f,'mt10'); reset(f); for i:=1 to n for j:=1 to n read(f,a[i,j]); close(f); end; end; end; 3: begin randomize; for i:=1 to n for j:=1 to n begin dau:=random(3); if dau=0 then a[i,j]:=(0-random(9)) else a[i,j]:=random(9); end; end; end; end; procedure tongmt(a,b:km;var c:km;n:kcs); var i,j:kcs; begin for i:=1 to n for j:=1 to n c[i,j]:=a[i,j]+b[i,j]; end; procedure tichmt(a,b:km;var c:km;n:kcs); var i,j,k:kcs; begin for i:=1 to n for k:=1 to n begin c[i,k]:=0; for j:=1 to n c[i,k]:=a[i,j]*b[j,k]+c[i,k]; end; end; procedure mtcv(a:km;var b:km;n:kcs); var i,j:kcs; begin for i:=1 to n for j:=1 to n b[i,j]:=a[j,i]; end; procedure sapxepmt(var a:km;n:kcs); var i,j,k:kcs; chon:1 4; tg:1 100; begin writeln('1 Sap xep tang theo hang'); writeln('2 Sap xep giam theo hang'); writeln('3 Sap xep tang theo cot'); writeln('4 Sap xep giam theo cot'); write('Chon: ');readln(chon); case chon of 1: begin for i:=1 to n for j:=1 to (n-1) for k:=j to n if a[i,j]>a[i,k] then begin tg:=a[i,j]; a[i,j]:=a[i,k]; a[i,k]:=tg; end; end; 2: begin for i:=1 to n for j:=1 to (n-1) for k:=j to n if a[i,j]a[k,j] then begin tg:=a[i,j]; a[i,j]:=a[k,j]; a[k,j]:=tg; end; end; 4: begin for i:=1 to (n-1) for j:=1 to n for k:=i to n if a[i,j](n-x+1)) or (m>(n-y+1)) then write('Khong the copy tu phan tu nay! Nhap lai a['); until ((mn then write('m phai [...]... writeln('CHUONG TRINH MA TRAN TAM GIAC'); writeln; write('Chon cap cua ma tran, n= ');readln(n); writeln;writeln; chonmt(a,n); writeln; writeln( 'Ma tran vua nhap la:'); writeln;writeln; inmt(a,n); writeln; write('Nhan phim ENTER de sap xep ma tran tam giac'); readln; writeln('1 Ma tran tam giac tren'); writeln('2 Ma tran tam giac duoi'); write('Chon '); readln(chon); case chon of 1: begin writeln( 'Ma tran tam... writeln; end; write('Nhan phim l de luu ma tran nay'); if readkey=#108 then begin write('Nhap ten File muon luu: '); readln(s); if length(s)0 then begin assign(f,s); rewrite(f); for i:=1 to n do begin for j:=1 to n do; if ij then write(f,a[i,j]) else write(f,s); end; writeln(f); close(f); end; write( 'Ma tran da duoc luu voi ten: ',s); end; end; end; writeln;writeln;writeln; ... TINH TONG MA TRAN' ); write('Chon cap cua ma tran: n= '); readln(n); writeln('Chon ma tran thu nhat'); chonmt(a,n); writeln; writeln('Chon ma tran thu hai'); chonmt(b,n); writeln('Hai ma tran vua... TICH MA TRAN' ); writeln; write('Chon cap cua ma tran: n= '); readln(n); writeln('Chon ma tran thu nhat'); chonmt(a,n); writeln; writeln('Chon ma tran thu hai'); chonmt(b,n); writeln; writeln('2 ma. .. clrscr; writeln('CHUONG TRINH MA TRAN CHUYEN VI'); writeln; write('Chon cap cua ma tran, n= '); readln(n); writeln('Chon ma tran' ); chonmt(a,n); writeln; writeln; writeln( 'Ma tran vua nhap la:'); writeln;

Ngày đăng: 30/12/2015, 18:42

TỪ KHÓA LIÊN QUAN

w