How to resolve the algorithm Munchausen numbers step by step in the Fortran programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Munchausen numbers step by step in the Fortran programming language

Table of Contents

Problem Statement

A Munchausen number is a natural number n the sum of whose digits (in base 10), each raised to the power of itself, equals n. (Munchausen is also spelled: Münchhausen.) For instance:   3435 = 33 + 44 + 33 + 55

Find all Munchausen numbers between   1   and   5000.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Munchausen numbers step by step in the Fortran programming language

Source code in the fortran programming language

C MUNCHAUSEN NUMBERS - FORTRAN IV
      DO 2 I=1,5000
        IS=0
        II=I
        DO 1 J=1,4
          ID=10**(4-J)
          N=II/ID
          IR=MOD(II,ID)
          IF(N.NE.0) IS=IS+N**N
  1       II=IR
  2     IF(IS.EQ.I) WRITE(*,*) I
      END


! MUNCHAUSEN NUMBERS - FORTRAN 77
      DO I=1,5000
        IS=0
        II=I
        DO J=1,4
          ID=10**(4-J)
          N=II/ID
          IR=MOD(II,ID)
          IF(N.NE.0) IS=IS+N**N
          II=IR
        END DO
        IF(IS.EQ.I) WRITE(*,*) I
      END DO
      END


  

You may also check:How to resolve the algorithm Towers of Hanoi step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Singleton step by step in the Vala programming language
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Stable marriage problem step by step in the Go programming language
You may also check:How to resolve the algorithm Euler's constant 0.5772... step by step in the Lambdatalk programming language