السابق التالي
0 / 7
الوحدة النمطية DEMO-32-58DEMO-C-32

Print Odd Numbers

DEMO-C-32 • Programming in C

Browser-only practice

بيان المشكلة

Write a C program that reads a positive integer n from the user and prints all odd numbers from 1 to n (inclusive), each on a new line.

For example, if n is 7, the output should be:

1 3 5 7

If n is 10, the output should be:

1 3 5 7 9

Use a loop to solve this problem.

قيود

1 ≤ n ≤ 1000

تنسيق الإدخال

A single line containing a positive integer n (1 ≤ n ≤ 1000).

تنسيق الإخراج

Print each odd number from 1 to n on a separate line.

حالات اختبار نموذجية

Submit runs every public testcase in this browser. Results and code never leave this device.

العينة رقم 1
عينة ظاهرة
5
1
3
5
Sample case showing odd numbers from 1 to 5
العينة رقم 2
عينة ظاهرة
1
1
Edge case with n=1, only one odd number
العينة رقم 3
عينة ظاهرة
2
1
Case where n is even and small, only one odd number
العينة رقم 4
عينة ظاهرة
3
1
3
Small case with n=3
العينة رقم 5
عينة ظاهرة
10
1
3
5
7
9
Sample case with even n, showing odd numbers from 1 to 10
العينة رقم 6
عينة ظاهرة
100
1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
Larger case with n=100 to test performance

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
إعدادات المحرر