等差数列前n项求和

n-->项数

a1-首项

an->末项

sum->和

#include<stdio.h>
int main()
{
    int n = 0;
    int a1 = 2;
    int an = 0;
    int sum = 0;
    while(scanf("%d",&n) != EOF)
    {
        an = a1 + (n-1)*3;
        sum = n * (a1 + an) / 2;
        printf("%d\n",sum);
    }
}