Count to N
Completed
Read n and print 1 to n separated by spaces.
Input
One integer ≥ 1.
Output
One line.
Example
Input
5
Output
1 2 3 4 5
Editor
C++
Hints
Print a space after every number except the last.
Solution explanation
The conditional operator picks the separator.
Show solution
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cout << i << (i < n ? " " : "\n");
}
return 0;
}