Lesson 15 of 23
seq
The seq Command
seq prints a sequence of numbers, one per line:
$ seq 1 5
1
2
3
4
5
It takes a first and last value and counts up from one to the other.
Your Implementation
Write void my_seq(int first, int last) that prints integers from first to last inclusive, one per line.
void my_seq(int first, int last) {
for (int i = first; i <= last; i++)
printf("%d\n", i);
}
That is all there is to it. A simple for loop.
Going Backwards
The real seq also supports counting down when first > last by accepting a negative step:
$ seq 5 -1 1
5
4
3
2
1
Our version keeps it simple — just first to last counting upward.
Your Task
Implement my_seq that prints integers from first to last, one per line.
TCC compiler loading...
Loading...
Click "Run" to execute your code.