Python program to find the maximum EVEN number

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

Problem statement

Write a Python program to input N integer numbers, and find the maximum even 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 EVEN 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 EVEN number or not.
  5. If it is an EVEN 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 EVEN value from the given N values.

Python code to find the maximum EVEN number

# Python code to find the maximum EVEN number

# Initialise the variables
i = 0  # loop counter
num = 0  # to store the input
maximum = 0  # to store maximum EVEN 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 even number
print("The maximum EVEN number :", maximum)

Output

The output of the above example is:

RUN 1:
Enter your number: 100
Enter your number: 222
Enter your number: 12
Enter your number: 333
Enter your number: 431
Enter your number: 90
Enter your number: 19
Enter your number: 56
Enter your number: 76
Enter your number: 671
The maximum EVEN number : 222

RUN 2:
Enter your number: 10
Enter your number: 22
Enter your number: 333
Enter your number: 4444
Enter your number: 55555
Enter your number: 6666
Enter your number: 12
Enter your number: 23
Enter your number: 3444441
Enter your number: 898989
The maximum EVEN number : 6666

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.