这是一个执行基本转换的简单程序。我尝试使用循环和指令打印出值:
write (*,'(i4,a,a)') it," = ",baseConversion(it,base)
出于某种原因,我无法使用此行获取值
program echeverria_4
implicit none
interface
function baseConversion(anumber,abase)
character(8) :: baseConversion
integer,intent(in) :: anumber, abase
end function baseConversion
end interface
integer :: firstNumbers,base,it, numero
character(8),dimension(100) :: rangeNumbers
!Part A
write(*,*) "Project 4 Part A"
firstNumbers = 20
base = 11
write(*,'(i4,i4)') firstNumbers, base
do it = 1, firstNumbers
write (*,'(i4,a,a)') it," = ",baseConversion(it,base)
end do
end program echeverria_4
function trans(anumber)
implicit none
character :: trans
integer,intent(in):: anumber
integer :: conversor1 = 48
integer :: conversor2 = 55
if (anumber >= 10) then
trans = char(anumber+conversor2)
else
trans = char(anumber+conversor1)
endif
end function trans
function baseConversion(anumber, abase)
implicit none
interface
function trans(anumber)
character :: trans
integer,intent(in):: anumber
end function trans
end interface
character(8):: baseConversion
integer,intent(in):: anumber,abase
character(8) :: leftmost
logical :: is_process_complete = .false.
integer :: remainder,division,localNumber
localNumber = anumber
do while(.not. is_process_complete)
!Step 1: Find the remainder
remainder = mod(localNumber,abase)
!Step 2: Divide the number by the base
division = localNumber/abase
if (division>0) then
localNumber = division
leftmost=trans(remainder)//leftmost
else
is_process_complete=.true.
leftmost=trans(remainder)//leftmost
end if
end do
write(baseConversion,'(a)') leftmost
end function baseConversion