- 论坛徽章:
- 1
|
回复 1楼 dbcat 的帖子
/* 求质数 */
#define DEBUG 0
#include <ctype.h>
#include <stdio.h>
#include <sys/types.h>
typedef unsigned long ulong;
typedef unsigned int uint;
typedef unsigned char uchar;
#define MAXSAM 0x20
#define MAXLINE 0x100
char buf1[MAXLINE];
FILE *fp1;
FILE *fp2;
ulong llimit;
ulong hlimit;
int hex=0;
main(ac,av)
int ac;
char *av[];
{ char *si;main(ac,av)
int ac;
char *av[];
{ char *si;
char *fname;
char *agbuf[MAXSAM];
ulong i;
ulong j,k;
if(ac == 1)
{ printf("Usage: zpkop [-x] [-lnnnn] [-hmmmm]\n");
exit(1);
}
llimit = 0 ;
hlimit = 0xffffffff;
j = 0;
for(i = 1; i < ac; i++)
{ si = av[i];
if(*si != '-')
{ agbuf[j++] = av[i];
}
else
{ switch(*(si+1))
{ case 'h': /* fname borrow for xdigit */
fname = *(si+2)? si+2 : av[++i];
sscanf( fname,hex?"%lx":"%ld",&hlimit);
break;
case 'l':
fname = *(si+2)? si+2 : av[++i];
sscanf( fname,hex?"%lx":"%ld",&llimit);
break;
case 'x':hex=1; break;
default:printf("parameter error!\n");
exit(1);
}
}
}
if(hlimit < llimit)
{ printf("Invalid limit values!\n");
exit(1);
}
for(i=llimit;i<hlimit;i++)
{ if((i&1)==0) continue;
j= i/2;
for(k=2; k<j; k++)
{ if((i%k)==0) goto cont;
}
printf(hex?"0x%lx\n":"%ld\n",i);
cont:;
}
}
4,4 顶端 |
|