#include
#include
void main()
{
int n=5,i,j;
clrscr();
for(i=1;i<=2*n-2;i++)
{
printf(" ");
}
printf("1\n");
for(i=2;i<=n-1;i++)
{
for(j = 1;j<=(n-i)*2;j++)
printf(" ");
for(j = i;j<=2*i-1;j++)
{
printf("%d ",j);
}
for(j = 2*i-2;j>=i;j--)
{
printf("%d ",j);
}
printf("\n");
}
for(i = n;i<=2*n-1;i++)
printf("%d ",i);
for(i = 2*n-2;i>=n;i--)
printf("%d ",i);
getch();
}
2006-11-08 22:59:50
·
answer #1
·
answered by kalpana m 2
·
1⤊
0⤋
As a student of computer science, I will want you to try this for yourself.
In case you fail, you can use this program. Offcourse the value of n, you should ask from the user. The output will be neat only upto n =5. afterwards it will be distorted.
#include
#include
void main()
{
clrscr();
int n = 5;
for(int i=1;i<=2*n-2;i++)
{
printf(" ");
}
printf("1\n");
for(i = 2;i<=n-1;i++)
{
for(int j = 1;j<=(n-i)*2;j++)
printf(" ");
for(j = i;j<=2*i-1;j++)
{
printf("%d ",j);
}
for(j = 2*i-2;j>=i;j--)
{
printf("%d ",j);
}
printf("\n");
}
for(i = n;i<=2*n-1;i++)
{
printf("%d ",i);
}
for(i = 2*n-2;i>=n;i--)
{
printf("%d ",i);
}
getch();
}
2006-11-08 22:31:06
·
answer #2
·
answered by manoj Ransing 3
·
1⤊
0⤋
if you are a student of comp sci, you are supposed to analyse this problem yourself, not ask for the answer.
some guidance:
- what kind of triangle? let's assume a equalateral. to do that in ASCII (printing characters to draw it) you will need 1 asterisk on the 1st line, 3 on the 2nd, 5 on the third and so on ... what is this pattern??? identify it.
- use a for loop that ranges from 1 to 232 since that's how many lines you need
- think about that pattern. how can you get the loop variable i associated with the pattern? also, think about the spaces you will need to pad the triangle so it's drawn centrally. what is the width using the pattern of the 232th line? then, what is the width of the 1st line .. how can you relate the spaces required each side of the line with the current iteration?
it's simple but you need to think it through. asking here is not a good way to start your comp sci course.
2006-11-08 20:08:17
·
answer #3
·
answered by a11st4rc 2
·
2⤊
0⤋
the question is perplexing. each and every triangle ought to have 3 stars that are the factors. Why carry out a little of your have one million celeb and a few have 5? Do you mean that the part of the triangle are created from a special style of stars?
2016-10-03 10:56:30
·
answer #4
·
answered by ? 4
·
0⤊
0⤋
#include
#include
void main()
{
clrscr();
int n = 5;
for(int i=1;i<=2*n-2;i++)
{
printf(" ");
}
printf("1\n");
for(i = 2;i<=n-1;i++)
{
for(int j = 1;j<=(n-i)*2;j++)
printf(" ");
for(j = i;j<=2*i-1;j++)
{
printf("%d ",j);
}
for(j = 2*i-2;j>=i;j--)
{
printf("%d ",j);
}
printf("\n");
}
for(i = n;i<=2*n-1;i++)
{
printf("%d ",i);
}
for(i = 2*n-2;i>=n;i--)
{
printf("%d ",i);
}
getch();
}
2006-11-08 23:07:23
·
answer #5
·
answered by Anonymous
·
1⤊
0⤋