on 09-19-2007 1:37 PM
Hi,
Can any one tell me the logic to print stars like this,
*
* *
* * * *
* *
*
using abap code?
Note: no. of maximum stars will be entered by user.
Regards,
Martina
Martina,
Try this program.
<b>
Note : p_star should be odd</b>
report z_test.
PARAMETERS: P_STAR TYPE I.
DATA lv_1 TYPE I.
DATA V_FLAG.
START-OF-SELECTION.
lv_1 = ( P_STAR / 2 ).
IF lv_1 = 0.
lv_1 = 2.
ELSE.
lv_1 = 1.
ENDIF.
DO P_STAR TIMES.
DO lv_1 TIMES.
WRITE: '*'.
ENDDO.
SKIP.
IF lv_1 = P_STAR.
V_FLAG = 'X'.
ENDIF.
IF V_FLAG IS INITIAL.
lv_1 = lv_1 + 2.
ENDIF.
IF V_FLAG IS NOT INITIAL.
lv_1 = lv_1 - 2.
ENDIF.
ENDDO.
p_star : 5
Output:
test
*
* *
* * * *
* *
*
I tested it, so it should work.
Regards
Aneesh.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
IF total * entered by user is "n" then develop the code like this
C_star = '*'
a = n/2.
Do n times.
IF a NE 0.
Do a times.
Write c_star.
Enddo.
ENDIF.
if a NE n.
a = a+2.
ELSE.
a = a - 2.
skip.
ENDDO.
Regards,
SaiRam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.