Skip to content

Instantly share code, notes, and snippets.

@nathabonfim59
Created August 11, 2020 10:45
Show Gist options
  • Select an option

  • Save nathabonfim59/76d6c8084271bf8525a0abfd72ad1d12 to your computer and use it in GitHub Desktop.

Select an option

Save nathabonfim59/76d6c8084271bf8525a0abfd72ad1d12 to your computer and use it in GitHub Desktop.

Revisions

  1. nathabonfim59 created this gist Aug 11, 2020.
    42 changes: 42 additions & 0 deletions P2_3bim_Alg.pas
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    program P2_3bim_Alg;

    // Achar a somatória de cada uma das colunas de uma matriz (5x10),
    // listando no final a somatória de todas as colunas.
    // Crie uma linha a mais e armazene dentro desta última linha a soma
    // das colunas.

    var
    matriz: array [1..6, 1..10] of integer;
    l, c, i: integer;

    begin
    // Popula a matriz com números sequenciais
    i := 1;

    for l := 1 to 5 do
    begin
    for c := 1 to 10 do
    begin
    matriz[l, c] := i;
    i := i + 1;

    // Inicializa com 0 a linha de soma das colunas
    matriz[6, c] := 0;
    end;
    end;

    // Computa a soma de cada coluna na última linha (6)
    for c := 1 to 10 do
    begin
    for l := 1 to 5 do
    begin
    matriz[6, c] := matriz[6, c] + matriz[l, c];
    end;
    end;

    // Exibe os resultados
    for c := 1 to 10 do
    begin
    writeln('Coluna ', c, ': ', matriz[6, c]);
    end
    end.