话不多说。直接上代码。
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;}