Series – Decreasing Limits
Print integers in decreasing limits from N to 1, then N-1 to 2, then N-2 to 3, and so on until the limits meet.
Understand the Problem
Problem Statement
Series – Decreasing Limits: The program must accept an integer N as the input. The program must print the integers from N to 1. Then the program must print the integers from N-1 to 2. Then the program must print the integers from N-2 to 3. Similarly, the program must print the integers in the remaining decreasing limits.
Constraints
- 1 ≤ N ≤ 500
- Output must be space-separated integers
- Each decreasing limit must be printed in sequence
Examples
66 5 4 3 2 1 5 4 3 2 4 3First prints 6 to 1 (6 5 4 3 2 1), then 5 to 2 (5 4 3 2), then 4 to 3 (4 3). The next would be 3 to 4, but since 3 < 4, the sequence stops.
55 4 3 2 1 4 3 2 3First prints 5 to 1 (5 4 3 2 1), then 4 to 2 (4 3 2), then 3 to 3 (3). The next would be 2 to 4, but since 2 < 4, the sequence stops.
Solution
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int start = n;
int end = 1;
while (start >= end) {
for (int i = start; i >= end; i--) {
printf("%d ", i);
}
start--;
end++;
}
return 0;
}Reads integer N from standard input. Uses two variables: start (initialized to N) and end (initialized to 1). The while loop continues while start >= end. Inside the loop, a for loop prints integers from start down to end. After each complete sequence, start is decremented and end is incremented to create the next decreasing limit. The process continues until start becomes less than end.