Triangle pattern


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

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.