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

Print Even 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 even numbers from 1 to n (inclusive), each on a new line.

An even number is any integer that is divisible by 2 with no remainder.

For example, if n is 10, the even numbers from 1 to 10 are: 2, 4, 6, 8, 10.

If n is less than 2, no even numbers should be printed since there are no even numbers in that range.

قيود

1 ≤ n ≤ 1000 Only use basic C constructs (loops, conditionals, variables) Do not use arrays or functions other than those in stdio.h

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

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

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

Print each even number from 1 to n on a separate line. If there are no even numbers in the range, print nothing.

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

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

العينة رقم 1
عينة ظاهرة
10
2
4
6
8
10
Sample case showing even numbers from 1 to 10.
العينة رقم 2
عينة ظاهرة
15
2
4
6
8
10
12
14
Hidden case with odd n value to test boundary handling.
العينة رقم 3
عينة ظاهرة
1
Sample case with n=1, no even numbers to print.
العينة رقم 4
عينة ظاهرة
2
2
Hidden case with n=2, only one even number to print.
العينة رقم 5
عينة ظاهرة
20
2
4
6
8
10
12
14
16
18
20
Sample case with larger n value.
العينة رقم 6
عينة ظاهرة
4
2
4
Sample case with small even n value.

Web terminal

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

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