You are not logged in.
Pages: 1
Any one can print this
******* *******
****** * ******
***** * *****
**** * * * ****
*** * ***
** * **
* *
Last edited by Zeeshan 01 (2018-06-22 15:30:53)
Malik
Offline
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
In which programming language do you want the loop program to be written?
I prefer Java.
Last edited by Zeeshan 01 (2018-06-22 15:34:03)
Malik
Offline
Hi;
Any one can print this
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
Help me
By using loops
In which programming language do you want the loop program to be written?
Zeeshan 01 wrote:I prefer c or cpp....
For ,,while or do while !!!
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.
EDIT: Here's a slightly more streamlined version:
a$="*******":b$=" ":c=7
WHILE c>0
PRINT RIGHT$(a$,c)+b$+RIGHT$(a$,c)
c=c-1:b$=b$+" "
WEND
...and another variation:
a$="*******":b$=" "
WHILE LEN(a$)>0
PRINT a$+b$+a$
a$=RIGHT$(a$,LEN(a$)-1)
b$=b$+" "
WEND
All three programs give the following output:
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
Last edited by phrontister (2018-11-22 23:01:47)
"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
Online
b$=" ":c=7
B is empty???
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.
EDIT: The following code explanation is for the first program in my previous post.
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.
Last edited by phrontister (2018-11-24 02:22:43)
"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
Online
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 (2018-11-22 23:04:30)
"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
Online
Hi Zeeshan 01;
Any one can print this
******* *******
****** * ******
***** * *****
**** * * * ****
*** * ***
** * **
* *
I thought I'd give your new puzzle a go, but unlike with your original puzzle, a simple solution has me stumped this time because it seems to lack symmetry now that you've added that internal cross. It's trickier now...hence your change of the thread title from "Help in simple prob of loop" to "Complex Loop", I suppose.
Thanks for help but I need c language code
I still don't know c, nor the other two programming languages you mentioned (cpp and Java); but anyway, in case it helps someone, here's my effort in BASIC, based on my first solution to your original puzzle:
EDIT: It's closer to the second solution, actually.
a$="*******":c=7
WHILE c>0
IF c=7 THEN b$=" "
IF c=6 THEN b$=" * "
IF c=5 THEN b$=" * "
IF c=4 THEN b$=" * * * "
IF c=3 THEN b$=" * "
IF c=2 THEN b$=" * "
IF c=1 THEN b$=" "
PRINT RIGHT$(a$,c)+b$+RIGHT$(a$,c)
c=c-1
WEND
My program's output:
******* *******
****** * ******
***** * *****
**** * * * ****
*** * ***
** * **
* *
Last edited by phrontister (2018-11-25 00:06:37)
"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
Online
Pages: 1