In this article, you’ll learn how to find the sum of the arithmetic series using Python, C++, JavaScript, and C.
What Is an Arithmetic Series?
The sum of the terms of a finite arithmetic sequence is called an arithmetic series. The arithmetic sequence is denoted as follows:
where,
Problem Statement
You’re given the first term, common difference, and no. of terms of the arithmetic series. You need to find the sum of the arithmetic series. Example: Let firstTerm = 1, commonDifference = 2, and noOfTerms = 5. Arithmetic Series: 1 + 3 + 5 + 7 + 9 Sum of the arithmetic series: 25 Thus, the output is 25.
Iterative Approach to Find the Sum of an Arithmetic Series
First, we’ll take a look at the iterative approach. You can find out how to find sums in this way for the main programming languages below.
C++ Program to Find the Sum of an Arithmetic Series Using Iteration
Below is the C++ program to find the sum of an arithmetic series using iteration:
Output:
Python Program to Find the Sum of an Arithmetic Series Using Iteration
Below is the Python program to find the sum of an arithmetic series using iteration:
Output:
JavaScript Program to Find the Sum of an Arithmetic Series Using Iteration
Below is the JavaScript program to find the sum of an arithmetic series using iteration:
Output:
C Program to Find the Sum of an Arithmetic Series Using Iteration
Below is the C program to find the sum of an arithmetic series using iteration:
Output:
Efficient Approach to Find the Sum of an Arithmetic Series Using Formula
You can use the following formula to find the sum of the arithmetic series:
where,
C++ Program to Find the Sum of an Arithmetic Series Using Formula
Below is the C++ program to find the sum of an arithmetic series using the formula:
Output:
Python Program to Find the Sum of an Arithmetic Series Using Formula
Below is the Python program to find the sum of an arithmetic series using the formula:
Output:
JavaScript Program to Find the Sum of an Arithmetic Series Using Formula
Below is the JavaScript program to find the sum of an arithmetic series using the formula:
Output:
C Program to Find the Sum of an Arithmetic Series Using Formula
Below is the C program to find the sum of an arithmetic series using the formula:
Output:
Finding Arithmetic Series With Different Programming Languages Is Easy
Now you’ve read this article, you know how to find arithmetic series with each of the main programming languages.
C++ is one of the “bread and butter” programming languages. It’s used to develop a variety of software like databases, operating systems, compilers, web browsers, etc. If you’re looking to learn C++, you should check out some of the best sites like Udemy, edX, LearnCpp, and so on.