Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void drawtriangle(void)
- {
- int alt, base;
- int iii, ii, i; //counters
- int n, nn; //number of boxes (down)
- int w, l; //width and length of inner triangle
- int box0; //if there is an empty box at the bottom, how long it is
- char letter;
- printf("What is the altitude of the triangle? ");
- scanf("%d", &alt);
- printf("What is the base of the triangle? ");
- scanf("%d", &base);
- printf("What symbol should fill the triangle? ");
- scanf(" %c", &letter);
- if((base==2)||(alt==2))
- {
- drawline(letter, base, 1);
- alt--;
- for (i=1;i<=alt;i++)
- printf("%c\n", letter);
- }
- else if(base<alt)
- {
- w=base-2;
- l=alt-2;
- n=l/w;
- nn=n;
- box0=l%w;
- drawline(letter, base, 1);
- for(iii=1;iii<=nn;iii++)
- {
- for(ii=1;ii<=n;ii++)
- {
- printf("%c", letter);
- for(i=1;i<=w;i++)
- printf("%c", letter);
- printf("\n");
- }
- w--;
- }
- if(box0!=0)
- {
- for(i=1;i<=box0;i++)
- printf("%c\n", letter);
- }
- drawline(letter, 1, 1);
- }
- else if(alt<base)
- {
- w=alt-2;
- l=base-2;
- n=l/w;
- nn=n;
- box0=l%w;
- drawline(letter, base, 1);
- l-=box0;
- for(ii=1;ii<=nn;ii++)
- {
- printf("%c", letter);
- for(i=n;i<=l;i+=n)
- drawline(letter, n, 0);
- printf("\n");
- l-=n;
- }
- drawline(letter, 1, 1);
- }
- else
- {
- n=base;
- drawline(letter, base, 1);
- for(i=base;i!=0;i--)
- {
- n--;
- drawline(letter, n, 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement