- #1
Nugso
Gold Member
- 170
- 10
Hello everyone. Today I learned how to write a program which calculates and prints integer squares roots from 1 to 1000. Here is what I wrote:
After compling this, 25, 49 etcs can't be seen. It lists like;
1.0000
4.0000
9.0000
and so on. However, if I write it like this;
then I do see 25.0000, 49.0000 etc too. What is confusing me is why do I have to add integer for sqrt(i) to see 25.0000, 49.0000?
Thanks.
Code:
program example
real::i
do i=1,1000
if(sqrt(i)**2==i) then
print*,i
end if
end do
end program example
After compling this, 25, 49 etcs can't be seen. It lists like;
1.0000
4.0000
9.0000
and so on. However, if I write it like this;
Code:
program example
real::i
integer::physicsforum
do i=1,1000
physicsforum=sqrt(i)
if(physicsforum**2=i)then
print*,i
end if
end do
end program example
then I do see 25.0000, 49.0000 etc too. What is confusing me is why do I have to add integer for sqrt(i) to see 25.0000, 49.0000?
Thanks.