Advertisement
malinaX

asterisk christmast tree

Sep 5th, 2020 (edited)
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5.     printf("Podaj wysokosc chinki: ");
  6.     int h;
  7.     scanf("%d", &h);
  8.  
  9.     printf("\nSposob 1:\n");
  10.     for (int i = 1; i <= h; i = i + 1)
  11.     {
  12.         for (int b = h - i; b > 0; b = b - 1)
  13.         {
  14.             printf(" ");
  15.         }
  16.         for (int a = 1; a <= 2 * i - 1; a = a + 1)
  17.         {
  18.             printf("*");
  19.         }
  20.         printf("\n");
  21.     }
  22.  
  23.     printf("\nSposob 2:\n");
  24.     int c = 1;
  25.     for (int i = 1; i <= h; i = i + 1)
  26.     {
  27.         for (int b = h - i; b > 0; b = b - 1)
  28.         {
  29.             printf(" ");
  30.         }
  31.         for (int a = 1; a <= c; a = a + 1)
  32.         {
  33.             printf("*");
  34.         }
  35.         printf("\n");
  36.         c = c + 2;
  37.     }
  38.  
  39.     printf("\nSposob 3:\n");
  40.     for (int lctr = 0, hctr = 0; hctr < h; lctr == h + hctr + 1 ? (lctr = 0, ++hctr) : 0)
  41.         printf("%c", lctr++ < h + hctr ? ((lctr < h - hctr) ? ' ' : '*') : '\n');
  42.     return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement