Home / Programs / write a program that performs an arithmetic sequence summation (arithmetic series).
Programming Example

write a program that performs an arithmetic sequence summation (arithmetic series).

👁 2,381 Views
💻 Practical Program
📘 Step by Step Learning
write a program that performs an arithmetic sequence summation (arithmetic series). The program should accept the following value from the user - first term(a1), last term (an), and number of terms(n). It should then calculate the sum of terms in the series, and also the common difference (d) between terms. All user input must be validated.
write a program that performs an arithmetic sequence summation (arithmetic series). The program should accept the following value from the user - first term(a1), last term (an),

Program Code

#include<stdio.h> 
int main(){

float n, a1, an, d;
float sn;


printf("Enter how many term: ");
scanf("%f",&n);
printf("Enter first term: ");
scanf("%f",&a1);
printf("Enter last term: ");
scanf("%f",&an);
 

sn = (n*(a1+an))/2;

printf("summation: %f \n", sn);

}

Output

Enter how many term: 41
Enter first term: 1
Enter last term: 101
summation: 2091.000000
Press any key to continue . . .

Explanation

n -Total Term

a1 - is first term

an - is last term

d -Common difference

Formula for calculating sum of n terms in arithmetic sequence summation (arithmetis series)

sn = (n*(a1+an))/2;

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.