Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. void trojkaty(int start, int stop, int h) {
  3. int i, j, k = 2 * h - 2;
  4. for (i = 0; i < start - 1; i++) k--;
  5. // rzędy
  6. for (i = start - 1; i < stop; i++) {
  7. // spacje
  8. for (j = 0; j < k; j++) printf(" ");
  9. k = k - 1;
  10. // funkcja po lewej
  11. for (j = 0; j <= i; j++) {
  12. if (j == 0 || (i==stop-1 && (stop==h || stop==4 || stop==h-1))) printf("*");
  13. else printf(" ");
  14. }
  15. //funkcja po prawej
  16. for (int x = i; x >= 0; x--) {
  17. if (x == 0 || (i == stop - 1 && (stop == h || stop == 4 || stop==h-1))) printf("*");
  18. else printf(" ");
  19. }
  20. printf("\n");
  21. }
  22. }
  23. void P(int h) {
  24. int a = h*3;
  25.  
  26. int i, j, k = 2 * a - 4;
  27. for (i = 1; i <= h+1; i++) {
  28. //spacje
  29. for (j = 0; j < k; j++) printf(" ");
  30. //
  31. for (j = 1; j <= h+1; j++) printf("#");
  32. printf("\n");
  33. }
  34. }
  35. void D(int h) {
  36. int a;
  37. a = h * 3;
  38. int start = 1, stop = 0, roz = 3;
  39. for (stop=start+roz;stop<a+1;stop=start+roz) {
  40. trojkaty(start, stop, a);
  41. roz++;
  42. start = stop - start;
  43. }
  44. }
  45. int main() {
  46. int h;
  47. printf("Wysokosc drzwka?(minimum 3):");
  48. scanf("%d", &h);
  49. D(h);
  50. P(h);
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement