Created
October 22, 2012 01:10
-
-
Save richo/3929157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* prime.c | |
* | |
* Created on: Oct 21, 2012 | |
* Author: emma | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
#define abs(x) ((x < 0) ? x *= -1 : x) | |
int isPrime(int x); | |
int main(int argc, char **argv) { | |
unsigned int temp; | |
int x = atoi(argv[1]); | |
x = abs(x); | |
temp = isPrime(x); | |
printf("Is %d prime: %d", x, temp); | |
return 0; | |
} | |
int isPrime(int x) { | |
if(x < 2) | |
return 0; | |
int temp = 1; | |
int i; | |
for(i = 2; i < x; i++) { | |
if(x % i == 0) | |
break; | |
else temp = 0; | |
} | |
return temp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment