dmilicev

big triangle v1.c

Oct 7th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. /*
  2.     big triangle v1.c
  3.  
  4. In entered number_of_rows print triangle of *
  5.  
  6. row spaces  *
  7.  
  8.  0.    4    1
  9.  1.    3    3
  10.  2.    2    5
  11.  3.    1    7
  12.  4.    0    9
  13.  
  14. For number of spaces in a row we have to find relation with
  15. row and number_of_rows (number_of_rows - row - 1).
  16.  
  17. For number of * in a row 2we have to find relation with row (2*row+1).
  18.  
  19. */
  20.  
  21. #include <stdio.h>
  22.  
  23. int main(void)
  24. {
  25.     int i, row, number_of_rows;
  26.  
  27.     printf("Triangle of how much number_of_rows = ");
  28.     scanf("%d", &number_of_rows);               // try 40
  29.  
  30.     printf("\n");
  31.  
  32.     for (row=0; row<number_of_rows; row++)      // print rows one by one row
  33.     {
  34.         for (i=0; i<number_of_rows-row-1; i++)  // print spaces, number_of_rows-row-1 times
  35.             printf("-");                        // replace "-" with " "
  36.  
  37.         for (i=0; i<2*row+1; i++)               // print *, 2*row+1 times
  38.             printf("*");
  39.  
  40.         printf("\n");                           // new row
  41.     }
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment