Sunday, April 18, 2021

31. Write a JavaScript program to find the largest of three given integers.

31. Write a JavaScript program to find the largest of three given integers.

function max_of_three(x, y, z) 
 {
  max_val = 0;
  if (x > y)
  {
    max_val = x;
  } else
  {
    max_val = y;
  }
  if (z > max_val) 
  {
    max_val = z;
  }
  return max_val;
}

console.log(max_of_three(1,0,1));
console.log(max_of_three(0,-10,-20));
console.log(max_of_three(1000,510,440));

No comments:

14 May 2021 Current Affairs