SUM OF NATURAL NUMBERS

 ************************************************************************ 

W.A.P TO FIND SUM OF NATURAL NUMBERS

************************************************************************  

JAVA Program







   



  
Online compiler

Output:


************************************************************************ 

C Program



Online Compiler 

 

************************************************************************ 

C++ Program

Online Compiler

************************************************************************ 

C# Program


 
 
Output:

************************************************************************ 

PHP Program


Online Compiler

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>

Online Compiler

************************************************************************ 

PYTHON Program

 

Online Compiler: 

************************************************************************  

Comments

Popular posts from this blog

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

PALINDROME NUMBER

FIBONACCI SERIES