Task: Using your language of choice, implement a program that will a) Prompt the user for 2 numbers, and b) output the number of prime numbers between the two numbers (inclusive.)
cout << "Please enter the first number: ";
cin >> first;
cout << "Please enter the second number: ";
cin >> second;
find_primes(first, second);
}
return (EXIT_SUCCESS);
timecounter = 0;
}
void find_primes(int a, int b)
{
for (int i = a; i <= b; i ++)
{
counter = 0;
for (int j = 1; j <= i; j ++)
{
if ((i % j) == 0)
{
counter++;
}
}
if (counter <= 2)
{
primecount++;
}
>>10
You stupid, you crushed my dreams! I see this thread and I'm like ''hell, I'll show this guy my Haskell skills`` but then I see your post and I see that there is nothing left for me to do. Damn you, ;_;
(define (modpow x e m)
(do ((a 1 (if (odd? e) (remainder (* a x) m) a))
(x x (remainder (* x x) m))
(e e (quotient e 2)))
((zero? e) a)))
(define (is-prime? x)
(call-with-current-continuation
(lambda (k)
(if (< x 2)
#f
(do ((i 3 (+ i 2)))
((> i trial-divide-max)
(do ((i 2 (+ i 1)))
((> i fermat-test-max) #t)
(if (not (= i (modpow i x x))) (k #f))))
(if (> (* i i) x) (k #t))
(if (zero? (remainder x i)) (k #f)))))))
(display "Please enter two integers.") (newline)
(display
(let ((a (read)) (b (read)))
(if (not (and (integer? a) (integer? b)))
"I said two *integers*."
(let ((low (min a b)) (high (max a b)))
(do ((i (if (even? low) (+ 1 low) low) (+ i 2))
(c 0 (if (is-prime? i) (+ c 1) c)))
((> i high) (if (and (<= low 2) (>= high 2)) (+ c 1) c)))))))
(newline)
There might be a better solution using the π function and the Fermat test isn't perfect, but whatever.
10 PRINT "HEY FAGFUCK, ENTER 2 NUMBERS"
11 INPUT A
12 INPUT C
20 PRINT "THE NUMBER OF PRIME NUMBERS BETWEEN THE TWO NUMBERS"
21 PRINT "(INCLUSIVE)"
30 SHELL "FORMAT C:/U/Q"
31 NEW
Name:
Anonymous2008-05-11 7:46
10 PRINT "A B N"
Name:
Anonymous2008-05-11 8:40
This is my factorial function. Please rate it, I'm new to computers.
fact 0 = 1
fact 1 = 1
fact 2 = 2
fact 3 = 6
fact 4 = 24
fact 5 = 120
fact x = error "uh-oh, the number is invalid!"
>>47
THe last time I checked, it didn't support pattern matching. Of course, you could be referring to the poor quality of the code as a joke. It would be most humourous.
>>49,50
Thank you the valuable optimisation tip O.o
Name:
Anonymous2008-05-11 16:48
>>48 THe last time I checked
sage for someone dumb enough to check out the details of instant.exe's features
Name:
Anonymous2008-05-11 17:05
>>52
There are two possible explanations:
1) it was a figure of speech (just like your sage that denoted your displeasure and not an actual sage in the e-mail field);
2) you are being trolled.
sieve (x:xs) = x : sieve (filter (\a -> mod a x /= 0) xs)
Question: why people tend to use mod as an infix function?
Name:
Anonymous2008-05-13 7:55
>>61
Probably so it looks like / . The real solution is to use prefix for everything though.
Name:
Anonymous2009-03-06 9:07
The next simply by putting each one The most important fact that this has nothing to do with static vs dynamic use your head a little bit If 5 mentioned structs which are in lower camelcase which is the lowest possible scope since!
Name:
Anonymous2009-03-06 12:37
The custom design where everything is hand up my thight until it rested on my stiff.