There are some ways of solving this problem. One of the ways is as follows:
read*, i ncount = 1 n = 1 result = 0 1 if(mod(i,10**ncount).eq.i) then n_digit = ncount else ncount = ncount + 1 goto 1 endif 2 if(n.eq.n_digit+1) then print*, result else nth_digit = mod(i,10**n) / 10**(n-1) result = result + nth_digit*(10**(n_digit-n)-10**(n-1)) n = n + 1 goto 2 endif stop end |
read*, a,b,c read*, x1, x2 iteration = 0 1 f_x1 = a*x1**2 + b*x1 + c f_x2 = a*x2**2 + b*x2 + c x3 = ( x1 + x2 ) / 2. f_x3 = a*x3**2 + b*x3 + c iteration = iteration + 1 if(iteration.ge.20.or.abs(f_x3).lt.0.001) then write(*,2) x3 2 format(F10.5) stop else if(f_x3.gt.0) then if(f_x1.gt.0) x1 = x3 if(f_x2.gt.0) x2 = x3 goto 1 elseif(f_x3.lt.0) then if(f_x1.gt.0) x2 = x3 if(f_x2.gt.0) x1 = x3 goto 1 endif endif stop end |