Home C Programming Language / 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,383 Views
💻 Practical Program
📘 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);

}
                        

🖥 Program 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;
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.