×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# How to handle large Primes ( longer than 16 digits ) ?

## How to handle large Primes ( longer than 16 digits ) ?

(OP)
I have written a simple QBASI program that checks if a number is Prime.
But the program cannot handle numbers larger than 16 digits.
Is there a way I can use QBASI to check for Primes greater than 16 digits long?

My program below:

10 REM Prime Tester 7B
20 COLOR 15, 0, 0
30 DIM P AS _FLOAT
40 DIM N AS _FLOAT
60 INPUT "Number"; N
65 START = TIMER
70 IF N <= 0 GOTO 999
75 IF N = 1 THEN PRINT "Sorry! 1 is in the Unitary Group": GOTO 20
80 FOR P = 2 TO SQR(N)
90 IF N MOD P = 0 THEN PRINT "Composite": GOTO 130
100 NEXT P
110 COLOR 31, 0, 0
120 PRINT "Prime"
130 ELAPSED = TIMER - START
140 COLOR 15, 0, 0
150 PRINT "elapsed time is"; ELAPSED, "seconds"
160 BEEP
170 GOTO 20
999 END

Regards

pya

### RE: How to handle large Primes ( longer than 16 digits ) ?

#### Quote (pya)

Is there a way I can use QBASI to check for Primes greater than 16 digits long?

### RE: How to handle large Primes ( longer than 16 digits ) ?

(OP)
Hi Mikrom,

Unfortunately, I am still learning QBASIC and had a hard time understanding all the code.
Is there any tutorial that will guide me through it.

Regards

pya

### RE: How to handle large Primes ( longer than 16 digits ) ?

Hi Pya,
The idea of the link I mentioned, is to represent numbers as strings, but then you have to write your own functions like MOD() and SQRT() which you are using in your program, so that they work with large numerical strings.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!