Pascal/Turbo Pascal - Ayuda xfa con este procedimiento en Pascal

 
Vista:
sin imagen de perfil

Ayuda xfa con este procedimiento en Pascal

Publicado por Rosario (5 intervenciones) el 20/11/2014 19:27:26
Por favor me ayudan con este problema:
Tengo que diseñar un procedimiento que dado un dígito d [1..9] muestre por pantalla el siguiente renglón:

1 2 3 .. d .. 3 2 1

Por ejemplo, si d = 6 el procedimiento deberá imprimir:

1 2 3 4 5 6 5 4 3 2 1

El encabezado del procedimiento sería:

PROCEDURE ImprimeRenglon (digito: integer);

{Objetivo: Imprime un renglón de la forma 1 2 3 .. d .. 3 2 1 donde d es un dígito de 0 a 9}
Escriba un programa en Pascal utilizando dicho procedimiento, que solicite un dígito d al usuario, y muestre por pantalla una figura como la siguiente:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
...
...
1 2 3 .....d..... 3 2 1




__ Tambien tengo que diseñar un programa modularizado que permita realizar las siguientes operaciones con dos matrices de NxN.

a.- Sumar matrices
b.- Obtener el valor máximo de una matriz (El valor más grande)
c.- Obtener el valor mínimo de una matriz (El valor más chico)
d.- Obtener la cantidad de números positivos, negativos y ceros que tiene la matriz
e.- Obtener la cantidad de números pares y la cantidad de impares que tiene la matriz.

Muchisimas Gracias¡¡¡ al que me conteste¡¡ :)
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
sin imagen de perfil

Ayuda xfa con este procedimiento en Pascal

Publicado por Rene Gar (58 intervenciones) el 21/11/2014 05:28:55
Buenas compañero te dejo mi version del programa esta tanto el primer metodo como la del las matrices
no retorne el valor de ninguna funcion porque no me dio ganas pero lo puedes implementar a tu gusto y necesidades

Eso si recuerda practicar porque el programa es relativamente sencillo y no tiene ninguna complicacion

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
type
 TArrayint=array of array of integer;
 
procedure imprimirRenglon(digito:integer); //imprimir los valores ejemplo:123454321
var
i:integer;
begin
   for i:=1 to digito do write(i,' ');
   for i:=digito-1 downto 1 do write(i,' ');
end;
 
//--------------------------------------------------------------------------------------------------
procedure sumarDosMatices(matriz1,matriz2:TArrayint); //funcion para sumar dos matrices de NXN
var
i,j:integer;
NewMatriz:TArrayint;
indice,subIndice:integeR;
begin
  if (high(matriz1)= high(matriz2)) and (high(matriz1[0])= high(matriz2[0])) then  //SI DOS MATRICES NO SON IGUALES NO ENTRA
  begin
   indice:=high(matriz1)+1; subindice:=high(matriz1[1])+1;
   setlength(NewMatriz,indice,subindice); //crear una matriz dinamica del tamano de las matrices
 
   for i:=0 to high(matriz1) do
   begin
      for j:=0 to high(matriz1[i]) do
      begin
        NewMatriz[i,j]:=matriz1[i,j]+matriz2[i,j]; //VA SUMANDO LAS DOS MATRICES
        write(NewMatriz[i,j],' ');
      end;
   end;
  end
  else
    writeln('Las matrices no son del mismo tamano');
end;
 
 
procedure MaximoValorMatriz(matriz:TArrayint);
var
i,max,j:integeR;
begin
   max:=matriz[0,0];
   for I :=0 to High(matriz) do
   begin
     for j :=0 to High(matriz[i]) do
     begin
        if matriz[i,j]>max then
            max:=matriz[i,j];
     end;
   end;
 
   writeln('el valor maximo de la matriz es ',max);
end;
 
procedure MinimoValorMatriz(matriz:TArrayint);
var
i,min,j:integeR;
begin
   min:=matriz[0,0];
   for I :=0 to High(matriz) do
   begin
     for j :=0 to High(matriz[i]) do
     begin
        if matriz[i,j]<min then
            min:=matriz[i,j];
     end;
   end;
 
   writeln('el valor minimo de la matriz es ',min);
end;
 
procedure ceros_positivos_negativos(matriz:TArrayint);
var
i,ceros,positivos,negativos,j:integeR;
begin
   ceros:=0; positivos:=0; negativos:=0;
   for I :=0 to High(matriz) do
   begin
     for j :=0 to High(matriz[i]) do
     begin
        if matriz[i,j]>0 then
           inc(positivos)
        else if  matriz[i,j]=0 then
           inc(ceros)
        else
          inc(negativos);
      end;
   end;
 
   writeln('Existen ',ceros,' ceros ,',negativos,' negativos y ',positivos,' positivos');
end;
 
procedure ParesEimpares(matriz:TArrayint);
var
i,j:integer;
pares,impares:integer;
begin
   pares:=0; impares:=0;
 
   for I :=0 to High(matriz) do
   begin
     for j :=0 to High(matriz[i]) do
     begin
        if matriz[i,j] mod 2=0 then
            inc(pares)
        else
          inc(impares);
     end;
   end;
 
   writeln('Existen ',pares,' numeros pares y ',impares,' numeros impares');
end;
 
 //AQUI TERMINAN LOS METODOS O FUNCIONES DEL PROGRAMA
//-----------------------------------------------------------------------------------------------------------
//AQUI INICIA EL PROGRAMA PRINCIPAL QUE LLAMA A LOS METODOS O FUNCIONES
var
i,j:integer;
arr1,arr2:TArrayint;
begin
    SetLength(arr1,5,2);//crear dos matrices dinamicas
    //las cuales las sumaremos con el metodo creado
    SetLength(arr2,5,2);
    randomize;
 
    if (high(arr1)= high(arr2)) and (high(arr1[0])= high(arr2[0])) then
    begin //este troco de codigo rellena dos matrices con valore aleatorios
    for i:=low(arr1) to high(arr1) do
    begin
      for j:=low(arr1[i]) to high(arr1[i]) do
      begin
         arr1[i,j]:=random(20)+10*-1;//genera valores aletorios y los asginar a las matrices
         arr2[i,j]:=random(50)+100*-1;
         writeln(arr1[i,j],'  ',arr2[i,j]); //imprime los valores generados aleatorios
      end;
    end;
    end
    else writeln('Las matrices no son del mismo tamano asi que no puede generar numero aleatorio');
 
    writeln;
    sumarDosMatices(arr1,arr2); //llama a la funcion parar sumar dos matrices de NXN
    writeln;
    MaximoValorMatriz(arr1);  //se llama al metodo y se le pasa la matriz 1
    MinimoValorMatriz(arr1);  //se llama al metodo y se le pasa la matriz 1
    ceros_positivos_negativos(arr1); //se llama al metodo y se le pasa la matriz 1
    ParesEimpares(arr1); //se llama al metodo y se le pasa la matriz 1
 
 //----------------------------------------------------------------------
 
   imprimirRenglon(11);//llama al primer metodo de imprimir el renglon de numeros
 
    readln;
end.

comente el codigo y deje ejemplo de su uso saludos...
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

Ayuda xfa con este procedimiento en Pascal

Publicado por ramon (2158 intervenciones) el 23/11/2014 00:53:44
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
{Espero esto te sirva}
 
program digitos;
 uses
    crt;
  const
     nmt = 8;
  var
    dig : integer;
    matriz : array[1..nmt,1..nmt] of integer;
    x, y : integer;
 
 
  procedure entrada(var d : integer);
  begin
     clrscr;
     write('   Entre Digito [1.a.9] : ');
     readln(d);
  end;
 
  PROCEDURE ImprimeRenglon(digito : integer);
  var
    t : integer;
  begin
      write('   Resultado = ');
      for t := 1 to digito do
      write(t);
      for t := digito - 1 downto 1 do
      write(t);
  end;
 
 procedure figura(digito : integer);
 var
   t, k, g : integer;
   begin
      writeln('   Figura ');
      writeln;
      write('   ');
      for k := 1 to digito do
      begin
        for g := 1 to k do
        write(g);
        for t :=  g - 1 downto 1 do
        write(t);
        writeln;
        write('   ');
      end;
   end;
 
   procedure rellenamatriz;
   var
     q, vm : integer;
   begin
      q := 1;
      x := 1;
      y := 1;
      repeat
       vm := random(nmt * nmt);
       matriz[x,y] := vm;
       x := x + 1;
       if x > nmt then
       begin
          y := y + 1;
          x := 1;
       end;
       q := q + 1;
      until q > (nmt * nmt);
   end;
 
  procedure Sumar_matrices;
  var
     s, j : integer;
     resul : longint;
  begin
     resul := 0;
     for s := 1 to nmt do
       for j := 1 to nmt do
       resul := resul + matriz[j,s];
       write('  La Suma De La Matriz Es = ',resul);
  end;
 
 
 
  procedure valor_minimo_maximo;
  var
    minimo : array[1..nmt * nmt] of integer;
    c, r, h, temp : integer;
  begin
      c := 1;
      for r := 1 to nmt do
      begin
        for h := 1 to nmt do
        begin
        minimo[c] := matriz[h,r];
        c := c + 1;
        end;
      end;
      for r := 1 to (nmt * nmt) do
       for h := (nmt * nmt) downto r + 1 do
       if minimo[r] > minimo[h] then
       begin
           temp := minimo[r];
           minimo[r] := minimo[h];
           minimo[h] := temp;
       end;
  write('  El Minimo Es = ',minimo[1],'   El Maximo Es = ',minimo[nmt * nmt]);
  end;
 
  procedure numeros_positivos_negativos_y_ceros;
  var
     pos, neg, cer : integer;
  begin
     pos := 0;
     neg := 0;
     cer := 0;
     for y := 1 to nmt do
     begin
       for x := 1 to nmt do
       begin
       if matriz[x,y] > 0 then
       pos := pos + 1;
       if matriz[x,y] < 0 then
       neg := neg + 1;
       if matriz[x,y] = 0 then
       cer := cer + 1;
       end;
      end;
       write('  Positivos = ',pos,'   Negativos = ',neg,'   Ceros = ',cer);
  end;
 
  procedure numeros_pares_y_impares;
  var
     par, imp : integer;
  begin
     par := 0;
     imp := 0;
     for y := 1 to nmt do
       for x := 1 to nmt do
       if matriz[x,y] mod 2 = 0 then
       par := par + 1
     else
       imp := imp + 1;
       write('  Numeros Pares = ',par,'   Numeros Impares = ',imp);
  end;
 
 
  begin
     randomize;
     entrada(dig);
     writeln;
     ImprimeRenglon(dig);
     writeln;
     writeln;
     figura(dig);
     writeln;
     rellenamatriz;
     Sumar_matrices;
     writeln;
     writeln;
     valor_minimo_maximo;
     writeln;
     writeln;
     numeros_positivos_negativos_y_ceros;
     writeln;
     writeln;
     numeros_pares_y_impares;
     writeln;
     writeln;
     writeln('   La Matriz Es ');
     writeln;
     for y := 1 to nmt do
     begin
        for x := 1 to nmt do
        begin
          write('  ',matriz[x,y]);
        end;
           writeln;
           writeln;
     end;
     readkey;
  end.
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
sin imagen de perfil

Ayuda xfa con este procedimiento en Pascal

Publicado por Romina (5 intervenciones) el 02/12/2014 00:50:40
Gracias si me sirvio pero tengo que tener los 2 programas por separado y no los 2 unidos en un solo programa:


ESTE ES EL PRIMERO:
Tengo que diseñar un procedimiento que dado un dígito d [1..9] muestre por pantalla el siguiente renglón:

1 2 3 .. d .. 3 2 1

Por ejemplo, si d = 6 el procedimiento deberá imprimir:

1 2 3 4 5 6 5 4 3 2 1

El encabezado del procedimiento sería:

PROCEDURE ImprimeRenglon (digito: integer);

{Objetivo: Imprime un renglón de la forma 1 2 3 .. d .. 3 2 1 donde d es un dígito de 0 a 9}
Escriba un programa en Pascal utilizando dicho procedimiento, que solicite un dígito d al usuario, y muestre por pantalla una figura como la siguiente:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
...
...
1 2 3 .....d..... 3 2 1








Y ESTE ES EL SEGUNDO:

Tengo que diseñar un programa modularizado que permita realizar las siguientes operaciones con dos matrices de NxN.

a.- Sumar matrices
b.- Obtener el valor máximo de una matriz (El valor más grande)
c.- Obtener el valor mínimo de una matriz (El valor más chico)
d.- Obtener la cantidad de números positivos, negativos y ceros que tiene la matriz
e.- Obtener la cantidad de números pares y la cantidad de impares que tiene la matriz.


COMO SERIA CADA UNO?? IGUALMENTE MUCHAS GRACIAS¡¡¡¡









Me podrias ayudar en este ultimo tambien:

Dado un número entero N, si la suma de sus divisores (descartándose a si mismo) es igual a N se dice que ese número es perfecto. Si la suma es inferior, se dice que es deficiente, y si es superior se dice que es abundante. Por ejemplo:
• 6 tiene como divisores a 1, 2 y 3 y la suma de éstos es 6, por lo tanto es PERFECTO
• 8 tiene como divisores a 1, 2 y 4 y la suma de éstos es 7, por lo tanto es DEFICIENTE
• 24 tiene como divisores a 1, 2, 3, 4, 6, 8 y 12 y la suma de éstos es 36, por lo tanto es ABUNDANTE.


MUCHAS GRACIAS¡¡¡¡¡ :)
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