November 12th, 2012, 02:23 PM

Triangle numbers
I was looking for assistance with this program. The goal is take user input in the form x,y where x is the amount of numbers in the first row and y is the amount of numbers in the last row and all while applying euler's triangle equation like so:
2,5 yields
13
136
13610
1361015
here is where i'm at:
Code:
<script language="javascript">
var str = prompt('Input beginning number, ending number', '3,4');
var size = new Array();
dimension = str.split(',');
var x = parseInt(dimension[0]);
var y = parseInt(dimension[1]);
var z = 1;
for(i=0; i<x; i++) { document.write(z+'  <br>'); z++
for(j=0; j<y; j++) document.write(z+'  ');
z =(z*(z+1)/2); }
</script>
November 12th, 2012, 09:24 PM

It took me a minute to put it all together, but the code below should produce what your looking for and I also added a "if" condition; to remove the last trailing hyphen (comment that out / remove that, if you want to).
Code:
<script type="text/javascript">
var str = prompt('Input beginning number, ending number', '3,4');
var size = new Array();
var dimension = str.split(',');
var x = parseInt(dimension[0]);
var y = parseInt(dimension[1]);
var z = 0;
var max = 1;
for(i=0;i<y;i++) {
z++;
size.push((z*(z+1)/2));
}
for (iii=1;iii<y;iii++) {
max++;
for (ii=0;ii<max;ii++) {
document.write(size[ii]);
if (ii<(max1)) {
document.write("  ");
}
}
document.write("<br/>");
}
</script>
Last edited by web_loone08; November 12th, 2012 at 09:30 PM.
November 13th, 2012, 01:45 AM

Oh alright that makes sense I wasn't familiar with push thank you very much.