Write a JavaScript program to find the maximum integer If a given integer is 10, value of maximum integer n is 4 so 10 is true.
and please elaborate the logic.
Answers
Answered by
0
HTML PROGRAM
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Find the maximum integer n.</title>
</head>
<body>
</body>
</html>
JAVASCRIPT PROGRAM
function sumn(val) {
var sn = 0;
var i = 0;
while (sn <= val) {
sn += i++;
}
return i - 2;
}
console.log(sumn(11))
console.log(sumn(15))
SAMPLE OUTPUT
4
5
ES6 SOLUTION
function sumn(val) {
let sn = 0;
let i = 0;
while (sn <= val) {
sn += i++;
}
return i - 2;
}
console.log(sumn(11))
console.log(sumn(15))
please mark as brainliest
Similar questions