Microsoft KB Archive/153200

= How To Determine Whether a Number is Prime =

Article ID: 153200

Article Last Modified on 12/1/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft FoxPro 2.5b for Macintosh
 * Microsoft Visual FoxPro 2.5c for Macintosh
 * Microsoft FoxPro 2.6a Professional Edition for Macintosh
 * Microsoft FoxPro 2.0
 * Microsoft FoxPro 2.5b for MS-DOS
 * Microsoft FoxPro 2.5a
 * Microsoft FoxPro 2.5b for MS-DOS
 * Microsoft FoxPro 2.6 for MS-DOS
 * Microsoft FoxPro 2.6a Standard Edition
 * Microsoft FoxPro 2.6 for SCO/UNIX
 * Microsoft Visual FoxPro 3.0 for Macintosh

-



This article was previously published under Q153200



SUMMARY
There is no single function in FoxPro or Visual FoxPro that determines whether a number is prime. This article describes how to use a program that allows you to enter a positive number and then reports if that number is prime.



MORE INFORMATION
A prime number is a number divisible only by one and itself. The following program uses the MODand ABS functions along with a For...Next loop to check if a number is prime: CLEAR SET TALK OFF x=0 @ 1,10 SAY "Please enter a positive integer" GET x   READ x=ABS(x) FOR i=2 to x-1 IF MOD(x,i)=0 @2,10 SAY "The number "+ ALLTRIM(STR(x))+ " is not prime." RETURN ENDIF ENDFOR @ 2,10 SAY "The number "+ ALLTRIM(STR(x))+ " is prime." SET TALK ON While this program uses the READ statement for backward compatibility with FoxPro 2.x versions, the basic algorithm may be used in a form within Visual FoxPro.

Additional query words: VFoxWin VFoxMac

Keywords: KB153200

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.