1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
dybincka [34]
4 years ago
6

Write a program whose inputs are three integers, and whose output is the smallest of the three values.

Computers and Technology
1 answer:
denis-greek [22]4 years ago
6 0

Answer:

<h2>JAVA program: </h2>

import java.util.Scanner;  //Scanner class is used to get the input

public class FindSmallest // class to find the smallest of 3 integer values

{     public static void main(String[] args) //entry point of the main program

{  int number1, number2, number3;  // 3 integer type numbers are declared

       Scanner scanner = new Scanner(System.in); //

//new Scanner is an object that is pointing towards scanner to get the input

       System.out.println("Enter the first number:");

//prompts the user to enter the first integer value

       number1 = scanner.nextInt();

// nextInt() method of reads integer value entered by user

       System.out.println("Enter the second number:");

//prompts the user to enter the second integer value

       number2 = scanner.nextInt();

       System.out.println("Enter the third number:");

//prompts the user to enter the third integer value

       number3 = scanner.nextInt();

       scanner.close();         //closes scanner

   if( number1 <= number2 && number1 <= number3)

//checks the condition if number1 is less than or equal to number2 and //number3

           System.out.println(number1 + " is the smallest number");

// if condition is true then displays the messages number1 is the smallest

       else if (number2 <= number1 && number2 <=number3)

//else checks if number2 is less than or equal to number1 and number3

           System.out.println(number2 + " is the smallest number");

// if else condition is true then display that number2 is the smallest

       else

           System.out.println(number3 + " is the smallest number");    }  }

//else display number3 is the smallest.

<h2>C++ program</h2>

#include <iostream>

//includes iostream header file for input output functions

using namespace std;

//namespace is used by computer in order to detect cout endl cin. objects

int main() //start of the main program

{  int number1, number2, number3; //declares 3 integer type numbers

   cout << "Enter the first number: ";

//prompts user to enter 1st integer value

   cin >> number1;

//accepts the first input value

   cout << "Enter the second number: ";

   cin>> number2;

   cout << "Enter the third number: ";

   cin>> number3;

   if(number1 <= number2 && number1 <= number3)

/*if condition checks whether value stored in number1 is less than or equal to the values stored in number2 and number3 variables */

   { cout << number1<< " is the smallest number ";    }

//if the condition is true this means number1 is the smallest

   else if(number2 <= number1 && number2 <= number3)

/*if number1 is neither smaller than number2 nor number then program control will move to else if part which checks if number2 is less than or eqal to number1 and number3*/

   { cout << number2<< " is the smallest number ";    }

//true if else part means that number2 is the smallest

   else

    { cout << number3<< " is the smallest number ";    }}

/*in case none of the above conditions is true then else part will be exectued which means that number3 is the smallest */

<h2>Python Code</h2>

number1 = int(input("Enter the first number: "))

#prompts user to enter the first number

number2 = int(input("Enter the second number: "))

number3 = int(input("Enter the third number: "))

if (number1 <= number2) and (number1 <= number3):

#if condition checks whether value stored in number1 is less than or equal #to the values stored in number2 and number3 variables

  smallest = number1

#value of number1 will be stored in smallest if the condition evaluates to #true

elif (number2 <= number1) and (number2 <= number3):

#if number1 is neither smaller than number2 nor number then program #control will move to elif part(else if) which checks if number2 is less than #or equal to number1 and number3

  smallest = number2

#value of number2 will be stored in smallest if the elif condition evaluates #to true

else:

#in case none of the above conditions is true then else part will be #exectued which means that number3 is the smallest

  smallest = number3

#value of number3 is stored in smallest variable

print(smallest, "is the smallest number")

#smallest value stored in smallest variable is displayed as output

<h2>Explanation:</h2>

So the program is used to take three integers from the user. Next the if condition first compares number1 to number2 and number3. If number1 is less than or equals to both number2 and number3 this means that one is the smallest of the three values. If not then the else if condition will be checked. This condition checks if value in number2 variable is less than or equal to that of number1 and number3. If its true then this means that number2 is the smallest. If both if and else if conditions are false then this means that number3 is the smallest number. I have used less than or equal = to here along with the less than relative operator. The reason is that if the user enters number1 as 8 number2 as 8 and number3 as 9 then this means number1 and number2 are equal but less than number3 so the output will display 8 as the smallest number but without using = it will display 9 as the smallest number.

<h2>Output:</h2>

Enter the first number:

3

Enter the second number:

6

Enter the third number:

1

1 is the smallest number

You might be interested in
Which of the following is time-dependant? Group of answer choices
Nookie1986 [14]

Answer:

A dynamic model accounts for time-dependent changes in the state of the system,

while a static model calculates the system in equilibrium, and thus is time-invariant.

Dynamic models typically are represented by differential equations or difference equations

7 0
4 years ago
A device that turns hard copy, such as a paper document, into a digital format that can be viewed or manipulated on a computer i
Nostrana [21]

A device that turns hard copy, such as a paper document, into a digital format that can be viewed or manipulated on a computer is an <u>optical scanner</u>.

<h3>What is a computer hardware?</h3>

A computer hardware can be defined as a physical component of an information technology (IT) or computer system that can be seen and touched such as:

  • Keyboard
  • Network
  • Monitor screen
  • Mouse
  • Hard-disk drive
  • Optical scanner

<h3>What is an optical scanner?</h3>

An optical scanner can be defined as a type of input device that is designed and developed to access, read, scan, convert, or store (memorize) information about a physical object such as a paper-document, especially through the use of a light beam.

Read more on optical scanner here: brainly.com/question/24937533

#SPJ1

5 0
2 years ago
The term used for doing business online is referred to as ___.
liubo4ka [24]
The process for doing business online is referred to as e-commerce.
6 0
3 years ago
If non-series-rated overcurrent devices (standard molded-case circuit breakers) are to be installed in the main switchboard, bre
const2013 [10]

Breakers with adequate short-circuit must be installed in the panelboards.

<h3>What are these equipment about?</h3>

Common Overcurrent Protection Devices (OCPDs) are known to be Breakers or fuses that are often used  to protect the full unit from too much current.

Note that Equipment such as switchboards and panelboards are often installed in an electrical system and they have to be of adequate measure of short-circuit current condition.

Learn more about overcurrent devices  from

brainly.com/question/14284905

3 0
2 years ago
Which osi model layer manages data encryption?
Hoochie [10]
The presentation Layer manages data encryption.
7 0
4 years ago
Other questions:
  • Most internet connections use what transmission
    13·2 answers
  • 1. _____ can’t be rewritten by the computer in which it’s installed, but it has the advantage of being very _____.
    6·1 answer
  • Some drugs, like Tylenol, are available over the counter because they are safe in any dose.
    8·1 answer
  • Kerry wants to save her file but give it a new name. Kerry should use the ____ command
    7·1 answer
  • Alexandria works for a non-profit company that asks for donations to help the homeless people in her community. Recently the dat
    12·1 answer
  • Jobs with only 7 letters
    7·2 answers
  • What is known as the global network of computers?
    9·2 answers
  • Carmen has met new people online that she enjoys talking to. One of these people has asked her to meet at the park in person and
    15·1 answer
  • Write a function solution that given an array a of n integers (between -100 and 100), returns the sign (-1,0,1) of product of al
    12·1 answer
  • Assume you have written a method with the header num yourMethod(string name, num code). The method's type is ____ .
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!