Chèn phần tử, xóa phần tử trong mảng một chiều Pascal

Chèn phần tử, xóa phần tử trong mảng một chiều Pascal

Viết chương trình nhập mảng gồm n (n<=100) phần tử rồi chèn vào một số bất kỳ vào một vị trí nào đó trong mảng, số cần chèn và vị trí chèn nhập từ bàn phím.

Program Chen;

Uses crt;

Var i,spt, so,vitri: Integer;

A: Array[1..100] Of Integer;

Begin

    Clrscr;

    Writeln(' + CHEN MOT SO VAO MANG +');

    Writeln('-------------------------------');

    Write('-Co bao nhieu phan tu-: ');

    Readln(spt);

    For i:=1 To spt Do

      Begin

        Write('-Phan tu A[',i,']= '); Readln(a[i]);

      End;

    Writeln; Writeln('--MANG TRUOC KHI CHEN--');

    For i:=1 To spt Do Write(a[i]: 6); Writeln;

    Write('-Can che so: ');

    Readln(so); Write('-Vao vi tri: ');

    Readln(vitri);

    For i:=spt+1 Downto Vitri+1 Do    Writeln;

    a[i]:=a[i-1]; a[vitri]:=so; spt:=spt+ 1;

    Writeln('MANG SAU KHI CHEN');

    Readln;

    For i:=1 To spt Do Write(a[i]: 6);

End.

Viết chương trình nhập mảng gồm n (n<=100)phần tử rồi xóa đi một phần tử nào đó có vị trí nhập từ bàn phím

Program Xoa_Pt;

Var i,spt,vitri: Integer;

a: Array[1..100] Of Integer;

Begin

Writeln('--XOA PHAN TU TRONG MANG--');

Writeln('------------------------------------------------------');

Writeln;

Write('-Mang co bo nhieu phan tu- ');

Readln(spt);

For i:=1 To spt Do

Begin

Write('-Phan tu A[',i: 2,']= ');

Readln(A[i]);

End;

Writeln;

Writeln(' --MANG TRUOC KHI XOA--');

Writeln('--------------------------------------------------------');

Writeln;

For i:=1 To spt Do Write(a[i]: 6);

Writeln;

Writeln;

Write('-Vi tri muon xoa: '); Readln(vitri);

For i:=vitri to spt - 1 Do a[i]:=a[i+1];

spt:=spt - 1;

Writeln;

Writeln(' MANG SAU KHI XOA');

Writeln('- -----------------------------------');

Writeln;

For i:=1 to spt Do Write(a[i]: 6);

Writeln; Writeln;

Writeln(' Bam phim  de ket thuc ');

Readln

End.

Viết chương trình nhập mảng gồm n (n<=100)phần tử rồi xóa đi những phần tử trùng nhau trong mảng và in ra màn hình phần tử sau khi đã bỏ bớt.

Program Bo_so_trung;

Uses crt;

Const Max=100;

Var A: Array[1..Max] Of Integer;

i,j,k,n: Integer;

Begin

Writeln('XOA BO CAC SO TRUNG NHAU');

Writeln('-----------------------------------------------');

Writeln;

Write('-Nhap so phan tu mang: '); Readln(n);

For i:=1 To N Do

Begin

Write('-Phan tu A[',i,']= ');

Readln(a[i]);

End;

i:=2;

While i <= N Do

Begin

j:=1;

While a[j] <> a[i] Do

j:=j+1;

If j < i Then

Begin

For k:=i to n-1 Do

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

n:=n-1;

End

Else

i:=i+1;

End;

Writeln;

Write('-Mang con lai: ');

For i:=1 to n Do Write(a[i]: 8);

Writeln;

Writeln(' Bam phim  de ket thuc ');

Readln

End.

 

Bạn thấy bài viết này như thế nào?: 
Average: 7.9 (8 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
7 Chi tiết cần được pin đầu trang Timeline [Facebook Page]

7 Chi tiết cần được pin đầu trang Timeline [Facebook Page]

Một trong những tính năng thông minh nhất của Timeline dành cho thương hiệu, đó là Pin.

24 suy nghĩ cần thiết về Drupal 8 trong 2016

24 suy nghĩ cần thiết về Drupal 8 trong 2016

John Ennew, Drupal 8 contributor and Deeson technical lead has collected together the questions we’ve been receiving from clients about Drupal 8 into one handy list.

Sony Ericsson Xperia Play Review

Sony Ericsson Xperia Play Review

Sony Ericsson puts a new wave on conventional smartphone features especially for gaming enthusiasts – the Sony Ericsson Xperia Play. It is the first-ever PlayStation phone in the Android world.

Công ty diệt chuột T&C

 

Diet con trung