I am trying to write simple Fortran code for practice. It is supposed to multiply the numbers in the range. Each time, the resulting product is converted to a string, because I want to see if it consists of the same numbers.
I checked the way to convert an integer to a string and typed the components of the string, and everything went right. Then I need to compare the components of the string for which I use the string (number: number). But I could not get the code to do it right.
Here's the code and output:
program test implicit none character(10) myString character(1) a,b,c,d,e,f integer::i,j,k do i=900,901,1 j=900 k=i*j write(*,*)'k =', k write(myString,'(i10)') k write(*,*)'myString = ', myString a=myString(1:1) b=myString(2:2) c=myString(3:3) d=myString(4:4) e=myString(5:5) f=myString(6:6) print*,a,b,c,d,e,f if (d==f) then print*,'hobla' else print*,'fobla' end if end do stop end program test
So, I defined the characters: a, b, c, d, e, f to contain the components of the string. And used myString (i: i) to find each component and store it in one of the characters a, b, c, d, e, f. But it seems that only the first two are working correctly, the rest are not saved!
Output:
k = 810000 myString = 810000 81 fobla k = 810900 myString = 810900 81 fobla
Notice 81. It was supposed that he should give 810,000 for the first time and type βhoblaβ. And give 810900 a second time and type "fobla." But this did not happen!
Can someone show me how to allow myString to accept zeros as characters?