Advertisement
dmilicev

simple star-o pattern v1 .c

Oct 13th, 2019
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. /*
  2.  simple star-o  pattern v1 .c
  3.  
  4. oooooooooo
  5. *********
  6. oooooooo
  7. *******
  8. oooooo
  9. *****
  10. oooo
  11. ***
  12. oo
  13. *
  14.  
  15. */
  16.  
  17. #include "stdio.h"
  18.  
  19. int main(void)
  20. {
  21. /*
  22.     i       for loop counter,
  23.     r       row,
  24.     nr      number_of_rows,
  25.     no      number_of_o,
  26.     na      number_of_*
  27. */
  28.     int i, r, nr, no, na;
  29.  
  30.     printf("\n Enter number of rows, nr = ");
  31.     scanf("%d", &nr);           // try 10
  32.  
  33.     no = nr;                    // initial value
  34.     na = nr-1;                  // initial value
  35.  
  36.     printf("\n");               // print new row
  37.  
  38.     for (r=0; r<nr/2; r++)      // repeat nr/2 times
  39.     {                           // print two rows at once, that is why r<nr/2
  40.         for (i=0; i<no; i++)    // print first row with "o", no times
  41.             printf("o");
  42.  
  43.         printf("\n");           // print new row
  44.  
  45.         for (i=0; i<na; i++)    // print second row with "*", na times
  46.             printf("*");
  47.  
  48.         printf("\n");           // print new row
  49.  
  50.         no = no-2;              // new numbers of "o" for next first row repeat
  51.         na = na-2;              // new numbers of "*" for next second row repeat
  52.     }
  53.  
  54.     printf("\n");           // print new row
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement