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
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
Math,
5 months ago
Political Science,
5 months ago
CBSE BOARD XII,
5 months ago
English,
11 months ago
English,
11 months ago
History,
1 year ago
Math,
1 year ago
Social Sciences,
1 year ago