Computer Science, asked by letnee2929, 11 months ago

Write a scriptlet that displays first n natural numbers and their sum. You may assume n=10. You must use looping construct for the same.

Answers

Answered by Anonymous
1

Answer:

Below code is to find the sum of the natural numbers from1 to 10 as it is given that n = 10

<!DOCTYPE html >

<html>

<head>

<title>Natural Number Addition</title>

</head>

<body>

<% out.println("The sum of the natural numbers is "); %>

<% int j; int sum=0;%>

<% for (j = 1; j <= 10; j++)

   {

       sum = sum + j;

       printf("%d ",j);    

   }%>

</body>

</html>

Similar questions