Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include <stdio.h>
  2. void drawline(char sym, int num, int newline);
  3. void drawsquare(void);
  4. void drawtriangle(void);
  5. char askshape();
  6. int main()
  7. {
  8. char shape=0;
  9. printf("Welcome to the shape machine!");
  10. do {
  11. if(shape=='a'||shape=='A')
  12. drawsquare();
  13. else if(shape=='b'||shape=='B')
  14. drawtriangle();
  15. shape=askshape();
  16. } while(shape != 'c' && shape != 'C');
  17. printf("\nGoodbye!\n");
  18. return(0);
  19. }
  20. void drawline(char sym, int num, int newline)
  21. {
  22. int i;
  23. for(i=1;i<=num;i++)
  24. printf("%c", sym);
  25. if(newline)
  26. printf("\n");
  27. }
  28. void drawsquare(void)
  29. {
  30. int side, i, n;
  31. printf("What size is a side? ");
  32. scanf("%d", &side);
  33. drawline('x', side, 1);
  34. for(i=1; i<=side-2; i++)
  35. {
  36. printf("x");
  37. drawline(' ', side-2, 0);
  38. printf("x\n");
  39. }
  40. drawline('x', side, 1);
  41. }
  42. void drawtriangle(void)
  43. {
  44. int alt, base;
  45. int iii, ii, i; //counters
  46. int n, nn; //number of boxes (down)
  47. int w, l; //width and length of inner triangle
  48. int box0; //if there is an empty box at the bottom, how long it is
  49. char letter;
  50. printf("What is the altitude of the triangle? ");
  51. scanf("%d", &alt);
  52. printf("What is the base of the triangle? ");
  53. scanf("%d", &base);
  54. printf("What symbol should fill the triangle? ");
  55. scanf(" %c", &letter);
  56. if((base==2)||(alt==2))
  57. {
  58. drawline(letter, base, 1);
  59. alt--;
  60. for (i=1;i<=alt;i++)
  61. printf("%c\n", letter);
  62. }
  63. else if(base<alt)
  64. {
  65. w=base-2;
  66. l=alt-2;
  67. n=l/w;
  68. nn=n;
  69. box0=l%w;
  70. drawline(letter, base, 1);
  71. for(iii=1;iii<=nn;iii++)
  72. {
  73. for(ii=1;ii<=n;ii++)
  74. {
  75. printf("%c", letter);
  76. for(i=1;i<=w;i++)
  77. printf("%c", letter);
  78. printf("\n");
  79. }
  80. w--;
  81. }
  82. if(box0!=0)
  83. {
  84. for(i=1;i<=box0;i++)
  85. printf("%c\n", letter);
  86. }
  87. drawline(letter, 1, 1);
  88. }
  89. else if(alt<base)
  90. {
  91. w=alt-2;
  92. l=base-2;
  93. n=l/w;
  94. nn=n;
  95. box0=l%w;
  96. drawline(letter, base, 1);
  97. l-=box0;
  98. for(ii=1;ii<=nn;ii++)
  99. {
  100. printf("%c", letter);
  101. for(i=n;i<=l;i+=n)
  102. drawline(letter, n, 0);
  103. printf("\n");
  104. l-=n;
  105. }
  106. drawline(letter, 1, 1);
  107. }
  108. else
  109. {
  110. n=base;
  111. drawline(letter, base, 1);
  112. for(i=base;i!=0;i--)
  113. {
  114. n--;
  115. drawline(letter, n, 1);
  116. }
  117. }
  118. }
  119. char askshape()
  120. {
  121. char shape;
  122. printf("\n\nPick a shape:\nA) square\nB) triangle\nC) quit\n> ");
  123. scanf(" %c", &shape);
  124. return(shape);
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement