Thread: Trying to make a triangle

1. Trying to make a triangle

the output should be:
Code:
```Size: 4  Seed: 1
1  2  4  7
3  5  8
6  9
0```
Updated code:
Code:
```main()
{
size = 6;
seed = 3;

for(row = 0; row < size; row++)
{
cnum = seed;

for(col = 0; col < size; col++)
{
if(col == row)
{
printf("%i ", cnum + row);
}
else if(col > row)
{
if((cnum = cnum + col) <= 9)
{
printf("%i ", cnum);
}
else
{
cnum = cnum - 10;
printf("%i ", cnum);
}
}
else
{
printf("  ");
}
}
printf("\n");
}
}```

2. I am begginer also but I see that you put
Code:
`for(col = 1; col < size; col++)`
isn't it must be
Code:
`for(col=1; col<=size;++col)`

3. Not sure but maybe it will help. In you if statement you have cnum assigned to crow, but you are not using it anywhere.

4. I know, I was trying something that didn't work. I must have missed that part, but it doesn't make any difference in the program.

5. What do you mean by "Trying to make a triangle"?

Greets,
Philip

6. i actually just found out the it is called a Parkside Triangle. That is what I need to make. Instead of me failing to properly describe it here:
http://www.wisegeek.com/what-is-parksides-triangle.htm

I can get the first row, but after that it all goes to hell.

7. Code:
```1  2  4  7
3  5  8
6  9
0```
I think with your settings (seed=1, size=4), the output should end in a line that contains a 1 instead of a 0...

Hint 0: no Parkside Triangle can contain zeros.

I can get the first row, but after that it all goes to hell.
Well, can you spot any obvious difference between the first row and all the other rows by looking at the output of your program?

Hint 1:
Try to get the correct numbers first, then use indenting to make it look as specified (I didn't test it, but this should solve your problem)

Hint 2:
In every row, the first number only depends on the seed, not on the size

Apart from that, it is desirable to explicitly state that seed, size, row, col, cnum and main() are of type int (or function returning int respectively).

Greets,
Philip

EDIT: you can compute the value of any of these numbers in constant time by using only seed, row and col. It's probably not the goal of your exercise to find this expression, but once you have it, the rest is easy. If you can't find it immediately, stick to your current approach.

8. Okay, I've got the 1st numbers in each row correct, but I can't figure out why the other numbers are off. I'm on about hour 7 on something that shouldn't be that hard so I'll a little frustrated. Any help is appreciated, thanks.

Code:
```Desired Output:
1 2 4 7
3 5 8
6 9
0

Actual:
1 3 4 5
3 6 7
6 0
0```
Here is my code:
Code:
```main()
{
printf("Enter size and seed:  ");
scanf("\n%i %i", &size, &seed);
rnum = seed;

for(row = 1; row <= size; row++)
{
for(col = 1; col <= size; col++)
{
if(col == row)
{
if(row == 1)
{
printf("%i ", seed);
}
else
{
rnum = y + row;
if(rnum > 9)
{
printf("%i ", rnum%10);
}
else
{
printf("%i ", rnum);
}
}
y = rnum;
}
else if(col > row)
{
cnum = rnum + col;
printf("%i ", cnum%10);
}
else
{
printf("  ");
}
}
printf("\n");
}
}```

9. when seed == 1, row ==1 and col == 2 you have rnum == seed == 1
Code:
```cnum = rnum + col;
printf("%i ", cnum%10);```
Now tell me why do you think that 1+2 should be 2 and not 3?