Skip Multiples
Completed
Read n and k. Print 1..n on one line, skipping multiples of k using continue.
Input
Two integers.
Output
One line.
Example
Input
10 3
Output
1 2 4 5 7 8 10
Editor
C
Hints
continue jumps to the next iteration.
Solution explanation
A first flag avoids a leading space.
Show solution
#include <stdio.h>
int main() {
int n, k, first = 1;
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
if (i % k == 0) continue;
if (!first) printf(" ");
printf("%d", i);
first = 0;
}
printf("\n");
return 0;
}