write a program to eccept three number, find its average and check whether average is even or odd.
Answers
If you like my answer please follow me.
Answer:
#Assign 3 number in 3 varriable.
a=int(input ("Enter number1"))
b=int(input("Enter number2"))
c=int(input("Enter number3"))
average = a+b+c/3 #Take out average
print ("Average of numbers is", average )
if (average%2=0): #Checking average
print ("Number is even")
else:
print ("Number is odd")
This program is in Java. The average of numbers is mostly in decimals and decimals are not even or odd. If it's written 0.3, it can also be 0.30 or 0.333333... . It's better not to just add this as it will make the program even complex.
import java.util.*;
public class AverageCalculator {
public static void main (String [] args) {
//Taking input from the user
Scanner sc = new Scanner(System.in);
System.out.print("Enter the first number: ");
double num1 = sc.nextDouble();
System.out.print("Enter the second number: ");
double num2 = sc.nextDouble();
System.out.print("Enter the third number: ");
double num3 = sc.nextDouble();
//Main part comes here
double Average = (num1 + num2 + num3) / 3;
double sum = num1 + num2 + num3;
System.out.println("The sum of the following numbers is " + sum);
System.out.println("The average of the given numbers is " + Average);
}
}
Output:
Enter the first number: 30
Enter the second number: 31
Enter the third number: 28
The sum of the following numbers is 89.0
The average of the given numbers is 29.666666666666668