Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write a program that enters 3 real numbers and prints them sorted in descending order.
- // * Use nested if statements.
- // Note: Donβt use arrays and the built-in sorting functionality.
- // Examples:
- // a b c result
- // 5 1 2 521
- // -2 -2 1 1 -2 -2
- // -2 4 3 4 3 -2
- // 0 -2.5 5 5 0 -2.5
- // -1.1 -0.5 -0.1 -0.1 -0.5 -1.1
- // 10 20 30 30 20 10
- // 1 1 1 1 1 1
- let input = ['5', '1', '2'];
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- //Get the input and convert it to numbers:
- let a = +gets();
- let b = +gets();
- let c = +gets();
- //Sort the numbers descending order:
- if (a < b) {
- if (b < c) {
- print(c, b, a);
- } else if (a < c) {
- print(b, c, a);
- } else {
- print(b, a, c);
- }
- } else if (c < a) {
- if (b < c) {
- print(a, c, b);
- } else {
- print(a, b, c);
- }
- } else {
- print(c, a, b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement