Question

Write a program that prompts the user to enter three integers and display the integers in...

Write a program that prompts the user to enter three integers and display the integers in non-decreasing order.

For example if you enter 10 and 9 and 12, in the result we will first see 9, then 10 and then 12 (because 9 < 10 < 12).

**using c++

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

#define PI 3.14159265358979323846

using namespace std;

void smallSort(int &i, int &j, int &k){
   int f = i,s = j,t = k;
   if(f<s && f<t){
      i = f;
      if(s<t){
         j = s;
         k = t;
      }
      else{
         j = t;
         k = s;
      }
   }
   else if(s<f && s<t){
      i = s;
      if(f<t){
         j = f;
         k = t;
      }
      else{
         j = t;
         k = f;
      }
   }
   else{
      i = t;
      if(f<s){
         j = f;
         k = s;
      }
      else{
         j = s;
         k = f;
      }
   }
   
}

int main()
{
   int first;
   int second;
   int third;
   cout<<"Please enter 3 numbers: ";
   cin>>first;
   cin>>second;
   cin>>third;
   smallSort(first, second, third);
   cout<<"\nNumbers in non decreasing order:"<<endl;
   
   cout<<first<<endl;
   cout<<second<<endl;
   cout<<third<<endl;
   
   return 0;
}
Add a comment
Know the answer?
Add Answer to:
Write a program that prompts the user to enter three integers and display the integers in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • Write a program that prompts the user to read three positive hex integers and display their...

    Write a program that prompts the user to read three positive hex integers and display their sum in both hex and decimal. Your program should prompt the user to read the number again, if the input is incorrect. You must use java.lang.NumberFormatException. (chapter12.AddThreeHexNumbers.java)

  • Write a C# program that prompts a user to enter a birth month and day. Display...

    Write a C# program that prompts a user to enter a birth month and day. Display an error message if the month is invalid (not 1 through 12) or the day is invalid for the month (for example, not between 1 and 31 for January or between 1 and 29 for February). If the month and day are valid, display them with a message.

  • Java: Write a program that prompts the user to enter integers in the range 1 to...

    Java: Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The program should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be: 10 occurs 4 times 20 occurs 2 times 25 occurs 1 time 30 occurs 1 time...

  • Write java program that prompts the user to enter integers from the keyboard one at a...

    Write java program that prompts the user to enter integers from the keyboard one at a time. Program stops reading integers once the user enters the same value three times consecutively. Program then outputs "Same entered 3 in a row. "

  • Write a program that prompts the user to enter a question (string) and display whether the...

    Write a program that prompts the user to enter a question (string) and display whether the question is correct. It is correct if it ends with the question mark (?) ----vyrovusmyzustning%20Class.pdf Programs with String Class Write a program that prompts the user to enter a question (string) and display whether the question is correct. It is correct if it ends with the question mark (?) Ask a question? Ask a question? How old are you What is your name? That's...

  • In Java - Write a program that prompts the user to enter two integers and displays...

    In Java - Write a program that prompts the user to enter two integers and displays their sum. If the input is incorrect, prompt the user again. This means that you will have a try-catch inside a loop.

  • Write a program that prompts the user to input three different integers from the keyboard, then...

    Write a program that prompts the user to input three different integers from the keyboard, then prints the sum, the average, and the product. The screen dialogue should appear exactly as follows: Enter three different integers: 13 27 14 Sum is 54 Average is 18 Product is 4914 Please code in c program

  • In C++, Write a program that it prompts to user for two integers, computes the quotient...

    In C++, Write a program that it prompts to user for two integers, computes the quotient of two integers, and then displays the result. You need to do the following things in this assignment: + The main function prompts for user input and reads the two integers that the user entered. + Write a quotient function that computes the quotient of two integers and return the results. (hint: avoid integer division and divide by zero)

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT