Divisor pattern


/ Published in: Fortran
Save to your folder(s)

This is a piece of code to print out a divisor pattern given a number n. It is a basic exercise of programming. It should be improved protecting the code.


Copy this code and paste it in your HTML
  1. program divisor_pattern
  2. integer :: n = 10;
  3. integer :: i = 1;
  4. integer :: j = 1;
  5. do while (i<=n)
  6. j = 1;
  7. do while (j<=n)
  8. if (mod(i,j)==0 .OR. mod(j,i)==0) then
  9. write(*,"(A)",advance="no") " *"
  10. else
  11. write(*,"(A)",advance="no") " "
  12. end if
  13. j = j + 1;
  14. end do
  15. print *,""
  16. i = i + 1;
  17.  
  18. end do
  19. read *,
  20. end program divisor_pattern

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.