Write a JavaScript program to calculate sum of 1 to n numbers

 


Code:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Practical-14</title>
</head>

<body>
    <script>

        var num = prompt("Enter the number ");
        var sum = 0;
        for (let i = 0i <= numi++) {
            sum = sum + i;

        }
        alert(`Sum of the 1 to ${num} numbers is :` + sum);

        
    </script>
</body>

</html>

Output:




Comments

Popular posts from this blog

Write A Program To Print Hello World Using Lex

Apply inline, internal and external style sheet for the student registration form.