PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
gentooF1
Forum Newbie
Posts: 4 Joined: Tue Sep 29, 2009 12:43 pm
Post
by gentooF1 » Tue Sep 29, 2009 12:48 pm
Hi!
there i need some help with two different things..
i need to print out a triangle that looks like this one:
******
*****
****
***
**
*
******
*****
****
***
**
*
I know that i have to play with FOR loops.
Can anyone help me and write it in PHP.
Code: Select all
<html>
<body>
<?php
for ($i=1; $i<=5; $i++)
//for ($j=i+1; $j<=5; $j++)
echo "*" ;
echo "<br>";
for ($j=1; $i<=9; $i++)
echo "*" ;
echo "<br>";
?>
</body>
</html>
REALLY DO NOT KNOW HOW TO DO.... SO PLEASE TELL ME WHERE TO POST IT IF THIS IS NOT CORRECT SITE.
arjan.top
Forum Contributor
Posts: 305 Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia
Post
by arjan.top » Tue Sep 29, 2009 2:35 pm
Code: Select all
for($i=0; $i<6; $i++) {
for($j=$i; $j<6; $j++) {
echo "*";
}
echo "\n";
}
gentooF1
Forum Newbie
Posts: 4 Joined: Tue Sep 29, 2009 12:43 pm
Post
by gentooF1 » Tue Sep 29, 2009 3:09 pm
Code: Select all
<html>
<body>
<?php
for($i=0; $i<6; $i++) {
for($j=$i; $j<6; $j++) {
echo "*";
}
echo "<br/>";
}
?>
</body>
</html>
It is a really corect output! This bellow it is correct from code upstars... THANK YOU
******
*****
****
***
**
*
gentooF1
Forum Newbie
Posts: 4 Joined: Tue Sep 29, 2009 12:43 pm
Post
by gentooF1 » Tue Sep 29, 2009 3:23 pm
I would like to know what to do for others combinations, let's say the one like bellow:
And now, what are the for cases... ?Anyone know?
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Tue Sep 29, 2009 5:41 pm
Is this a homework assignment?
Also, I've moved this thread to PHP - Code. Please check all the forums before posting to make sure you put it in the right spot.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
gentooF1
Forum Newbie
Posts: 4 Joined: Tue Sep 29, 2009 12:43 pm
Post
by gentooF1 » Wed Sep 30, 2009 8:06 am
No, this is the excersise that I have to do for my new work... So please help me... !
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Sep 30, 2009 9:44 am
Your work hired you as a PHP developer and are asking you to do something like this ? Seems a bit odd.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Wed Sep 30, 2009 9:47 am
pickle wrote: Your work hired you as a PHP developer and are asking you to do something like this ? Seems a bit odd.
lol yeah. You get paid to draw triangles? Nice...
And the title of this thread sucks. It applies to like...probably about 75% of posts on this forum.
HavokDelta6
Forum Newbie
Posts: 16 Joined: Mon Sep 28, 2009 4:11 pm
Post
by HavokDelta6 » Wed Sep 30, 2009 10:08 am
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Last edited by
HavokDelta6 on Tue Mar 20, 2012 5:58 am, edited 1 time in total.
AlexC
Forum Commoner
Posts: 83 Joined: Mon May 22, 2006 10:03 am
Post
by AlexC » Wed Sep 30, 2009 2:30 pm
An easier way:
Code: Select all
<?php
for( $i = 10; $i > 0; $i-- ) {
echo str_repeat( '*', $i )."\n";
}
?>
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Wed Sep 30, 2009 2:54 pm
gentooF1 wrote: No, this is the excersise that I have to do for my new work... So please help me... !
You need to explain this. I never heard of an employer who pays someone to do exercises.
Mirge
Forum Contributor
Posts: 298 Joined: Thu Sep 03, 2009 11:39 pm
Post
by Mirge » Wed Sep 30, 2009 4:30 pm
califdon wrote: gentooF1 wrote: No, this is the excersise that I have to do for my new work... So please help me... !
You need to explain this. I never heard of an employer who pays someone to do exercises.
Yeah.......seriously.. who is going to invest time and money into someone just to have them draw pointless shapes heh.
CodeGeek
Forum Newbie
Posts: 12 Joined: Wed Sep 30, 2009 3:36 pm
Location: England
Post
by CodeGeek » Wed Sep 30, 2009 4:35 pm
Who cares he's getting paid for it? Getting paid is a good thing, last time I checked.
Mirge
Forum Contributor
Posts: 298 Joined: Thu Sep 03, 2009 11:39 pm
Post
by Mirge » Wed Sep 30, 2009 4:42 pm
CodeGeek wrote: Who cares he's getting paid for it? Getting paid is a good thing, last time I checked.
Doesn't sound like a job to me.. sounds like an assignment. I think that's what people are getting at.
peterjwest
Forum Commoner
Posts: 63 Joined: Tue Aug 04, 2009 1:06 pm
Post
by peterjwest » Wed Sep 30, 2009 5:20 pm
How the hell is he employed? I could do this in my sleep, I have a first class degree and I still can't get employed.