Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Program

Former Member
0 Likes
1,115

Hi,

Can some one tell me how to write these 2 programs

1. Accept 2 Numbers from the user and display all the odd numbers in that range.

2. Display the first 10 numbers in Fibonace series.

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
990

HI,

<b>1)check this for even numbers in the entered range</b>

PARAMETERS:num1 type i,

num2 type i.

data:temp type i.

temp = num1.

num1 = num1 / 2.

num1 = num1 * 2.

if num1 = temp.

while temp <= num2.

write:/ temp.

temp = temp + 2.

endwhile.

else.

temp = temp + 1.

while temp <= num2.

write:/ temp.

temp = temp + 2.

endwhile.

endif.

<b>2)check this for febanaci series</b>

data:num type i value 0.

data:temp_1 type i value 1,

temp_2 type i.

write:/ num.

do 9 times.

temp_2 = temp_1.

temp_1 = num.

num = temp_1 + temp_2.

write:/ num.

enddo.

rgds,

bharat.

6 REPLIES 6
Read only

Former Member
0 Likes
990
  • Selection Screen Elements.

PARAMETERS:

p_number(2) TYPE n. " Input Number

  • Data Declarations.

DATA:

w_num1 TYPE i VALUE 0,

w_num2 TYPE i VALUE 1,

w_num3 TYPE i,

w_count TYPE i VALUE 0.

IF p_number GT 45.

WRITE: 'Enter an input less than 45'.

ELSEIF p_number LE 0.

WRITE: 'Dont enter negative numbers'.

ELSE.

WHILE w_count LT p_number.

w_num3 = w_num1 + w_num2.

w_num1 = w_num2.

w_num2 = w_num3.

w_count = w_count + 1.

WRITE w_num3. " Generates Fibonacci Series.

ENDWHILE.

ENDIF.

-


data: w_i type i value 0.

parameters:

w_num1 type i,

w_num2 type i.

add w_num1 to w_i.

if w_i lt w_num2.

if w_i % 2 = 1.

write: /10 w_i.

add 1 to w_i.

endif.

endif.

Regards,

Pavan

Read only

former_member189059
Active Contributor
0 Likes
990

<b>FIBONACCI</b>

data: lv_one type i value 0.
data: lv_two type i value 1.
data: lv_last type i value 1.


write:/ lv_one.
write:/ lv_two.
do 20 times.   " change 20 as required
  lv_last = lv_one + lv_two.
  lv_one = lv_two.
  lv_two = lv_last.
  write:/ lv_last.
enddo.

Read only

Former Member
0 Likes
991

HI,

<b>1)check this for even numbers in the entered range</b>

PARAMETERS:num1 type i,

num2 type i.

data:temp type i.

temp = num1.

num1 = num1 / 2.

num1 = num1 * 2.

if num1 = temp.

while temp <= num2.

write:/ temp.

temp = temp + 2.

endwhile.

else.

temp = temp + 1.

while temp <= num2.

write:/ temp.

temp = temp + 2.

endwhile.

endif.

<b>2)check this for febanaci series</b>

data:num type i value 0.

data:temp_1 type i value 1,

temp_2 type i.

write:/ num.

do 9 times.

temp_2 = temp_1.

temp_1 = num.

num = temp_1 + temp_2.

write:/ num.

enddo.

rgds,

bharat.

Read only

gopi_narendra
Active Contributor
0 Likes
990

Fibonacci Series.

DATA : v1 TYPE i,
v2 TYPE i,
v3 TYPE i,
count TYPE i.
v1 = 0.
v2 = 1.
PARAMETER : n TYPE i.
WRITE : v1, v2.
DO n TIMES.
  count = count + 1.
  v3 = v1 + v2.
  WRITE v3.
  v1 = v2.
  v2 = v3.

  IF count = n.
    EXIT.
  ENDIF.
ENDDO.

Regards

Gopi

Read only

Former Member
0 Likes
990

try this for odd no


tables : CECUSF.
select-options : s_no for CECUSF-sliNE .
.

data : res type  i,
       temp type i,
       dif  type i.

compute res = s_no-low mod 2.


if s_no-low = s_no-high.
  if res = 0.
   write : / 'No odd no in this range'.
  else.
   write : / s_no-low.
  endif.
else.
dif = s_no-high - s_no-low.
temp = s_no-low.
do dif times.
compute res = temp mod 2.
 if res ne 0.
    write : / temp.
 endif.
temp = temp + 1.
enddo.
endif.

and for fibonace series


data : strt type i value 0,
       next type i value 1,
       res type i.


write : (3) strt, '.' ,(3) next,'.'.

do 5 times.
res = strt + next.
strt = res.
next = next + strt.
write : (3) strt, '.' ,(3) next,'.'.
enddo.

regards

shiba dutta

Read only

Former Member
0 Likes
990

report ztest_4.

Parameter p_one type i.

Parameter p_two type i.

Data w type i.

data var1 type i.

data diff type i.

diff = p_two - p_one.

Check diff GT 0.

Var1 = p_one.

Do diff times.

w = var1 mod 2 .

if not w is initial.

write var1.

endif.

var1 = 1 + var1.

enddo.