undefined, n == INT_MAX - .
Note that both loops will output a space after the last number before the new line, which may be incorrect.
You can solve both problems with one additional test:
void print_odd_integers(int n) {
for (int i = 1; i <= n; i += 2) {
printf("%d", i);
if (i == n)
break;
}
printf("\n");
}
source
share