- #1
NicolasPan
- 21
- 2
Mod note: Fixed indents in code below
1. Hello everyone! I've been trying two days to find a solution to my problem though,unfortunately I'm stuck.The problem demands the creation of a program that is able to calculate the geeometric and the harmonic mean of a 5-digit integer.In addition the program checks and denies with approriate message numbers other than 5 digits in lenght.Ultimately the harmonic mean should be calculated only when all of the 5 digits are diffrent than 0.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
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 length 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
The Attempt at a Solution
Last edited by a moderator: