Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript Program for sum of arithmetic series using loop

// JavaScript program to find the sum of arithmetic series
// Function to find the sum of arithmetic series
function sumOfArithmeticSeries(firstTerm, commonDifference, noOfTerms) {
 var result = 0;
 for (let i=0; i<noOfTerms; i++)
 {
 result = result + firstTerm;
 firstTerm = firstTerm + commonDifference;
 }
 return result;
}

var firstTerm = 1;
var commonDifference = 2;
var noOfTerms = 5;
document.write("First Term: " + firstTerm + "<br>");
document.write("Common Difference: " + commonDifference + "<br>");
document.write("Number of Terms: " + noOfTerms + "<br>");
document.write("Sum of the arithmetic series: " + sumOfArithmeticSeries(firstTerm, commonDifference, noOfTerms));
Source by www.makeuseof.com #
 
PREVIOUS NEXT
Tagged: #javascript #Program #sum #arithmetic #series #loop
ADD COMMENT
Topic
Name
1+8 =