
Originally Posted by
dcr33
Traq i am upset ... Leave aside hirng u ...
I wasn't suggesting you hire me. Your initial post seemed to imply you just wanted someone to give you working code -- hiring someone is a better solution to that end.
I'm sorry to have upset you, and I apologize. I was trying to discover if you wanted to learn something or just have someone do it for you.

Originally Posted by
dcr33
... that wont work ever. Have u ever tried that in ur own machine?pathetic co...

yes, I have.
PHP Code:
<?php
// $n determines the number of rows in your triangle
$n = 8;
// first row (always a single star)
$R[] = '*';
// more than one row needed?
if( $n > 1 ){
// $w is the amount of whitespace needed for each row
// (the second row will need only 1 space)
$w = 1;
// loop to create each row
for( $c=2; $c<=$n; $c++ ){
// each row adds an element to the array
// containing star + whitespace + star
$R[] = '*'.str_repeat( ' ',$w ).'*';
// increment the whitespace count by two for next row
$w = $w+2;
}
// $l is the length of the last (longest) row
$l = strlen( $R[$n-1] );
// loop through each row in the array
for( $c=0; $c<count($R); $c++ ){
// pad each row so they're all the same length
$R[$c] = str_pad( $R[$c],$l,' ',STR_PAD_BOTH );
}
}
// using <pre> to preserve the whitespace / newlines
print '<pre>'.implode( "\n",$R ).'</pre>';
output:
Code:
*
* *
* *
* *
* *
* *
* *
* *
I hope this helps you with your questions.
Bookmarks