Application Development 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: 

Finding Prime Numbers from 1 to 100

Former Member
0 Kudos

Hi Friends

I want to get prime numbers from 1 to 100, please help me, how to develop logic.

Regards

Praveen

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Praveen, look at the following report

&----


*& Report ZTEST_PNUM *

*& *

&----


*& *

*& *

&----


REPORT ZTEST_PNUM .

PARAMETERS : start(16) TYPE p DECIMALS 0 DEFAULT 1,

endnum(16) TYPE p DECIMALS 0 OBLIGATORY DEFAULT 100.

TYPES ans(16) TYPE p DECIMALS 0.

DATA ans(16) TYPE p DECIMALS 0.

DATA itab TYPE TABLE OF ans.

DATA wa TYPE ans.

DATA wa_1(16) TYPE p DECIMALS 0.

DATA wa_2 TYPE ans.

DATA wa_3(16) TYPE p DECIMALS 0.

DATA wa_4(16) TYPE p DECIMALS 0.

START-OF-SELECTION.

DO .

CLEAR wa_4.

wa_3 = 1.

wa_1 = sqrt( wa_2 ).

WHILE wa_3 <> 0.

ADD 1 TO wa_4.

IF wa_4 > wa_1 AND wa_2 <> 4.

EXIT.

ENDIF.

IF wa_4 > 1.

wa_3 = wa_2 MOD wa_4.

ENDIF.

ENDWHILE.

IF wa_3 <> 0 and wa_2 > 0.

APPEND wa_2 TO itab.

ENDIF.

ADD 1 TO wa_2.

IF wa_2 = endnum.

EXIT.

ENDIF.

ENDDO.

LOOP AT itab INTO wa.

WRITE: / sy-tabix, wa.

ENDLOOP.

Hope it will give you the solution.

Don't forget to reward points if this code solves your issue.

Regards.

Naveen

3 REPLIES 3

Former Member
0 Kudos

Former Member
0 Kudos

Praveen, look at the following report

&----


*& Report ZTEST_PNUM *

*& *

&----


*& *

*& *

&----


REPORT ZTEST_PNUM .

PARAMETERS : start(16) TYPE p DECIMALS 0 DEFAULT 1,

endnum(16) TYPE p DECIMALS 0 OBLIGATORY DEFAULT 100.

TYPES ans(16) TYPE p DECIMALS 0.

DATA ans(16) TYPE p DECIMALS 0.

DATA itab TYPE TABLE OF ans.

DATA wa TYPE ans.

DATA wa_1(16) TYPE p DECIMALS 0.

DATA wa_2 TYPE ans.

DATA wa_3(16) TYPE p DECIMALS 0.

DATA wa_4(16) TYPE p DECIMALS 0.

START-OF-SELECTION.

DO .

CLEAR wa_4.

wa_3 = 1.

wa_1 = sqrt( wa_2 ).

WHILE wa_3 <> 0.

ADD 1 TO wa_4.

IF wa_4 > wa_1 AND wa_2 <> 4.

EXIT.

ENDIF.

IF wa_4 > 1.

wa_3 = wa_2 MOD wa_4.

ENDIF.

ENDWHILE.

IF wa_3 <> 0 and wa_2 > 0.

APPEND wa_2 TO itab.

ENDIF.

ADD 1 TO wa_2.

IF wa_2 = endnum.

EXIT.

ENDIF.

ENDDO.

LOOP AT itab INTO wa.

WRITE: / sy-tabix, wa.

ENDLOOP.

Hope it will give you the solution.

Don't forget to reward points if this code solves your issue.

Regards.

Naveen

0 Kudos

This message was moderated.