Pascal/Turbo Pascal - [AYUDA] Ejercicio en pascal.. !

 
Vista:

[AYUDA] Ejercicio en pascal.. !

Publicado por Leandro (1 intervención) el 26/05/2011 06:32:49
Hola gente.. bueno yo venia a pedir ayuda con este ejercicio porque la verdad ni idea como poder hacerlo.. soy malo en el tema de la programación.. y lo peor es que es para hoy 26 :S agradezco mucho su ayuda..


PROBLEMA

Ingresar pares de valores numéricos y mostrar el resultado del producto de ambos.
Para ello el programa presentara un menú de opciones con la siguiente pantalla:


1 - Multiplicación por sumas reiteradas
2 - Multiplicación a la “rusa”
0 - Salir
Ingrese su opción : ----


Si el operador digita 1, el programa pedirá los dos valores y la pantalla de salida será:


Multiplicación por sumas reiteradas

Multiplicando----Multiplicador---- Resultado
------150-----------------10---------------1500


Si el operador digita 2 el programa pedirá los dos valores y la pantalla de salida será:


Multiplicación a la rusa

Nro. de pasos---- Multiplicador---- Multiplicando---- Resultado---- Resultado acumulado
--------1-------------------- 27------------------ 19----------------- 19------------------------ 19
--------2-------------------- 13-------------------38------------------38------------------------ 57
--------3---------------------- 6------------------ 76------------------- 0------------------------ 57
--------4---------------------- 3-----------------152--------------- 152----------------------- 209
--------5---------------------- 1---------------- 304--------------- 304----------------------- 513


El proceso podrá repetirse tantas veces como el operador lo requiera
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

[AYUDA] Ejercicio en pascal.. !

Publicado por ramon (2158 intervenciones) el 26/05/2011 12:49:21
{Espero te sirva como ayuda en tus estudios y no como otra cosa suerte}

program mulrusa;
uses
crt, dos;
const
menuopcion : array[1..3] of string[10] = ('Suma Rpt.','Multi.Rusa','Salir');
var
mul1, mul2 : integer;
total, res1, res2 : longint;
tecla : char;
resulmul1 : array[0..100] of integer;
resulmul2 : array[0..100] of integer;

procedure sumareiterada(mul1, mul2 : integer);
var
resultado : longint;
k : integer;
begin
resultado := 0;
for k := 1 to mul2 do
resultado := resultado + mul1;
writeln;
writeln('Resultado de la suma es = ',resultado);
writeln;
writeln('Resultado de la Multiplicacion es = ',mul1 * mul2);
end;

function stringinteger(s : string) : integer;
var
r : integer;
er : integer;
begin
val(s,r,er);
stringinteger := r;
end;

procedure entrada_numeros;
var
dato : string[10];
entra, i : integer;
begin
i := 1;
entra := 1;
repeat
if entra = 1 then
begin
TextBackground(0);
gotoxy(3,2);ClrEol;
textcolor(1);
TextBackground(7);
gotoxy(3,2);write(' Entre Multiplicador :');
gotoxy(28,2);
end;
if entra = 2 then
begin
TextBackground(0);
gotoxy(3,2);ClrEol;
textcolor(15);
TextBackground(1);
gotoxy(3,2);write(' Entre Multiplicando :');
gotoxy(28,2);
end;
fillchar(dato,11,' ');
dato[0] := chr(10);
repeat
tecla := readkey;
if tecla in[#48..#57] then
begin
dato[i] := tecla;
dato[0] := chr(i);
gotoxy(28,2);write(dato);
i := i + 1;
if i > 10 then
i := 10;
end;
if tecla = #8 then
begin
i := i - 1;
dato[i] := ' ';
dato[0] := chr(i);
gotoxy(28,2);write(dato);
end;
until tecla = #13;
if entra = 1 then
begin
mul1 := stringinteger(dato);
end;
if entra = 2 then
begin
mul2 := stringinteger(dato);
end;
entra := entra + 1;
until entra > 2;
TextBackground(0);
gotoxy(3,2);ClrEol;
textcolor(10);
TextBackground(7);
writeln('La operacion Sera = ',mul1,' X ',mul2);
textcolor(15);
TextBackground(0);
end;

procedure proceso_multiplicacion_rusa(multp, multd : integer);
var
co, resul1, resul2 : longint;
res : real;
cont : integer;
begin
co := 0;
resulmul1[co] := multp;
resulmul2[co] := multd;
resul1 := 0;
resul2 := 0;
co := 1;
res := 0.0;
repeat
res := (multp / 2);
resul1 := round(int(res));
resul2 := multd * 2;
if resul1 > 0 then
begin
resulmul1[co] := resul1;
resulmul2[co] := resul2;
multp := resul1;
multd := resul2;
co := co + 1;
end;
until resul1 <= 0;
resul1 := 0;
resul2 := 0;
for cont := 0 to (co - 1) do
begin
if Frac(resulmul1[cont] / 2) = 0 then
begin
resulmul1[cont] := 0;
resulmul2[cont] := 0;
end;
end;
writeln;
total := 0;
for cont := 0 to (co - 1) do
begin
if resulmul1[cont] > 0 then
begin
total := total + resulmul2[cont];
end;
end;
gotoxy(3,2);ClrEol;
writeln('La operacion de la Multiplicar Rusa sera = ',mul1,' X ',mul2,' = ',total);
end;
procedure menu;
var
x1, y1, g, opcion : integer;
salir : boolean;
tec : char;
begin
opcion := 1;
salir := false;
x1 := 3;
y1 := 3;
repeat
textcolor(15);
TextBackground(1);
gotoxy(1,1);write('** MENU GENERAL **');
textcolor(15);
TextBackground(0);
for g := 1 to 3 do
begin
gotoxy(3,2 + g);write(menuopcion[g]);
end;
textcolor(14);
TextBackground(7);
gotoxy(x1,y1);write(menuopcion[opcion]);
textcolor(15);
TextBackground(0);
tec := readkey;
if tec = #72 then
begin
opcion := opcion - 1;
y1 := y1 - 1;
if opcion < 1 then
begin
opcion := 1;
y1 := y1 + 1;
end;
end;
if tec = #80 then
begin
opcion := opcion + 1;
y1 := y1 + 1;
if opcion > 3 then
begin
opcion := 3;
y1 := y1 - 1;
end;
end;
if tec = #13 then
begin
case opcion of
1 : begin
clrscr;
entrada_numeros;
sumareiterada(mul1,mul2);
writeln;
writeln('****** Pulse Enter ******');
readln;
clrscr;
end;
2 : begin
clrscr;
entrada_numeros;
proceso_multiplicacion_rusa(mul1, mul2);
writeln;
writeln('****** Pulse Enter ******');
readln;
clrscr;
end;
3 : salir := true;
end;
end;
until salir;
end;


begin
clrscr;
textcolor(15);
menu;
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

[AYUDA] Ejercicio en pascal.. !

Publicado por maxi (1 intervención) el 26/05/2011 18:00:49
ojo que claudia no dio arreglos todavia leandro asiq ojo con eso
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] Ejercicio en pascal.. !

Publicado por ramon (2158 intervenciones) el 26/05/2011 21:05:34
{siento por poner el programa con arreglos no tengo ni idea de lo que asondado pero os pongo un
ejemplo para que arregleis a vuestro nivel pero temo que no abre is entrado en otras muchas cosas
del programa pero vuestro conocimiento de lo que a veis echo os permitirá ajustarlo a vuestras necesidades}

var
resulmul1 : integer;
resulmul2 : integer;


procedure proceso_multiplicacion_rusa(multp, multd : integer);
var
resul1, resul2 : longint;
res : real;
cont : integer;
begin
resul1 := 0;
resul2 := 0;
res := 0.0;
total := 0;
if frac(multp / 2) > 0 then
total := total + multd;
repeat
res := (multp / 2);
resul1 := round(int(res));
resul2 := multd * 2;
if resul1 > 0 then
begin
resulmul1 := resul1;
resulmul2 := resul2;
if Frac(resulmul1 / 2) = 0 then
begin
resulmul1 := 0;
resulmul2 := 0;
end;
if resulmul1 > 0 then
begin
total := total + resulmul2;
end;
end;
multp := resul1;
multd := resul2;
until resul1 <= 0;
gotoxy(3,2);ClrEol;
writeln('La operacion de Multiplicar sera = ',mul1,' X ',mul2,' = ',total);
end;

{En el resto cambiar los arreglos por variables o constantes vosotros veréis lo mejor}
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