Lương Thị Mộng | Chat Online
31/03/2024 09:01:23

Program CT_mangcon


Program CT_mangcon;
uses crt;
Var i,n,d,c,s,j:integer;
    A:array [1..100] of integer;
    f,g : text;
    max:longint;
    kt:boolean;
Begin
  clrscr;
  Assign(f, 'mangcon.inp');  Reset(f);
  Assign(g, 'mangcon.out');  Rewrite(g);
  Readln(f,n);
   For i:=1 to n do
     begin
     write('a[',i,']= ');
      Read(f,a[i]);
     end;
  Max:=low(longint);
  For i:=1 to n do
   Begin
     s:=a[i];
     For j:=i to n do
       Begin
         if i<>j then s:=s+a[j];
         if s>max then
           Begin
             max:=s;
             d:=i;
             c:=j;
           End;
        End;
    End;
     For i:=d to c do
       begin
        s:=a[i];
        for j:=i to n do
         Begin
          if i<>j then s:=s+a[j];
          if s>max then max:=s;
         end;
       end;
       kt:=true;
     For i:=d to c-1 do
       for j:=i+1 to c do
        if a[i]>a[j] then
        kt:=false;
       For i:=d to c do
         If kt then write(g,a[i],'  ');
          write(g,'tong con lon nhat va tang dan la: ',max);
   Close(g);
   close(f);
End.
* ĐÂY LÀ CODE MIK LÀM CHO BÀI TÍNH TỔNG MẢNG CON LỚN NHẤT VÀ TĂNG DẦN, MONG CÁC BẠN GIÚP MÌNH TÌM LỖI SAI Ạ VÌ CÓ 1 VÀI DÙNG CODE NÀY ĐƯỢC NHƯNG 1 SỐ KHÁC LẠI CHẠY SAI ĐÁP ÁN. MÌNH CẢM ƠN Ạ
Bài tập đã có 1 trả lời, xem 1 trả lời ... |
Đăng ký tài khoản để trả lời bài tập.
Đăng ký tài khoản để có thể trả lời bài tập này!

Đăng ký qua Google:

Hoặc lựa chọn:
Đăng ký bằng email, điện thoại Đăng nhập bằng email, điện thoại
Lazi.vn