PROGRAM FactorPrimo(input,output);
VAR
numero : integer;
factor : integer;
resto : integer;
primo : integer;
multiplicidad : boolean;
BEGIN
write('Ingrese numero: ');
readln(numero);
factor := 2;
primo := 0;
multiplicidad := false;
IF numero > 1 THEN
BEGIN
REPEAT
BEGIN
resto := numero MOD factor;
IF resto = 0 THEN
BEGIN
numero := numero DIV factor;
primo := primo + 1;
multiplicidad := true;
END
ELSE IF multiplicidad = true THEN
IF primo > 1 THEN
writeln(factor,'^',primo);
multiplicidad := false;
ELSE
writeln(factor);
multiplicidad := false;
ELSE
factor := factor + 1;
primo := 0;
END;
UNTIL numero = 1;
writeln(factor);
END
ELSE
write('Debe ingresar un numero mayor a 1');
END.
I don't know why but the program doesn't enter in IF PRIMO > 1 then it always goes to the ELSE statment below. Have I done something wrong? I have done it in java and it works fine.
Working fine it should says:
factor^primo
But what displays is only:
factor
It should go from the if to the else if and the try the else. But what it is doing now is going from the if to the else and then else if.
An example, with the number 360 it should says:
2^3
3^2
5
But what it shows now is:
2
3
5
I think this is because it always end up with primo = 0, and I don't know how to fix this.