. Write a program to input 10 integers and check whether all the entered numbers are even numbers
1or not.
Answers
Program
a1 = int(input("Enter the first number:\n"))
a2 = int(input("Enter the second number:\n"))
a3 = int(input("Enter the third number:\n"))
a4 = int(input("Enter the fourth number:\n"))
a5 = int(input("Enter the fifth number:\n"))
a6 = int(input("Enter the sixth number:\n"))
a7 = int(input("Enter the seventh number:\n"))
a8 = int(input("Enter the eight number:\n"))
a9 = int(input("Enter the ninth number:\n"))
a10 = int(input("Enter the tenth number:\n"))
l = [a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]
All_the_numbers_are_even = True
for i in range(0,len(l)):
if(l[i]%2!=0):
All_the_numbers_are_even = False
break
if All_the_numbers_are_even:
print("All the numbers are even.")
else:
print("All the numbers are not even.")
Explanation
- I have used for loop to print the result.
- By default, i have assumed that all the numbers entered by the user are even.
- Then, i have used break statement. for loop will stop executing as soon as it encounters any odd number and our statement is declared false.
JAVA PROGRAM:
import java.util.*;
public class Brainly
{
static void main()
{
Scanner sc=new Scanner(System.in);
int i,n,f=0;
System.out.println("Enter 10 integers:");
for(i=1;i<=10;i++)
{
n=sc.nextInt();
if(n%2!=0)
f=1;
}
if(f==0)
System.out.println("All are Even Numbers");
else
System.out.println("All are not Even Numbers");
}
}