Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2017-01-11 04:34:09

Zeeshan 01
Member
Registered: 2016-07-22
Posts: 518

Help in simple prob of loop

Hi  any one can print this
*******   *******
******      ******
*****         *****   
****            ****
***               ***
**                  **
*                     *
Help me
By using loops


Math !!!!.

Offline

#2 2017-01-11 23:36:32

iamaditya
Member
From: Planet Mars
Registered: 2016-11-15
Posts: 617

Re: Help in simple prob of loop

In which programming language do you want the loop program to be written?


Practice makes a man perfect.
There is no substitute to hard work
All of us do not have equal talents but everybody has equal oppurtunities to build their talents.-APJ Abdul Kalam

Offline

#3 2017-01-12 04:40:02

Zeeshan 01
Member
Registered: 2016-07-22
Posts: 518

Re: Help in simple prob of loop

I prefer c or cpp....

For ,,while or do while !!!


Math !!!!.

Offline

#4 2017-01-12 18:28:23

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,568

Re: Help in simple prob of loop

Hi;

I don't know c or cpp, but here's a code in BASIC that will do it...

    a$="*******":b$="                     ":c=7:d=1
    While c>0
        Print Right$(a$,c)+Right$(b$,d*3)+Right$(a$,c)
        c=c-1:d=d+1
    WEnd

It runs in LibertyBASIC (paid software) and JustBASIC (freeware), but in most other BASIC programs the code will need some tweaking to work.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

#5 2017-01-12 19:37:52

Zeeshan 01
Member
Registered: 2016-07-22
Posts: 518

Re: Help in simple prob of loop

Thanks for help but I need c language code


Math !!!!.

Offline

#6 2017-01-12 19:38:56

Zeeshan 01
Member
Registered: 2016-07-22
Posts: 518

Re: Help in simple prob of loop

b$="                     ":c=7
B is empty???


Math !!!!.

Offline

#7 2017-01-12 20:50:49

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,568

Re: Help in simple prob of loop

No, b$ isn't empty: it contains 21 blank spaces.

Each of the seven lines of printing in your first post contains two equal groups of asterisks that are separated by a group of blank spaces. Line 1 has 3 blank spaces, increasing by 3 in each subsequent line until reaching 21 blank spaces in the last (7th) line.

Right$(b$,d*3) for line 1 selects the right-most 3 blank spaces from b$, and, using the increasing value of d, for each subsequent loop selects 3 more spaces from b$ than for the previous line.

Right$(a$,c) for line 1 selects the right-most 7 asterisks from a$, and, using the reducing value of c, for each subsequent loop selects 1 less asterisk from a$ than for the previous line.

Btw, here is the output from my program: 

*******   *******
******      ******
*****         *****
****            ****
***               ***
**                  **
*                     *

Last edited by phrontister (2017-01-12 21:24:49)


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

#8 2017-01-12 20:57:05

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,568

Re: Help in simple prob of loop

Here's a different method...

    a=8:b=0
    While a>1
        a=a-1:b=b+3
        For aa=1 To a
            Print "*";
        Next aa
        For bb=1 To b
            Print " ";
        Next bb
        For aa=1 To a
            Print "*";
        Next aa
        Print
    WEnd

And the output:

*******   *******
******      ******
*****         *****
****            ****
***               ***
**                  **
*                     *

Last edited by phrontister (2017-01-12 21:00:48)


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

#9 2017-01-12 21:42:01

Zeeshan 01
Member
Registered: 2016-07-22
Posts: 518

Re: Help in simple prob of loop

It takes time to understand this  code!!,


Math !!!!.

Offline

Board footer

Powered by FluxBB