|
Answer» How WOULD I create an "IF" syntax that if I had a number and DIVIDED it by another number my batch file would do [glb]one[/glb] thing if the result:
WAS a WHOLE number NOT equal to 1
and [glb]another[/glb] output if the result:
WAS NOT a WHOLE number NOT equal to 1
for example
5/2= Not Whole 6/2= 3 - Whole 7/7= 1 - Have same return as Not Whole
I am writing a batch file to generate prime numbers Please help me I will refine the number througr steps in division and eventually ECHO it back if it [glb]IS[/glb] prime
Thanks For Anything You Might Have Sigma Batch language can only do integer arithmetic in W2K or XP, but there is no functionality for floating point division. You either need to use one of many programming languages or one of many scripting languages availabe to Windows.
Get back to us if you need further ASSISTANCE. So is there any way to do division at [glb]ALL[/glb]?
for ex.)
if 25 divided by 5 == 5 (goto start)
Thanks for any help SigmaYou can do some math with set /a
set /a 25/5
But it isn´t working if it is not an integer.
uliIT WORKED I finally got mt batch file to echo [glb]ONLY PRIME NUMBERS[/glb]
Dont believe me? Check the math...
25507 25511 25513 25517 25519 25523 25531 25537 25541 25547 25549 25553 25559 25561 25567 25573 25577 25579 25583 25589 25591 25597 25601 25603 25607 25609 25619 25621 25631 25633 25637 25639 25643 25649 25651 25657 25661 25663 25667 25673 25679 25681 25687 25691 25693 25699 25703 25709 25717 25721 25723 25727 25729 25733 25741 25747 25751 25757 25759 25763 25769 25771 25777 25783 25787 25789 25793 25799 25801 25807 25811 25813 25817 25819 25829 25831 25841 25843 25847 25849 25853 25859 25861 25867 25871 25873 25877 25883 25889 25891 25897 25901 25903 25909 25913 25919 25927 25931 25933 25937 25939 25943 25951 25957 25961 25967 25969 25973 25979 25981 25987 25993 25997 25999
Thanks for all the help Sigma
I hate to burst your bubble, but the very first three prime numbers on your list are not prime. A noble try, but using the integer math available in batch language cannot solve this. There is no way to isolate the remainders.
A simple script, NEVER to be confused with a C program that can handle huge numbers, might go something like this:
Code: [Select] For i = 1 to 1000000 primeflag = "y" For j = 2 to i / 2 If i mod j = 0 Then primeflag = "n" Exit For End If Next If primeflag = "y" Then WScript.Echo i & " is prime" WScript.Sleep 100 Next
The code is only valid to 1 million and basically uses simple arithmetic, but it might give you some ideas. You can get a list of the first 10,000 primes from:
http://www.math.utah.edu/~alfeld/math/p10000.html
Well... perhaps my number sorter wasn't comprehensive enough... This was the process I used:
If CMD divides a number and it isn't whole it rounds DOWN 1. By comparing the output to what it should have been, I refined a number by dividing that number by and only by... [glb]2,3,5 and 7[/glb] I thought that if a number WASN'T divisible by 2,3,5 or 7 that it was prime. Is this correct? Any suggestions? Thanks for any help Sigma
ps.) what would you do w/ that C program to run it?Prime numbers are those which have only themselves and one as divisors. The code above is a VB Script not a C program. To use it, CUT and paste the code into your editor (notepad will work fine), save it with vbs extension. Run in a cmd box:
cscript scriptname.vbs
The Sleep command will slow down processing, but will allow you to see the prime numbers as they go by. The script also gets progressively slower over time since many more divisions are necessary.
Note: I wrote this script down and dirty; if you find a bug, LET me know.
|