Xây dựng menu sắp xếp mảng không giảm, số nguyên tố trong Pascal

Xây dựng menu sắp xếp mảng không giảm, số nguyên tố trong Pascal

Nhập vào mảng có n giá trị n<=100, dếm số lần xuất hiện của các phần tử trong mảng.

>>Tính x^n với n là số nguyên không âm trong Pascal

>>Viết phương trình pascal tìm số tự nguyên lớn nhất và in ra màn hình

Đầu tiên sắp xếp trước rồi sau đó đếm các phần tử giống nhau.

Program Dem_so_lan_xuat_hien_trong_mang;
Uses CRT;
    Var i,j,n,dem:byte;
            tam:integer;
        a: Array [1..100] of integer;
Begin
    Clrscr;
    write('Nhap so pt:');readln(n);
    For i:=1 to n do Begin  write('A[',i,']=');readln(a[i]); End;
    For i:=1 to n-1 do {Sap xep A tang dan}
      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;
        i:=1;
        While i<=n do  {duyet qua mang}
         Begin
           Write(a[i],' xuat hien ');
           dem:=1;
           While a[i]=a[i+1] do begin inc(dem); inc(i); end; {Dem pt trung}
           inc(i); Writeln(dem,' lan');
         End;
    Readln
End.

Viết chương trình nhập mảng gồm n phần tử kiểu nguyên(n<=100) và cho ra màn hình phần tử xuât hiện nhiều nhất và số lần xuât hiện của nó trong mảng

Program Tansuat;
Uses crt;
var i,k,j,n,max:integer;
b,st: array [1..100] of integer;
begin
    clrscr;
        write('Nhap so pt:');readln(n);
        for i:=1 to n do
    Begin
        write('st[',i,']=');readln(st[i]);
    End;
        b[i]:=0;
        for i:=1 to n do
            for j:=i to n do
                if st[i]=st[j]then inc(b[i]);
                max:=b[1];
                for i:=1 to n do if b[i]>max then max:=b[i];
                    write('--So xuat hien nhieu nhat la--');
                for i:=1 to n do
                    if max=b[i]then write(st[i],' ');
    write('---xuat hien--- ',max,' –lan--');
    Readln
End.

Viết chương trình nhập vào mảng gồm n phần tử (n<=100) tìm và hiển thị vị trí phần tử có giá trị lớn nhât, sau đó sắp xếp các phần tử theo thứ tự tăng dần và hiển thị các phần tử sắp xếp đó ra màn hình.

Program Tim_vi_tri;
Uses crt;
var a: array[1..100] of integer;
var i,n,j, tg,max, vt: integer;
begin
    clrscr;
    write(' nhap so phan tu cua mang ');
    readln(n);
    writeln(' moi nhap cac phan tu cua mang ');
        for i:=1 to n do
            begin
                write('A', i,']= ');
                readln(a[i]);
            end;
    Max:=a[1]; vt:=1;
        For i:=1 to n do
        begin
            If A[i]>max then
            Begin
                Max:=a[i]; vt:=i;
            End;
        End;
    Writeln('gia tri lon nhat la ', max, ' nam o vi tri thu ',vt);
    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(' day sau khi sap xep la ');
        for i:=1 to n do    
        write( a[i]: 4);
    readln;
End.

Viết chương trình nhập vào một mảng gồm N số nguyên. Sắp xếp lại mảng theo thứ tự tăng dần (không giảm) và in kết quả ra màn hình.

Uses Crt;
Type Mang = ARRAY[1..50] Of Integer;
Var A:Mang;
N,i,j,Tam:Integer;
    Begin
    {Nhập mảng}
        Write('Nhap N='); Readln(N);
        For i:=1 To N Do
        Begin
            Write('A[',i,']='); Readln(A[i]);
        End;
    {Sắp xếp}
        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;
    {In kết quả ra màn hình}
    Writeln('Ket qua sau khi sap xep:');
        For i:=1 To N Do Write(A[i]:5);
    Readln;
End.

Viết chương trình nhập vào một mảng gồm N số nguyên. Sắp xếp lại mảng theo thứ tự giảm dần và in kết quả ra màn hình.

Uses Crt;
Type Mang = ARRAY[1..50] Of Integer;
Var A:Mang;
N,i,j,Tam:Integer;
Begin
    {Nhập mảng}
    Write('Nhap N='); Readln(N);
    For i:=1 To N Do
        Begin
            Write('A[',i,']='); Readln(A[i]);
        End;
    {Sắp xếp}
    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;
    {In kết quả ra màn hình}
    Writeln('Ket qua sau khi sap xep:');
        For i:=1 To N Do Write(A[i]:5);
    Readln;
End.
Bạn thấy bài viết này như thế nào?: 
Average: 9.9 (104 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

 
Hướng dẫn cách đóng góp Translations cho Drupal Projects

Hướng dẫn cách đóng góp Translations cho Drupal Projects

Learn how you can help with translation on Drupal.org from Drupalize.me's Amber Matz.

Drupal 8 Module Development: Phần 2 - tạo Forms

Drupal 8 Module Development: Phần 2 - tạo Forms

Like all Drupal 8 module development, creating forms isn't quite as straight forward as it has been in the past using the hook system.

Hướng dẫn tạo 1 field Autocomplete bằng cách dùng the Drupal 8 Form API

Hướng dẫn tạo 1 field Autocomplete bằng cách dùng the Drupal 8 Form API

In this article, I will not explain how to customise/alter an Autocomplete Field Widget — which should only be used on from using the Drupal Admin UI.

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

 

Diet con trung