Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
f95
program name use dec2bin implicit none integer :: response,binary,input,bdec,adec real :: binaradix
print*,'Choose one option:' print*,'1.Convert a positive integer to binary' print*,'2.Convert a positive real number to binary' read*,response
if (response==1) then print*,'Enter the integer:' read*,input binary=dec2binInt(input) print*,binary else if (response==2) then print*,'Enter the part before float as integer:' read*,bdec print*,'Enter the part after the decimal as integer:' read*,adec binary=dec2binInt(bdec) print*,'The part before binary radix:'
print*,binary binaradix=dec2binFlt(adec) print*,'The part after binary radix:' print*, binaradix end if end program name
module dec2bin
contains
!Find binary digits in reverse do while(quo/=0) quo=num/2 rem=num-(quo*2) num=quo output=(output*10)+rem counter=counter+1 end do
end function
implicit none integer :: input integer :: count,prod,num,length,lenTemp real :: temp num=input temp=0.1 count=0 do while(count<21 .and. num>0) length= lenInt(num) prod=num*2 lenTemp= lenInt(prod)
if (lenTemp>length) then
dec2binFlt=temp