- Related Questions & Answers
- Python program to print all even numbers in a range
- Python program to print odd numbers in a list
- Print all Good numbers in given range in C++
- Python program to print all Prime numbers in an Interval
- Program to print all palindromes in a given range in C++
- PHP program to find the sum of odd numbers within a given range
- Program to print prime numbers in a given range using C++ STL
- Python program to print even numbers in a list
- Python program to print negative numbers in a list
- Python program to Count Even and Odd numbers in a List
- Print all odd numbers and their sum from 1 to n in PL/SQL
- Python Program to Print Numbers in an Interval
- Python program to print all sublists of a list.
- Program to sort all even and odd numbers in increasing and decreasing order respectively in Python
- Print prime numbers in a given range using C++ STL

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will learn about the solution and approach to solve the given problem statement.

Given a range, we need to print all the odd numbers in the given range.

The brute-force approach is discussed below −

Here we apply a range-based for loop which provides all the integers available in the input interval.

After this, a check condition for odd numbers is applied to filter all the even numbers.

This approach takes O(n) + constant time of comparison.

Now let’s see the implementation below −

start, end = 10, 29 # iteration for num in range(start, end + 1): # check if num % 2 != 0: print(num, end = " ")

11 13 15 17 19 21 23 25 27 29

All the variables and functions are declared in a global frame as shown in the figure below.

In this article, we learned about the approach to print odd numbers in the input range.

Advertisements