Respuesta :

Answer:

JAVA program:

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.

C++ program

#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 */

Python Code

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

Explanation:

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.

Output:

Enter the first number:

3

Enter the second number:

6

Enter the third number:

1

1 is the smallest number

Following are the program to calculate the smallest number among three numbers:

Program:

#include <iostream>//header file

using namespace std;

int main()//main method

{

   int x_1,y_1,z_1;//defining an array and an integer variable

   cout<<"Enter three values: "<<endl;//print message

   cin>>x_1>>y_1>>z_1;//input value

   if(x_1<y_1 &&x_1<z_1)//defining if block that checks x_1 value is less than y_1 and z_1 value

   {

       cout<<"First number that is "<<x_1<<" has the smallest number.";//print value with message

   }

   else if(y_1<z_1 )//defining else if the that checks y_1 value is less than z_1 value

   {

       cout<<"Second number that is "<<y_1<<" has the smallest number.";//print value with the message

   }

   else//else block

   {

       cout<<"Third number that is "<<z_1<<" has the smallest number.";//print value with the message

   }

   return 0;

}

Program Explanation:

  • Defining header file.
  • Defining the main method.
  • Inside the main method three integer variable "x_1,y_1,z_1" is declared, in which we input an integer value from the user-end.
  • After input value, a conditional statement has used that checks the smallest value among the input value and prints its value.

Output:

Please find the attached file.

Find out more information about the smallest of the three values here:

brainly.com/question/10659180

Ver imagen codiepienagoya
RELAXING NOICE
Relax