Posted By

chema_ar on 10/22/14


Tagged

pattern triangle loops Diagonal


Versions (?)

Triangle pattern


 / Published in: Fortran
 

This is a piece of code to draw a triangle pattern in the upper diagonal elements. It is a basic exercise of programming.

  1. program triangle_pattern
  2.  
  3. integer :: i = 0;
  4. integer :: j = 0;
  5. integer :: n = 3;
  6.  
  7. do while (i<n)
  8. j = 0;
  9. do while (j<n)
  10. if (j>=i) then
  11. write(*,"(A)",advance="no") " *"
  12. else
  13. write(*,"(A)",advance="no") " ."
  14. end if
  15. j=j+1;
  16. end do
  17. i = i +1;
  18. print *,""
  19. end do
  20. read *,
  21.  
  22. end program triangle_pattern

Report this snippet  

You need to login to post a comment.