This simple C program allows users to generate all even or odd numbers within a specified range. It automatically adjusts the start number if it's not evenly divisible by 2, based on the user's choice. Useful for beginners learning loops and conditionals in C.
-
User selects:
1for Even numbers2for Odd numbers
-
User provides the start and end of the range.
-
Program:
- Adjusts the start value if needed.
- Loops through the range with a step of 2 to print even or odd numbers.
Type
1 for even numbers
2 for an odd number
: 2
Where to start and end?
Type Start and End Number: 4 15
Odd numbers from 5 to 15 are:
5
7
9
11
13
15
evenodd.c— Complete program source code
- C compiler (like
gcc) - Works with Code::Blocks, VS Code, Dev C++, or any terminal
- Smart auto-adjustment of start number
- Clean and user-friendly I/O
- Uses
switch-casefor user choices