Here’s my code for the upright triangle. Now I’m hard up on doing the code for inverted triangle, I’m working on it right now, but a little help would be great.

#include <iostream.h>
#include <conio.h>
void main()
{
        int len,ht,ch,cho,sz,col=20,ctr=1;
        cout<<"\nTRIANGLE";
        cout<<"\nEnter Size: ";
        cin>>sz;
        if (sz<5||sz>20)
                cout<<"Size must be between 5 and 20 only.";
        else
        {
                clrscr();
                for(int x=1;x<=sz;x++,col--,ctr+=2)
                {
                        gotoxy(col,x);
                        for(int y=1;y<=ctr;y++)
                        {
                                cout<<"*";
                        }
                }
        }
}

Share/Save/Bookmark

  • No Related Post