Posted By

chema_ar on 10/22/14


Tagged

number perfect


Versions (?)

Perfect Number


 / Published in: Fortran
 

This is a solution to the problem of detecting whether a number is a perfect number or not. It is a basic example of programming and it should be improved to protect the code.

  1. program perfect_number
  2. integer :: number
  3. integer :: result, i
  4.  
  5. print*,"Intro a number..."
  6. read *, number
  7.  
  8. i = 1;
  9. result = 0;
  10. do while (i < number)
  11. if(mod(number, i) == 0) then
  12. result = result + i;
  13. end if
  14. i = i+1;
  15. end do
  16.  
  17. print*,"The number ",number," is a Perfect number ", (number == result)
  18. read *,
  19. end program perfect_number

Report this snippet  

You need to login to post a comment.