回 帖 发 新 帖 刷新版面

主题:求解

请编一程序,功能如下:
    输入一个大于1的自然数,如以75为例,打印出如下解:
       75=3*5*5;
     感激不尽!!

回复列表 (共12个回复)

沙发

短除法

板凳

program yb(input,output);
var n:integer;
     a,b:integer;
  begin
  while not seekeof(input) do begin
   b:=1;
   read(n);
   write(n,'=');
    while n<>1 do
     begin
      b:=b+1;
      if n mod b=0 then
       begin
       n:=n div b;
        if n=1 then begin
         write(b);
         writeln;
        end
        else
         begin
         write(b,'*');
        b:=1;
       end;
      end;
     end;
    end;
   end.

3 楼

program zhs (input,output);
  var
    x,y,n:integer;
  begin
    read(x);
    write(x,'=');
    y:=2;
    n:=1;
    repeat
      if x mod y=0
        then begin
               x:=x div y;
               if n <> 1
                 then write('*');
               write(y);
               n:=2
             end
        else y:=y+1
    until x=1;
    writeln
  end.

4 楼

2楼的正确!

5 楼

我已经上机试过了,没有错.

6 楼

好复杂哦

7 楼

2楼的
while not seekeof(input) do begin//seekeof(input)是什么意思哟?
看不懂~

8 楼

这个嘛~不好说 做下TJU的1007吧 这样你就知道了
acm.tongji.edu.cn

9 楼

楼上的我没看懂呀~~~~

10 楼

我做了,还是不知道是什么~
它是怎么判断输入结束的?

我来回复

您尚未登录,请登录后再回复。点此登录或注册