Pascal/Turbo Pascal - EJERCICIO PASCAL

 
Vista:

EJERCICIO PASCAL

Publicado por David (1 intervención) el 22/04/2013 16:54:30
Buenas tardes,
Que hago mal en este ejercicio?
ENUNCIADO
Escribe un programa que declare un tipo de matriz de enteros de 4x3 y un tipo vector de
3 enteros. El programa deberá leer la matriz mediante un StringGrid y, a continuación,
sumar cada columna de la matriz por separado y guardar la suma de cada columna en
un elemento de un vector, que visualizará en otro StringGrid.
SOLUCIÓN
unit Unit1;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{$mode objfpc}{$H+}
 
interface
 
uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
  StdCtrls;
 
type
 
  { TForm1 }
 
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Matriu1: TStringGrid;
    Matriu2: TStringGrid;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Label1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.lfm}
 
{ TForm1 }
 
const
  F=3;
  C=2;
  N=2;
type
  TTabla = array[0..F, 0..C] of integer;
  TVector = array[0..N] of integer;
 
procedure TForm1.Label1Click(Sender: TObject);
begin
 
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  m1:TTabla;
  VectorSuma:TVector;
  i,j,contador:integer;
begin
for j:=0 to C do
  for i:=0 to F do
        m1[i,j]:=StrToInt(Matriu1.Cells[j,i]);
      if j=0 then
        begin
        contador:=0;
        VectorSuma[j]:= contador+m1[i,j];
        end;
      if j=1 then
        begin
        contador:=0;
        VectorSuma[j]:= contador+m1[i,j];
        end;
      if j=2 then
        begin
        contador:=0;
        VectorSuma[j]:= contador+m1[i,j];
        end;
      for j:=0 to C do
     Matriu2.Cells[j,0]:=IntToStr(VectorSuma[j]);
    end;
  end.


Gracias! :)
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

EJERCICIO PASCAL

Publicado por Javi (1 intervención) el 22/04/2013 16:56:04
Gracias por su aporte compañero!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar