Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C Program

Name: Anonymous 2008-09-25 14:26

Programming newfag here. I'm trying to make a c program that determines whether a number is prime. It isn't working properly though. It only indicate that the number is not prime, regardless of the number, so something wrong. Anybody can help?

#include<stdio.h>

int main(void)
{

    int number;
    int count;
    int divisor = 2;
   
    printf("Input number for primality testing\n");
    scanf("d",number);
   
    while (divisor < number/2) {   
        if (number % divisor == 0) {
            break;   
        }
        else
            divisor++;
    }

    if (divisor == number/2) {
        printf("Number is prime\n");
    }
    else {
        printf("Number is not prime\n");
    }
    return 0;
}

Name: Anonymous 2008-09-25 23:21

isPrime   :: Integer -> Bool
isPrime x | x <= 2    = True
          | otherwise = isPrime' 2 x

isPrime'     :: Integer -> Integer -> Bool
isPrime' y x | x `mod` y == 0 = False
             | y*y < x        = True && isPrime' (y+1) x
             | otherwise      = True

main = do print $ zip [0..100] (map isPrime [0..100])

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List