Advertisement
dmilicev

simple star-o pattern v2 .c

Oct 13th, 2019
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. /*
  2.     simple star-o  pattern v2 .c
  3.  
  4.     h = 10
  5.  
  6.   i   j=h-i
  7.  
  8.   0    10
  9.   1     9
  10.   2     8
  11.   3     7
  12.   4     6
  13.   5     5
  14.   6     4
  15.   7     3
  16.   8     2
  17.   9     1
  18.  
  19. */
  20.  
  21. #include<stdio.h>
  22.  
  23. int main(void)
  24. {
  25. /*
  26.     i   number of current row
  27.     j   number of chars in current row
  28.     h   number of rows of whole tirangle
  29. */
  30.     int i,j,h;
  31.  
  32.     printf("Enter the height of the triangle : ");
  33.     scanf("%d",&h);
  34.  
  35.     printf("\n");
  36.  
  37.     for(i=0;i<h;i++)            // repeat loop for rows of triangle, h times
  38.     {
  39.         for(j=0;j<h-i;j++)      // repeat loop for chars in single row, h-i times
  40.         {
  41.             if(i%2==0)          // if row is even
  42.                 printf("O");    // print "O"
  43.             else                // if row is odd
  44.                 printf("*");    // print "*"
  45.         }
  46.         printf("\n");           // go to next row
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement