Question

In: Computer Science

Using C# programming language, Write a program that sort three numbers entered by the user using...

Using C# programming language, Write a program that sort three numbers entered by the user using only if and nested if statements. If for instance the user entered 5, 2, and 7; the program should display 2,5,7.

Solutions

Expert Solution

C# code:

using System;
class Program{
static void Main() {
//accepting first number
int num1=Convert.ToInt32(Console.ReadLine());
//accepting second number
int num2=Convert.ToInt32(Console.ReadLine());
//accepting third number
int num3=Convert.ToInt32(Console.ReadLine());
//checking if num1 is the smallest
if(num1<num2 && num1<num3){
//printing num1
Console.Write(num1+" ");
if(num2<num3){
//printing num2
Console.Write(num2+" ");
//printing num3
Console.Write(num3);
}
else{
//printing num3
Console.Write(num3+" ");
//printing num2
Console.Write(num2);
}
}
//checking if num2 is the smallest
if(num2<num1 && num2<num3){
//printing num2
Console.Write(num2+" ");
if(num1<num3){
//printing num1
Console.Write(num1+" ");
//printing num3
Console.Write(num3);
}
else{
//printing num3
Console.Write(num3+" ");
//printing num1
Console.Write(num1);
}
}
//checking if num3 is the smallest
if(num3<num1 && num3<num1){
//printing num3
Console.Write(num3+" ");
if(num2<num1){
//printing num2
Console.Write(num2+" ");
//printing num1
Console.Write(num1);
}
else{
//printing num1
Console.Write(num1+" ");
//printing num2
Console.Write(num2);
}
}
}
}


Screenshot:


Input :

Output:


Related Solutions

LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
Using c# programming language Write a program that mimics a lottery game. Have the user enter...
Using c# programming language Write a program that mimics a lottery game. Have the user enter 3 distinct numbers between 1 and 10 and match them with 3 distinct, randomly generated numbers between 1 and 10. If all the numbers match, then the user will earn $10, if 2 matches are recorded then the user will win $3, else the user will lose $5. Keep tab of the user earnings for, let say 5 rounds. The user will start with...
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude...
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude <iostream>)
C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
C++ Bubble Sort Write a program that ask user to enter 7 numbers and store that...
C++ Bubble Sort Write a program that ask user to enter 7 numbers and store that in array. Display that all numbers before and after performing Bubble sort. You must have to create new function with required parameter to perform Bubble sort. Sample Run :- Enter 1 number :- 1 Enter 2 number :- 5 Enter 3 number :- 7 Enter 4 number :- 45 Enter 5 number :- 90 Enter 6 number :- 6 Enter 7 number :- 55...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Write a program that asks the user to enter an array of random numbers, then sort...
Write a program that asks the user to enter an array of random numbers, then sort the numbers (ascending order), then print the new array, after that asks the user for a new two numbers and add them to the same array and keep the array organization. (c++ ) (using while and do while loops)
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Using the C Programming language, write a program that sums an array of 50 elements. Next,...
Using the C Programming language, write a program that sums an array of 50 elements. Next, optimize the code using loop unrolling. Loop unrolling is a program transformation that reduces the number of iterations for a loop by increasing the number of elements computed on each iteration. Generate a graph of performance improvement. Tip: Figure 5.17 in the textbook provides an example of a graph depicting performance improvements associated with loop unrolling. Marking:- Optimize the code for an array of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT