话不多说,直接上代码。
int printPrimaryNumber(int nUpperBound)
{
int iTotal = 0;
// Primary number start with 2.
for (int i = 2; i <= nUpperBound; i++)
{
bool isPrimary = true;
for (int j = 2; j < i; j++)
{
if (i % j == 0)
{
isPrimary = false;
break;
}
}
if (isPrimary)
{
iTotal++;
printf("%d, ", i);
}
}
printf("Total: %d.\n", iTotal);
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-13 07:12:31