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
for (int i = 1; i <= n; i++) counts from 1 to n.
Solution explanation
A for loop has three parts: start, condition and step.
Show solution
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
printf("%d", i);
if (i < n) printf(" ");
}
printf("\n");
return 0;
}