Jump to content

School Assinments


randymartin

Recommended Posts

Ok i've done the first half for you...

 

<?php
for ($count = 1; $count <= 5; $count +=1) {
for ($i = 1; $i <= $count; $i ++) {
echo $count;
}
echo "<br />";
}
?>

 

Considering it's school work might be best for you to try and resolve the second half yourself.

 

Matt

 

 

 

Thanks m8 i will try to fix it ;) many thanks

Link to comment
Share on other sites

Thanks m8 i will try to fix it ;) many thanks

 

No worries.

 

The first for statement is the one which will need to be changed.

 

Basically set the loop count to the maximum loops you require. Then set the lowest times to loop (1) and then set the final variable to deduct 1 each time instead of add 1.

 

It will end up looking like;

 

for ($count = 5; $count >= 1; $count -=1) {

 

That's it. Just make sure you comment your code and give the variables valid names or they'll wonder how you did it...

Edited by matthewtbaker
Link to comment
Share on other sites

No worries.

 

The first for statement is the one which will need to be changed.

 

Basically set the loop count to the maximum loops you require. Then set the lowest times to loop (1) and then set the final variable to deduct 1 each time instead of add 1.

 

It will end up looking like;

 

for ($count = 5; $count >= 1; $count -=1) {

 

That's it. Just make sure you comment your code and give the variables valid names or they'll wonder how you did it...

 

youre awesome, i am doing ict, aducation but first six week is an introduction for people that would like to chose application development and since i am so bad at php it is not for me, but you have to make the assignments still got 2 left i have to make this one,

 

1

23

345

4567

56789

 

i really have no idea how you can make it haha :(

Link to comment
Share on other sites

1

23

345

4567

56789

 

i really have no idea how you can make it haha :(

 

Start by creating a description of the rules for the pattern as you would describe to another human. Then figure out how you will do it in the code. In this case I would describe it as follows:

 

Starting with the number 1, perform the following process for 5 iterations:

On each iteration create a number that

1) starts with the digit matching the iteration count

2) contains sequentially numbered digits up to the same number as the iteration count

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.