You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

68 lines
944 B

// Objective C version of a Prime Number Finder
// haplo@mindstab.net
#include <objc/Object.h>
#include <stdio.h>
#include "math.h"
@interface Primes
{
}
- (void)print:(unsigned int)MAX;
+ (id)alloc;
- (id)init;
@end
@implementation Primes
+ (id)alloc
{
return self;
}
- (id)init
{
return self;
}
- (void)print:(unsigned int)MAX
{
unsigned int cnt, test, i;
char isPrime;
for( cnt = 3; cnt <= MAX; cnt +=2)
{
test = (unsigned int)sqrt(cnt);
isPrime = 1;
for(i=3; i<= test; i+=2)
{
if( !(cnt%i))
{
isPrime=0;
break;
}
}
if(isPrime) {
printf("%d\n", cnt);
}
}
}
@end
int main(int argc, char **argv)
{
unsigned int max;
Primes *primes;
if(argc <= 1) {
printf("Useage: primesobjc [Max Num]\n");
return(1);
}
max = atoi(argv[1]);
if(max<1) {
printf("Invalid Max Num\n");
return(1);
}
printf("allocing\n");
primes = [[Primes alloc] init];
printf("calling\n");
[primes print:max];
}