Viết chương trình pascal nhập vào MMC gồm N phần tử nguyên. Hãy tìm và in ra phần tử lớn nhất trong mảng vừa nhập

Viết chương trình pascal nhập vào MMC gồm N phần tử nguyên. Hãy tìm và in ra phần tử lớn nhất trong mảng vừa nhập

0 bình luận về “Viết chương trình pascal nhập vào MMC gồm N phần tử nguyên. Hãy tìm và in ra phần tử lớn nhất trong mảng vừa nhập”

  1. Var a:array[1..100] of integer;

          i,n,max:integer;

          begin

            write(‘nhap so phan tu cua mang:’);readln(n);

            for i:=1 to n do

            begin

              write(‘a[‘,i,’]=’);readln(a[i]);

             end;

             max:=a[1];  

             for i:=2 to n do

             if a[i]>max then max:=a[i];

             writeln(‘phan tu lon nhat:’,max);

          readln

          end.           

    Bình luận
  2. $\color{green}{\text{Program BTT;}}$ 
    $\color{red}{\text{Uses crt;}}$ 

    $\color{blue}{\text{Var A: array[1..1000] of longint;}}$ 

    $\color{yellow}{\text{n,i,max: longint;}}$ 

    $\color{green}{\text{Begin}}$ 

    $\color{red}{\text{        Clrscr;}}$ 

    $\color{yellow}{\text{        Write(‘Nhap n: ‘); Readln(n);}}$ 
    $\color{red}{\text{        max:=0;}}$ 

    $\color{blue}{\text{         For i:=1 to n do}}$ 

    $\color{green}{\text{        Begin}}$ 

    $\color{pink}{\text{                Write(‘A[‘,i,’] = ‘);}}$ 

    $\color{blue}{\text{                Readln(A[i]);}}$ 

    $\color{red}{\text{                If A[i]>max then max:=A[i];}}$ 

    $\color{green}{\text{        End;}}$ 

    $\color{blue}{\text{        Write(‘Max = ‘,max);}}$ 

    $\color{yellow}{\text{       Readln}}$

    $\color{blue}{\text{End.}}$

    Bình luận

Viết một bình luận