#define __STDC_WANT_LIB_EXTl__ 1
#include <stdio.h>
#include <stdlib.h>
typedef enum {false=0,true=1}bool;
/*
#define bool int
#define true 1
#define false 0
和上述一致均是为了声明bool的头文件,代替了stdbool.h
*/
int main(void)
{
unsigned long long *pPrimes =NULL;
unsigned long long trial =0;
bool found =false;
int total=0;
int count=0;
int i;
printf("How many........");
scanf_s("%d",&total); //比scanf安全
total=total<4?4:total;
pPrimes=(unsigned long long*)malloc(total*sizeof(unsigned long long));
if (!pPrimes)
{
printf("not enough...
");
return 1;
}
*pPrimes=2ULL;
*(pPrimes +1)=3ULL;
*(pPrimes+2)=5ULL;
count =3;
trial =5LL;
while (count<total)
{
trial+=2ULL;
for(i=1;i<count;i++)
{
if(!(found=(trial%*(pPrimes + i))))
break;
}
if(found)
*(pPrimes+count++)=trial;
}
for (i=1;i<total;i++)
printf("%12llu",*(pPrimes + i));//%llu对应的数据类型为unsigned long long,这是C语言用来表示整数的最大类型
if(!(i+1)%5)
printf("
");
}
printf("
");
free(pPrimes);
pPrimes=NULL;
system("pause");
return 0;
}