用Pascal编写一程序,输入一个正整数N,将N分解成质因数幂的乘积形式(帮忙看一下我哪里错了)

问题描述:

用Pascal编写一程序,输入一个正整数N,将N分解成质因数幂的乘积形式(帮忙看一下我哪里错了)
Program dw;
var n,i,t:longint;
begin
readln(n);
write(n,'=');
i:=2;
while n1 do
if n mod i=0 then
begin
t:=t+1;
n:=n div i;
if n=1 then write(i,'(',t,')');
end
else
begin
if t0 then
begin
write(i,'(',t,')','*');
end;
end;
End.
1个回答 分类:综合 2014-11-20

问题解答:

我来补答
1.每次除完之后i 要更新,你这里i的值就没变过
2.每次输出后要把t 赋值为0;
3.if n mod i=0 then
begin
t:=t+1;
n:=n div i;
if n=1 then write(i,'(',t,')');
end
这里不能用IF语句,用IF语句只会出1次,要改为WHILE语句我把你的程序改了一下,贴在下面,应该没问题了.
var n,i,t:longint;
begin
readln(n);
write(n,'=');
i:=2;
while n1 do
begin
while n mod i=0 do
begin
t:=t+1;
n:=n div i;
end;
if t0 then
begin
write(i,'(',t,')');
if n1 then write('*');
end;
i:=i+1; t:=0;
end;
End.
 
 
展开全文阅读
剩余:2000
上一页:ghhhhh
下一页:概括每段段意