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

even number code

Former Member
0 Likes
3,945

Hi ,

i am writing code for getting even numbers from 1 to 100.

biut i am always getting 0.

below i am writing my code if any one can correct me.

data : n type i value 0,

m type i .

do 100 times.

n = n + 1.

*m = m + 1.

m = ( n mod 2 ).

if m = 0.

write 😕 'even',m.

endif.

enddo.

regards,

karan

1 ACCEPTED SOLUTION
Read only

ThomasZloch
Active Contributor
0 Likes
1,736

> write 😕 'even',m.

->

> write 😕 'even',n.

10 REPLIES 10
Read only

ThomasZloch
Active Contributor
0 Likes
1,737

> write 😕 'even',m.

->

> write 😕 'even',n.

Read only

Former Member
0 Likes
1,736

dude .... u are display the value of M man ... display 'N' ...

data : n type i value 0,

m type i .

do 100 times.

n = n + 1.

*m = m + 1.

m = ( n mod 2 ).

if m = 0.

write 😕 'even',n.

endif.

enddo.

Thanks,

Aditya. V

Read only

Former Member
0 Likes
1,736

correct code

data : n type i value 1,

m type i .

do 100 times.

n = n + 1.

*m = m + 1.

m = ( n mod 2 ).

if m = 0.

write 😕 'even',n. "change line

endif.

enddo.

Read only

abdul_hakim
Active Contributor
0 Likes
1,736

Here is the code for you.

data: no1 type i,

no2 type i.

do 100 times.

no1 = no1 + 1.

no2 = no1 mod 2.

if no2 eq 0.

write:/ 'Even:', no1.

endif.

enddo.

Cheers,

Hakim

Read only

Former Member
0 Likes
1,736

HI,

data : n type i value 0,

m type i .

DO 50 TIMES.

M = N MOD 2.

IF M = 0.

WRITE:/ N,

'EVEN'.

ENDIF.

N = N + 1.

enddo.

Read only

Former Member
0 Likes
1,736

Hi,

you can simply do like this:

data : n type i.

do 50 times.

n = 2 * sy-index.

write 😕 'even', n.

enddo.

Regards,

Neha

Read only

Former Member
0 Likes
1,736

Hi,

You can do like this also.

DATA : n TYPE i.

DATA: a TYPE i VALUE 0.

WRITE 'List Of Even Nos.'.

DO 50 TIMES.

a = a + 1.

n = 2 * a.

WRITE / n.

ENDDO.

Thanks

Read only

Former Member
0 Likes
1,736

dont forget to mark the thread as answered once ur issue gets solved

Read only

former_member224008
Active Participant
0 Likes
1,736

hi karan,

data : n type i value 0,

m type i .

do 100 times.

n = n + 1.

*m = m + 1.

m = ( n mod 2 ).

if m = 0.

write 😕 'even',m. "change to write 😕 'even',n.

endif.

enddo.

regards,

ARUN

Read only

0 Likes
1,736

This message was moderated.