Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How we can find the prime number

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
mauvis

New User


Joined: 27 Jul 2007
Posts: 11
Location: india

PostPosted: Wed Aug 29, 2007 12:34 am    Post subject: How we can find the prime number
Reply with quote

Can anyone tell me how we can find the prime number?

i need a simple logic...i need to accept a number through the JCL and have to check through cobol for prime no...

Mauvis
Back to top
View user's profile Send private message

superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4650
Location: Raleigh, NC, USA

PostPosted: Wed Aug 29, 2007 12:40 am    Post subject: Reply to: prime number
Reply with quote

A Google search led to this website which has an example program.
Back to top
View user's profile Send private message
Balraj

New User


Joined: 16 Aug 2007
Posts: 34
Location: Bangalore

PostPosted: Wed Aug 29, 2007 10:29 am    Post subject:
Reply with quote

Logic

Accept A

Perform varying i from 2 by 1 untill i > A

Divide A by i giving c remainder D
if D = 0
Not a prime
stop run
End-if
end-perform
A is a prime no.
stop run.
Back to top
View user's profile Send private message
himanshupant

New User


Joined: 21 Mar 2007
Posts: 46
Location: India

PostPosted: Tue Sep 25, 2007 1:20 pm    Post subject: after thought
Reply with quote

Just an afterthought , most of the times mainframe question / queries have some underlying Business requirement which needs to be satisfied , what was the business requirement behind this...


As for prime number bit , we can repeatedly divide the number ( Say x ) from 2 till x/2 and if in any of the case it divides exactly then its not a prime. We need not divide it till the number x.. This will reduce the number of iterations through loop

Correct me if I am wrong
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Tue Sep 25, 2007 1:27 pm    Post subject:
Reply with quote

Hi himanshupant,

Code:
As for prime number bit , we can repeatedly divide the number ( Say x ) from 2 till x/2 and if in any of the case it divides exactly then its not a prime. We need not divide it till the number x.. This will reduce the number of iterations through loop



For prime number there is no need to divide till the number x/2 we can repeatedly divide the number til √x
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Tue Sep 25, 2007 1:28 pm    Post subject:
Reply with quote

Hi All,

In my prev post i mean till square root of X
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Command to find TMEMBER name for a TPIPE Siva NKK Kothamasu IMS DB/DC 0 Wed Aug 16, 2017 6:08 pm
No new posts Profile changed to NUMBER ON STD (fro... Martylin TSO/ISPF 1 Thu Aug 03, 2017 9:14 am
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts SMTP the current generation number of... Jyothi Kulunde JCL & VSAM 4 Thu May 04, 2017 4:08 pm
No new posts To find out size allocated to a seque... ashek15 JCL & VSAM 15 Thu Apr 27, 2017 9:42 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us