一个关于“同构数”的Fortran程序的问题

来源:百度知道 编辑:UC知道 时间:2024/07/02 03:39:52
题目要求1-1000中的同构数
program ex309
implicit none
integer x,n
do x=1,1000
do n=1,4
if((x/10**n)==0)then
goto 1
endif
enddo
1 if(mod(x**2-x,10**n)==0)then
print*,x
endif
enddo
end
这是我个人编写的程序~貌似和书上的答案有所出入~
书上的答案是
program ex309_1
implicit none
integer m,l,n,j
do m=1,1000
k=m*m
l=1
n=0
do while((n<4)).and.(l==1))
n=n+1
j=10**n
if(m/j==0)l=0
enddo
if(mod(k-m,j)==0)
print*,"m=",m,"m**2=",k
enddo
end
但是书上的答案输入电脑里却出现错误
ex309_1.F95(8) : error 58 - Unpaired right bracket(s)
ex309_1.F95(13) : error 363 - Expected label/statement/THEN after IF statement, inserting THEN
ex309_1.F95(15) : error 763 - Nesting error - this END DO statement is matched with the IF construct starting on line 13
ex309_1.F

书上的答案你又抄错这么多。。。
program ex309_1
implicit none
integer m,l,n,j,k//忘记声明K了
do m=1,1000
k=m*m
l=1
n=0
do while((n<4).and.(l==1)) //多写了个括号
n=n+1
j=10**n
if(m/j==0)l=0
enddo
if(mod(k-m,j)==0)print*,"m=",m,"m**2=",k //没有THEN的话不能换行
enddo
end
你自己的程序没错,goto以后最好别用,破坏结构化,改成break 语句标号去掉就规范些了