Hi..
I want to make following series..
I try a lot but i am having confusion in loops. so please help me.

1
212
32123
4321234
So any one have idea about this .

Recommended Answers

All 4 Replies

Post what you have tried so far, even if it is not working.

Member Avatar for diafol

Increments and decrements, decisions, decisions! This can be done in a reasonably painless way with just a single increment. However, as MS says, show us yer code!

I have write this code.. but it is simple one.

<?php
for($a=1 ; $a<=5; $a++)
{
    for($b=5; $b>$a; $b--)
    {
        echo ".";
    }

    for($i=($a*2-1); $i>=1; $i--)
    {
        echo $i;


    }
    echo "<br>";
}
?>
Member Avatar for diafol

Nah, you just need to keep copying the previous answer and apply the next number front and end.

e.g. current number is 32123 (3rd go)
next number is 4 (4th go) & last number & 4 (4th go)
etc.

Don't know if that makes sense. Didn't want to give you the whole thing. I'd start with a default value of 1 for the output and then start incrementing on counter = 2.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.