Saturday, October 31

To display a triangle using C Programming!

// to display a triangle using Graphics
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm,x,a,b;
initgraph (&gd,&gm,"c:\\tc\\bgi ");
while(!kbhit()) //display a triangle till a key is pressed
{
setcolor(WHITE);
line(300,200,400,300);
line(300,200,200,300);
line(200,300,400,300);
}
getch();
}

2 comments:

  1. 123456(input)
    1
    12
    123
    1234
    12345
    123456
    witkout array how possible???

    ReplyDelete
  2. #include
    using namespace std;
    int main()
    {
    int i,j,rows;
    cout<<"Enter the number of rows: ";
    cin>>rows;
    for(i=rows;i>=1;--i)
    {
    for(j=1;j<=i;++j)
    {
    cout<<j<<" ";
    }
    cout<<"\n";
    }
    return 0;
    }

    ReplyDelete