MAKING A triangle LINE

i dont how to make a diagonal line using FOR LOOP.. were just using <stdio.h>, <conio.h>, <dos.h>.. please help me :( because out professor didnt teach us how to do a diagonal line

i want to make a program like this(PLEASE IGNORE THE DOTS):
(there should be two triangles where the angle of the first triangle intersects with the angle of the second triangle.. )

********************
*.....*************.....*
*........*................*........*
*.............*......*.............*
*.................*.................*
*.............*......*.............*
*........*................*........*
*.....*************.....*
********************

the code for the rectangle is this:

#include<stdio.h>
#include<conio.h>
#include<dos.h>
main()
{
clrscr();
for(int x=1; x<=60;x++)
{ gotoxy(x,1); printf("*"); delay(50); }
for(x=1;x<=25;x++)
{ gotoxy(60,x); printf("*");delay(50); }
for(int x=60; x>=1;x--)
{ gotoxy(x,25); printf("*");delay(50); }
for(int x=25; x>=1;x--)
{ gotoxy(1,x); printf("*");delay(50); }

getch();
return 0;
}
Last edited on
@swellrock

Using the same gotoxy command, you would add 3 to the x, and 1 to the y location to go down the screen, or subtract 1 from the y location, to go up the screen, like so..
1
2
3
4
5
for(x=1;x< 20;x++)
{ gotoxy(1+(x*3),3+x);  printf("*");
  gotoxy(1+(x*3),23-x); printf("*"); 
  delay(50);
}

Or, if you wanted just two large triangles that don't start at the corners of the two center lines, just add x to the column starting position. Hope this helps you..
@whitenite1


thank you for help.. it helped me alot.. but i was a little bit confused then i ask my classmate on what you mean add 3 to the x, then he explained it to me very well..

THANKS AGAIN :)
Topic archived. No new replies allowed.