Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. void drawtriangle(void)
  2. {
  3. int alt, base;
  4. int iii, ii, i; //counters
  5. int n, nn; //number of boxes (down)
  6. int w, l; //width and length of inner triangle
  7. int box0; //if there is an empty box at the bottom, how long it is
  8. char letter;
  9. printf("What is the altitude of the triangle? ");
  10. scanf("%d", &alt);
  11. printf("What is the base of the triangle? ");
  12. scanf("%d", &base);
  13. printf("What symbol should fill the triangle? ");
  14. scanf(" %c", &letter);
  15. if((base==2)||(alt==2))
  16. {
  17. drawline(letter, base, 1);
  18. alt--;
  19. for (i=1;i<=alt;i++)
  20. printf("%c\n", letter);
  21. }
  22. else if(base<alt)
  23. {
  24. w=base-2;
  25. l=alt-2;
  26. n=l/w;
  27. nn=n;
  28. box0=l%w;
  29. drawline(letter, base, 1);
  30. for(iii=1;iii<=nn;iii++)
  31. {
  32. for(ii=1;ii<=n;ii++)
  33. {
  34. printf("%c", letter);
  35. for(i=1;i<=w;i++)
  36. printf("%c", letter);
  37. printf("\n");
  38. }
  39. w--;
  40. }
  41. if(box0!=0)
  42. {
  43. for(i=1;i<=box0;i++)
  44. printf("%c\n", letter);
  45. }
  46. drawline(letter, 1, 1);
  47. }
  48. else if(alt<base)
  49. {
  50. w=alt-2;
  51. l=base-2;
  52. n=l/w;
  53. nn=n;
  54. box0=l%w;
  55. drawline(letter, base, 1);
  56. l-=box0;
  57. for(ii=1;ii<=nn;ii++)
  58. {
  59. printf("%c", letter);
  60. for(i=n;i<=l;i+=n)
  61. drawline(letter, n, 0);
  62. printf("\n");
  63. l-=n;
  64. }
  65. drawline(letter, 1, 1);
  66. }
  67. else
  68. {
  69. n=base;
  70. drawline(letter, base, 1);
  71. for(i=base;i!=0;i--)
  72. {
  73. n--;
  74. drawline(letter, n, 1);
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement