- #1

- 21

- 2

**Mod note**: Fixed indents in code below

Fortran:

```
!this program accepts a 5 digit integer
!and calculates the harmonic and geometric means of it's digits
!the program checks and denies numbers with lenght diffrent than 5 digits
!The harmonic mean should be calculated only when
!all of the number's digits are non zero
program ex_3
implicit none
!Variables
integer::harmonicmean,geometricmean,div,div1,div2,div3,div4,div5,x
print*,'Welcome to my program,please input a 5 digit number'
geometricmean=(div1*div2*div3*div4*div5)**(1/5)
harmonicmean=(5)/((1/div1)+(1/div2)+(1/div3)+(1/div4)+(1/div5))
read*,x
if (x>=11111) then
if (x<=99999) then
print*,'to apotelesma twn armonikwn kai geometrikwn meswn einai:',geometricmean,harmonicmean
end if
else
if(x>=10000) then
print*,'Impossible to calculate harmonic mean'
print*,'Geometricmean=',geometricmean
else
print*,'Error'
end if
end if
end program
```

So what is really baffling me is how to break apart a 5 digit number and use it's digits for my calculations.I know that the code is not right though I assume it will much easier if a solve this question.I've written a few codes though none of them seems right to me.I would really appreciate your help,thanks in advance

## The Attempt at a Solution

Last edited by a moderator: