Computer Science, asked by hudaabidi786, 3 months ago

Write a program to obtain three numbers and print their sum and average.

Answers

Answered by deepakkumar9254
2

Program using Java -

import java.util.Scanner; //importing package

class oo //class declaration  

{

   public static void main (String args[]) //main()method declaration

   {

       Scanner sc = new Scanner(System.in); //input object creation

       System.out.println("Enter three numbers");

       int a = sc.nextInt();  

       int b = sc.nextInt();

       int c = sc.nextInt();

       int sum = a + b + c;

       double av = (sum)/3;

       System.out.println("The sum of the numbers is = " + sum);

       System.out.println("The average of the numbers is = " + av);

   }

}

Output :- in the attachment.

Glossary :-

\begin{array}{| c | c | c |}\cline{1-3} \bf Variable& \bf Type & \bf Description\\ \cline{1-3} a &\sf int & \sf to\:store\:the\:first\:number\\ \cline{1-3} b &\sf int & \sf to\:store\:the\:second\:number \\ \cline{1-3} c &\sf int & \sf to\:store\:the\:third\:number \\ \cline{1-3} sum &\sf int & \sf to\:store\:the\:sum\:of\:numbers \\ \cline{1-3} av &\sf double & \sf to\:store\:the\:average\:of\:numbers \\ \cline{1-3}\end{array}

Attachments:
Answered by Shivu516
0

This program is in Java.  

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

Similar questions