Python program to find the maximum ODD number

Finding maximum ODD number: Here, we are going to implement a python program that will input N number and find the maximum ODD number. By Anuj Singh Last updated : January 04, 2024

Problem statement

Write a Python program to input N integer numbers, and find the maximum ODD number.

There are many ways of doing this but this time, we have to thought of most computationally efficient algorithm to do so.

Algorithm

The steps (algorithm) to find the maximum ODD number from N numbers:

  1. Take a variable maximum and assign it with 0.
  2. Run a loop till N times.
  3. Input the integer number inside the loop.
  4. Check whether the input is an ODD number or not.
  5. If it is an ODD number, then check whether the number is greater than the maximum, if yes update the maximum with the number.
  6. Increase the loop counter.
  7. After running the loop N time, print the value of the maximum, which will be the maximum ODD value from the given N values.

Python code to find the maximum ODD number

# Python code to find the maximum ODD number

# Initialise the variables
i = 0  # loop counter
num = 0  # to store the input
maximum = 0  # to store maximum ODD number
N = 10  # To run loop N times

# loop to take input 10 number
while i < N:
    num = int(input("Enter your number: "))
    if num % 2 != 0:
        if num > maximum:
            maximum = num
    i += 1

# printing the 	maximum ODD number
print("The maximum ODD number :", maximum)

Output

The output of the above example is:

RUN 1:
Enter your number: 121
Enter your number: 234
Enter your number: 561
Enter your number: 800
Enter your number: 780
Enter your number: 870
Enter your number: 122
Enter your number: 345
Enter your number: 679
Enter your number: 986
The maximum ODD number : 679

RUN 2:
Enter your number: 111111
Enter your number: 23223
Enter your number: 1234113
Enter your number: 9089292
Enter your number: 2000100
Enter your number: 909090
Enter your number: 1234
Enter your number: 5678
Enter your number: 12345678
Enter your number: 121212
The maximum ODD number : 1234113

To understand the above program, you should have the basic knowledge of the following Python topics:

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.