Advertisement
3vo

Problem 4. Multiplication Sign

3vo
Oct 25th, 2022
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.91 KB | Source Code | 0 0
  1. // Write a program that shows the sign (+, - or 0) of the product of three real numbers,
  2. // without calculating it. * Use a sequence of if operators.
  3. //
  4. // Examples:
  5. //  a     b     c       result
  6. //  5     2     2       +
  7. // -2    -2     1       +
  8. // -2     4     3       -
  9. //  0    -2.5   4       0
  10. // -1    -0.5  -5.1     -
  11. let input = [
  12.     '-1',
  13.     '-0.5',
  14.     '-5.1'
  15. ];
  16. let print = this.print || console.log;
  17. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  18. //Get the three numbers
  19. let a = +gets();
  20. let b = +gets();
  21. let c = +gets();
  22.  
  23. //Check if the numbers are real
  24. if (a > 0 && b > 0 && c > 0) {
  25.     console.log("+");
  26. } else if (a < 0 && b < 0 && c < 0) {
  27.     console.log("-");
  28. } else if (a > 0 && b < 0 && c < 0) {
  29.     console.log("+");
  30. } else if (a < 0 && b > 0 && c < 0) {
  31.     console.log("+");
  32. } else if (a === 0 || b === 0 || c === 0) {
  33.     console.log('0');
  34. } else {
  35.     console.log('-')
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement