Posted By

chema_ar on 10/22/14


Tagged

pattern loops divisor f90


Versions (?)

Divisor pattern


 / Published in: Fortran
 

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.

  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  

You need to login to post a comment.