SUM OF NATURAL NUMBERS
************************************************************************
W.A.P TO FIND SUM OF NATURAL NUMBERS
************************************************************************
JAVA Program
Output:
************************************************************************
C Program
Online Compiler
************************************************************************
C++ Program
Online Compiler
************************************************************************
C# Program
************************************************************************
PHP Program
Php is a server side scripting language.
************************************************************************
JAVASCRIPT Program
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title></title>
<script type="text/javascript">
// SUM OF NATURAL NUMBERS
function sum(num){
if (num>0)
{ return (num + sum(num-1)); }
else{ return 0; }
}
function check() {
var number= document.getElementById('n1').value;
var ans= sum(parseInt(number));
document.getElementById('ans').innerText=`SUM OF NATURAL NUMBERS UPTO ${number} IS ${ans} `;
}
</script>
</head><body>
SUM OF NATURAL NUMBERS GENERATOR
<br>Enter upper limit:
<input type="number" name="" id="n1"/>
<br>
<button onclick="check()">GENERATE</button>
<h2 id="ans" ></h2>
</body></html>
************************************************************************
PYTHON Program
************************************************************************
Comments
Post a Comment